|
| 1 | +const std = @import("../index.zig"); |
| 2 | +const valgrind = std.valgrind; |
| 3 | + |
| 4 | +pub const CallgrindClientRequest = extern enum { |
| 5 | + DumpStats = valgrind.ToolBase("CT"), |
| 6 | + ZeroStats, |
| 7 | + ToggleCollect, |
| 8 | + DumpStatsAt, |
| 9 | + StartInstrumentation, |
| 10 | + StopInstrumentation, |
| 11 | +}; |
| 12 | + |
| 13 | +fn doCallgrindClientRequestExpr(default: usize, request: CallgrindClientRequest, |
| 14 | + a1: usize, a2: usize, a3: usize, a4: usize, a5: usize |
| 15 | + ) usize |
| 16 | +{ |
| 17 | + return valgrind.doClientRequest( |
| 18 | + default, |
| 19 | + @intCast(usize, @enumToInt(request)), |
| 20 | + a1, a2, a3, a4, a5); |
| 21 | +} |
| 22 | + |
| 23 | +fn doCallgrindClientRequestStmt(request: CallgrindClientRequest, |
| 24 | + a1: usize, a2: usize, a3: usize, a4: usize, a5: usize |
| 25 | + ) void |
| 26 | +{ |
| 27 | + _ = doCallgrindClientRequestExpr(0, request, a1, a2, a3, a4, a5); |
| 28 | +} |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +/// Dump current state of cost centers, and zero them afterwards |
| 33 | +pub fn dumpStats() void { |
| 34 | + doCallgrindClientRequestStmt(CallgrindClientRequest.DumpStats, |
| 35 | + 0, 0, 0, 0, 0); |
| 36 | +} |
| 37 | + |
| 38 | + |
| 39 | +/// Dump current state of cost centers, and zero them afterwards. |
| 40 | +/// The argument is appended to a string stating the reason which triggered |
| 41 | +/// the dump. This string is written as a description field into the |
| 42 | +/// profile data dump. |
| 43 | +pub fn dumpStatsAt(pos_str: [*]u8) void { |
| 44 | + doCallgrindClientRequestStmt(CallgrindClientRequest.DumpStatsAt, |
| 45 | + @ptrToInt(pos_str), |
| 46 | + 0, 0, 0, 0); |
| 47 | +} |
| 48 | + |
| 49 | + |
| 50 | +/// Zero cost centers |
| 51 | +pub fn zeroStats() void { |
| 52 | + doCallgrindClientRequestStmt(CallgrindClientRequest.ZeroStats, |
| 53 | + 0, 0, 0, 0, 0); |
| 54 | +} |
| 55 | + |
| 56 | + |
| 57 | +/// Toggles collection state. |
| 58 | +/// The collection state specifies whether the happening of events |
| 59 | +/// should be noted or if they are to be ignored. Events are noted |
| 60 | +/// by increment of counters in a cost center |
| 61 | +pub fn toggleCollect() void { |
| 62 | + doCallgrindClientRequestStmt(CallgrindClientRequest.ToggleCollect, |
| 63 | + 0, 0, 0, 0, 0); |
| 64 | +} |
| 65 | + |
| 66 | + |
| 67 | +/// Start full callgrind instrumentation if not already switched on. |
| 68 | +/// When cache simulation is done, it will flush the simulated cache; |
| 69 | +/// this will lead to an artificial cache warmup phase afterwards with |
| 70 | +/// cache misses which would not have happened in reality. |
| 71 | +pub fn startInstrumentation() void { |
| 72 | + doCallgrindClientRequestStmt(CallgrindClientRequest.StartInstrumentation, |
| 73 | + 0, 0, 0, 0, 0); |
| 74 | +} |
| 75 | + |
| 76 | + |
| 77 | +/// Stop full callgrind instrumentation if not already switched off. |
| 78 | +/// This flushes Valgrinds translation cache, and does no additional |
| 79 | +/// instrumentation afterwards, which effectivly will run at the same |
| 80 | +/// speed as the "none" tool (ie. at minimal slowdown). |
| 81 | +/// Use this to bypass Callgrind aggregation for uninteresting code parts. |
| 82 | +/// To start Callgrind in this mode to ignore the setup phase, use |
| 83 | +/// the option "--instr-atstart=no". |
| 84 | +pub fn stopInstrumentation() void { |
| 85 | + doCallgrindClientRequestStmt(CallgrindClientRequest.StopInstrumentation, |
| 86 | + 0, 0, 0, 0, 0); |
| 87 | +} |
0 commit comments