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