Skip to content

Commit 93c661c

Browse files
committed
minitrace updated
1 parent 55ae902 commit 93c661c

File tree

4 files changed

+320
-199
lines changed

4 files changed

+320
-199
lines changed

3rdparty/minitrace/README.md

Lines changed: 60 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,43 @@ Remember to be careful when interpreting the output. This is not a sampling prof
1818
How to use
1919
----------
2020

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.
2222

2323
2. In your initialization code:
2424

25-
mtr_init("trace.json");
25+
```c
26+
mtr_init("trace.json");
27+
```
2628

2729
3. In your exit code:
2830

29-
mtr_shutdown();
31+
```c
32+
mtr_shutdown();
33+
```
3034

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`
3236

33-
// C
34-
MTR_BEGIN("GFX", "RasterizeTriangle")
35-
...
36-
MTR_END("GFX", "RasterizeTriangle")
37+
5. In all functions you want to profile:
3738

38-
// C++
39-
MTR_SCOPE("GFX", "RasterizeTriangle")
39+
```c
40+
// C
41+
MTR_BEGIN("GFX", "RasterizeTriangle")
42+
...
43+
MTR_END("GFX", "RasterizeTriangle")
44+
```
4045

41-
5. In Google Chrome open "about:tracing"
46+
```c++
47+
// C++
48+
MTR_SCOPE("GFX", "RasterizeTriangle")
49+
```
4250

43-
6. Click Open, and choose your trace.json
51+
6. In Google Chrome open "about:tracing"
4452

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`
4654

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.
4856

49-
-DMTR_DISABLE
57+
9. In your final release build, don't forget to remove `-DMTR_ENABLED` or however you set the define.
5058

5159

5260
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.
5765
Example code
5866
------------
5967

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+
```
95105
96106
The output will result in something looking a little like the picture at the top of this readme.
97107

0 commit comments

Comments
 (0)