• Stars
    star
    351
  • Rank 120,848 (Top 3 %)
  • Language
    C++
  • License
    MIT License
  • Created over 10 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple C/C++ library for producing JSON traces suitable for Chrome's built-in trace viewer (about:tracing).

minitrace

by Henrik RydgÃ¥rd 2014 ([email protected])

MIT licensed, feel free to use however you want. If you use it for something cool, I'd love to hear about it!

This is a C library with C++ helpers for producing JSON traces suitable for Chrome's excellent built-in trace viewer (chrome://tracing).

Extremely simple to build and use. Tested on Mac and Windows, but should compile anywhere you can use ANSI C with few or no changes.

Sample output (see example code below):

minitrace

Remember to be careful when interpreting the output. This is not a sampling profiler, so it only records start and stop times for blocks. This means that blocks grow even when the CPU is off running another thread, and that it can look like work is being done on more blocks at a time than you have CPUs.

How to use

  1. Include minitrace.c and minitrace.h in your project. #include minitrace.h in some common header.

  2. In your initialization code:

    mtr_init("trace.json");
  3. In your exit code:

    mtr_shutdown();
  4. Make sure MTR_ENABLED is defined globally when you want to profile, for example -DMTR_ENABLED

  5. In all functions you want to profile:

    // C
    MTR_BEGIN("GFX", "RasterizeTriangle")
    ...
    MTR_END("GFX", "RasterizeTriangle")
    // C++
    MTR_SCOPE("GFX", "RasterizeTriangle")
  6. In Google Chrome open "about:tracing"

  7. Click Open, and choose your trace.json

  8. Navigate the trace view using the WASD keys, and Look for bottlenecks and optimize your application.

  9. In your final release build, don't forget to remove -DMTR_ENABLED or however you set the define.

By default, it will collect 1 million tracepoints and then stop. You can change this behaviour, see the top of the header file.

Note: Please only use string literals in MTR statements.

Example code

int main(int argc, const char *argv[]) {
  int i;
  mtr_init("trace.json");

  MTR_META_PROCESS_NAME("minitrace_test");
  MTR_META_THREAD_NAME("main thread");

  int long_running_thing_1;
  int long_running_thing_2;

  MTR_START("background", "long_running", &long_running_thing_1);
  MTR_START("background", "long_running", &long_running_thing_2);

  MTR_BEGIN("main", "outer");
  usleep(80000);
  for (i = 0; i < 3; i++) {
    MTR_BEGIN("main", "inner");
    usleep(40000);
    MTR_END("main", "inner");
    usleep(10000);
  }
  MTR_STEP("background", "long_running", &long_running_thing_1, "middle step");
  usleep(80000);
  MTR_END("main", "outer");

  usleep(50000);
  MTR_INSTANT("main", "the end");
  usleep(10000);
  MTR_FINISH("background", "long_running", &long_running_thing_1);
  MTR_FINISH("background", "long_running", &long_running_thing_2);

  mtr_flush();
  mtr_shutdown();
  return 0;
}

The output will result in something looking a little like the picture at the top of this readme.

Future plans:

  • Builtin background flush thread support with better synchronization, no more fixed limit
  • Support for more trace arguments, more tracing types

If you use this, feel free to tell me how, and what issues you may have had. [email protected]

More Repositories

1

ppsspp

A PSP emulator for Android, Windows, Mac and Linux, written in C++. Want to contribute? Join us on Discord at https://discord.gg/5NJB6dD or just send pull requests / issues. For discussion use the forums at forums.ppsspp.org.
C++
11,183
star
2

native

NOTE: DEPRECATED! No longer used in PPSSPP! Various C++ utility code: OpenGL ES, JSON, etc, portable to Android.
C
73
star
3

ppsspp-ffmpeg

A slimmed-down build of FFMPEG used in PPSSPP. Includes h.264, atrac3+, AAC and a few other codecs.
C
62
star
4

pspautotests

A test suite based on the pspautotests svn.
C++
52
star
5

ppsspp-lang

DEPRECATED / ARCHIVED - merged into the main PPSSPP repository. Make further changes there.
49
star
6

minidx9

Minimal cutdown DirectX9 SDK for buildbot use.
C++
36
star
7

ppsspp-site

New PPSSPP website
JavaScript
25
star
8

dirtree-json

Tiny utility to read a directory tree and produce JSON.
Rust
7
star
9

minimal-site-generator

Silly minimal PHP-based static site generator
Makefile
7
star
10

boatrage

BoatRage - a DOS game I wrote in 1998? 1999? To build on modern platforms use Allegro 4.2.
C++
5
star
11

besserwisser

Very simple and straightforward neural network implementation in C++, AVX-accelerated. Gets around 98% on MNIST with a 2-layer net (or 92% as a 1-layer linear classifier)
C++
4
star
12

nodeprep

go implementation of the "nodeprep" profile of "stringprep". Not that interesting for most people, heh.
Python
3
star
13

openscad-models

Random stuff I design in OpenSCAD and 3D print. Most of it will probably only be useful for me.
OpenSCAD
3
star
14

ppsspp-redist

Just a place to store redist files which will be included in the PPSSPP installer.
3
star
15

dotfiles

My vimrc and other related files
Vim Script
3
star
16

ppsspp-freetype

Just a prebuilt freetype for building the texture atlas tools for PPSSPP.
C
3
star
17

storeutil

PPSSPP store utility
Go
2
star
18

hrydgard

Config files for my GitHub profile.
1
star
19

ra-vec4-repro

Repro of an issue with rust-analyzer with the vec4 type from glam-rs
Rust
1
star
20

ppsspp-mac-sdl

SDL.framework for MacOS for PPSSPP
C
1
star
21

ppsspp-glslang

This contains the latest glslang compiler from the Vulkan SDK.
C++
1
star
22

martian-dice

Simple command line clone of Martian Dice in Go.
Go
1
star