Skip to content

Instantly share code, notes, and snippets.

@sargun
Created December 12, 2019 05:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sargun/bf85419cd4f3066d535e193282617937 to your computer and use it in GitHub Desktop.
Save sargun/bf85419cd4f3066d535e193282617937 to your computer and use it in GitHub Desktop.
const std = @import("std");
const perf_event = @cImport(@cInclude("linux/perf_event.h"));
const Event = struct {
Fd: c_int = 0,
Id: c_int = 0,
// Maybe make these enums?
PerfEventType: perf_event.enum_perf_type_id,
PerfEventConfig: perf_event.enum_perf_hw_id,
FriendlyName: [*]const u8,
};
const EventGroup = struct {
LeaderFd: c_int = 0,
Events: [*]const Event,
};
fn makeEvent(friendly_name: [*]const u8, perf_event_type: perf_event.enum_perf_type_id, perf_event_config: perf_event.enum_perf_hw_id) Event {
return Event{
.FriendlyName = friendly_name,
.PerfEventType = perf_event_type,
.PerfEventConfig = perf_event_config,
};
}
fn makeEventGroup() EventGroup {
return EventGroup{
.Events = [_]Event{
makeEvent(c"cycles", perf_event.PERF_TYPE_HARDWARE, perf_event.PERF_COUNT_HW_CPU_CYCLES),
makeEvent(c"cycles", perf_event.PERF_TYPE_HARDWARE, perf_event.PERF_COUNT_HW_CPU_CYCLES),
},
};
}
pub fn main() anyerror!void {
const event_groups = [1]EventGroup{makeEventGroup()};
std.debug.warn("x: {}\n", c_int(3));
std.debug.warn("All your base are belong to us.\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment