2019-11-16 18:59:52 -08:00
|
|
|
const std = @import("../std.zig");
|
2018-12-30 07:55:24 -08:00
|
|
|
const valgrind = std.valgrind;
|
|
|
|
|
|
|
|
pub const CallgrindClientRequest = extern enum {
|
|
|
|
DumpStats = valgrind.ToolBase("CT"),
|
|
|
|
ZeroStats,
|
|
|
|
ToggleCollect,
|
|
|
|
DumpStatsAt,
|
|
|
|
StartInstrumentation,
|
|
|
|
StopInstrumentation,
|
|
|
|
};
|
|
|
|
|
2019-05-19 13:26:43 -07:00
|
|
|
fn doCallgrindClientRequestExpr(default: usize, request: CallgrindClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) usize {
|
|
|
|
return valgrind.doClientRequest(default, @intCast(usize, @enumToInt(request)), a1, a2, a3, a4, a5);
|
2018-12-30 07:55:24 -08:00
|
|
|
}
|
|
|
|
|
2019-05-19 13:26:43 -07:00
|
|
|
fn doCallgrindClientRequestStmt(request: CallgrindClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) void {
|
2018-12-30 07:55:24 -08:00
|
|
|
_ = doCallgrindClientRequestExpr(0, request, a1, a2, a3, a4, a5);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Dump current state of cost centers, and zero them afterwards
|
|
|
|
pub fn dumpStats() void {
|
2019-11-16 19:03:52 -08:00
|
|
|
doCallgrindClientRequestStmt(.DumpStats, 0, 0, 0, 0, 0);
|
2018-12-30 07:55:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Dump current state of cost centers, and zero them afterwards.
|
|
|
|
/// The argument is appended to a string stating the reason which triggered
|
|
|
|
/// the dump. This string is written as a description field into the
|
|
|
|
/// profile data dump.
|
|
|
|
pub fn dumpStatsAt(pos_str: [*]u8) void {
|
2019-11-16 19:03:52 -08:00
|
|
|
doCallgrindClientRequestStmt(.DumpStatsAt, @ptrToInt(pos_str), 0, 0, 0, 0);
|
2018-12-30 07:55:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Zero cost centers
|
|
|
|
pub fn zeroStats() void {
|
2019-11-16 19:03:52 -08:00
|
|
|
doCallgrindClientRequestStmt(.ZeroStats, 0, 0, 0, 0, 0);
|
2018-12-30 07:55:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Toggles collection state.
|
|
|
|
/// The collection state specifies whether the happening of events
|
|
|
|
/// should be noted or if they are to be ignored. Events are noted
|
|
|
|
/// by increment of counters in a cost center
|
|
|
|
pub fn toggleCollect() void {
|
2019-11-16 19:03:52 -08:00
|
|
|
doCallgrindClientRequestStmt(.ToggleCollect, 0, 0, 0, 0, 0);
|
2018-12-30 07:55:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Start full callgrind instrumentation if not already switched on.
|
|
|
|
/// When cache simulation is done, it will flush the simulated cache;
|
|
|
|
/// this will lead to an artificial cache warmup phase afterwards with
|
|
|
|
/// cache misses which would not have happened in reality.
|
|
|
|
pub fn startInstrumentation() void {
|
2019-11-16 19:03:52 -08:00
|
|
|
doCallgrindClientRequestStmt(.StartInstrumentation, 0, 0, 0, 0, 0);
|
2018-12-30 07:55:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Stop full callgrind instrumentation if not already switched off.
|
|
|
|
/// This flushes Valgrinds translation cache, and does no additional
|
|
|
|
/// instrumentation afterwards, which effectivly will run at the same
|
|
|
|
/// speed as the "none" tool (ie. at minimal slowdown).
|
|
|
|
/// Use this to bypass Callgrind aggregation for uninteresting code parts.
|
|
|
|
/// To start Callgrind in this mode to ignore the setup phase, use
|
|
|
|
/// the option "--instr-atstart=no".
|
|
|
|
pub fn stopInstrumentation() void {
|
2019-11-16 19:03:52 -08:00
|
|
|
doCallgrindClientRequestStmt(.StopInstrumentation, 0, 0, 0, 0, 0);
|
2018-12-30 07:55:24 -08:00
|
|
|
}
|