callgrind.odin 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //+build amd64
  2. package sys_valgrind
  3. import "core:intrinsics"
  4. Callgrind_Client_Request :: enum uintptr {
  5. Dump_Stats = 'C'<<24 | 'T'<<16,
  6. Zero_Stats,
  7. Toggle_Collect,
  8. Dump_Stats_At,
  9. Start_Instrumentation,
  10. Stop_Instrumentation,
  11. }
  12. @(require_results)
  13. callgrind_client_request_expr :: #force_inline proc "c" (default: uintptr, request: Callgrind_Client_Request, a0, a1, a2, a3, a4: uintptr) -> uintptr {
  14. return intrinsics.valgrind_client_request(default, uintptr(request), a0, a1, a2, a3, a4)
  15. }
  16. callgrind_client_request_stmt :: #force_inline proc "c" (request: Callgrind_Client_Request, a0, a1, a2, a3, a4: uintptr) {
  17. _ = intrinsics.valgrind_client_request(0, uintptr(request), a0, a1, a2, a3, a4)
  18. }
  19. // Dump current state of cost centres, and zero them afterwards.
  20. dump_stats :: proc "c" () {
  21. callgrind_client_request_stmt(.Dump_Stats, 0, 0, 0, 0, 0)
  22. }
  23. // Zero cost centres
  24. zero_stats :: proc "c" () {
  25. callgrind_client_request_stmt(.Zero_Stats, 0, 0, 0, 0, 0)
  26. }
  27. // Toggles collection state.
  28. // The collection state specifies whether the happening of events should be noted or
  29. // if they are to be ignored. Events are noted by increment of counters in a cost centre.
  30. toggle_collect :: proc "c" () {
  31. callgrind_client_request_stmt(.Toggle_Collect, 0, 0, 0, 0, 0)
  32. }
  33. // Dump current state of cost centres, and zero them afterwards.
  34. // The argument is appended to a string stating the reason which triggered
  35. // the dump. This string is written as a description field into the
  36. // profile data dump.
  37. dump_stats_at :: proc "c" (pos_str: rawptr) {
  38. callgrind_client_request_stmt(.Dump_Stats_At, uintptr(pos_str), 0, 0, 0, 0)
  39. }
  40. // Start full callgrind instrumentation if not already switched on.
  41. // When cache simulation is done, it will flush the simulated cache;
  42. // this will lead to an artificial cache warmup phase afterwards with
  43. // cache misses which would not have happened in reality.
  44. start_instrumentation :: proc "c" () {
  45. callgrind_client_request_stmt(.Start_Instrumentation, 0, 0, 0, 0, 0)
  46. }
  47. // Stop full callgrind instrumentation if not already switched off.
  48. // This flushes Valgrinds translation cache, and does no additional instrumentation
  49. // afterwards, which effectivly will run at the same speed as the "none" tool (ie. at minimal slowdown).
  50. // Use this to bypass Callgrind aggregation for uninteresting code parts.
  51. // To start Callgrind in this mode to ignore the setup phase, use the option "--instr-atstart=no".
  52. stop_instrumentation :: proc "c" () {
  53. callgrind_client_request_stmt(.Stop_Instrumentation, 0, 0, 0, 0, 0)
  54. }