@@ -18,35 +18,43 @@ Remember to be careful when interpreting the output. This is not a sampling prof
18
18
How to use
19
19
----------
20
20
21
- 1 . Include minitrace.c and minitrace.h in your project. #include minitrace.h in some common header.
21
+ 1 . Include ` minitrace.c ` and ` minitrace.h ` in your project. ` #include minitrace.h ` in some common header.
22
22
23
23
2 . In your initialization code:
24
24
25
- mtr_init("trace.json");
25
+ ``` c
26
+ mtr_init ("trace.json");
27
+ ```
26
28
27
29
3 . In your exit code:
28
30
29
- mtr_shutdown();
31
+ ``` c
32
+ mtr_shutdown ();
33
+ ```
30
34
31
- 4 . In all functions you want to profile:
35
+ 4 . Make sure `MTR_ENABLED` is defined globally when you want to profile, for example `-DMTR_ENABLED`
32
36
33
- // C
34
- MTR_BEGIN("GFX", "RasterizeTriangle")
35
- ...
36
- MTR_END("GFX", "RasterizeTriangle")
37
+ 5 . In all functions you want to profile:
37
38
38
- // C++
39
- MTR_SCOPE("GFX", "RasterizeTriangle")
39
+ ```c
40
+ // C
41
+ MTR_BEGIN ("GFX", "RasterizeTriangle")
42
+ ...
43
+ MTR_END("GFX", "RasterizeTriangle")
44
+ ```
40
45
41
- 5 . In Google Chrome open "about: tracing "
46
+ ```c++
47
+ // C++
48
+ MTR_SCOPE("GFX", "RasterizeTriangle")
49
+ ```
42
50
43
- 6 . Click Open, and choose your trace.json
51
+ 6 . In Google Chrome open "about : tracing "
44
52
45
- 7 . Navigate the trace view using the WASD keys , and Look for bottlenecks and optimize your application.
53
+ 7 . Click Open , and choose your ` trace.json `
46
54
47
- 8 . In your final release build, build with
55
+ 8 . Navigate the trace view using the WASD keys, and Look for bottlenecks and optimize your application.
48
56
49
- -DMTR_DISABLE
57
+ 9 . In your final release build, don't forget to remove ` -DMTR_ENABLED ` or however you set the define.
50
58
51
59
52
60
By default, it will collect 1 million tracepoints and then stop. You can change this behaviour, see the
@@ -57,41 +65,43 @@ Note: Please only use string literals in MTR statements.
57
65
Example code
58
66
------------
59
67
60
- int main(int argc, const char *argv[]) {
61
- int i;
62
- mtr_init("trace.json");
63
-
64
- MTR_META_PROCESS_NAME("minitrace_test");
65
- MTR_META_THREAD_NAME("main thread");
66
-
67
- int long_running_thing_1;
68
- int long_running_thing_2;
69
-
70
- MTR_START("background", "long_running", &long_running_thing_1);
71
- MTR_START("background", "long_running", &long_running_thing_2);
72
-
73
- MTR_BEGIN("main", "outer");
74
- usleep(80000);
75
- for (i = 0; i < 3; i++) {
76
- MTR_BEGIN("main", "inner");
77
- usleep(40000);
78
- MTR_END("main", "inner");
79
- usleep(10000);
80
- }
81
- MTR_STEP("background", "long_running", &long_running_thing_1, "middle step");
82
- usleep(80000);
83
- MTR_END("main", "outer");
84
-
85
- usleep(50000);
86
- MTR_INSTANT("main", "the end");
87
- usleep(10000);
88
- MTR_FINISH("background", "long_running", &long_running_thing_1);
89
- MTR_FINISH("background", "long_running", &long_running_thing_2);
90
-
91
- mtr_flush();
92
- mtr_shutdown();
93
- return 0;
94
- }
68
+ ``` c
69
+ int main (int argc, const char * argv[ ] ) {
70
+ int i;
71
+ mtr_init("trace.json");
72
+
73
+ MTR_META_PROCESS_NAME("minitrace_test");
74
+ MTR_META_THREAD_NAME("main thread");
75
+
76
+ int long_running_thing_1;
77
+ int long_running_thing_2;
78
+
79
+ MTR_START("background", "long_running", &long_running_thing_1);
80
+ MTR_START("background", "long_running", &long_running_thing_2);
81
+
82
+ MTR_BEGIN("main", "outer");
83
+ usleep(80000);
84
+ for (i = 0; i < 3; i++) {
85
+ MTR_BEGIN("main", "inner");
86
+ usleep(40000);
87
+ MTR_END("main", "inner");
88
+ usleep(10000);
89
+ }
90
+ MTR_STEP("background", "long_running", &long_running_thing_1, "middle step");
91
+ usleep(80000);
92
+ MTR_END("main", "outer");
93
+
94
+ usleep(50000);
95
+ MTR_INSTANT("main", "the end");
96
+ usleep(10000);
97
+ MTR_FINISH("background", "long_running", &long_running_thing_1);
98
+ MTR_FINISH("background", "long_running", &long_running_thing_2);
99
+
100
+ mtr_flush();
101
+ mtr_shutdown();
102
+ return 0;
103
+ }
104
+ ```
95
105
96
106
The output will result in something looking a little like the picture at the top of this readme.
97
107
0 commit comments