Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
61 lines (50 sloc) 1.8 KB
* @file hawktracer-hello-world.cpp
* The file demonstrates how to use HawkTracer in GNU C/C++ applications.
* Please note this file won't compile in for other than GNU C or C++ compilers.
#include <hawktracer.h>
#include <stdio.h>
static void hello_world()
/* A function scoped tracepoint - measures a duration of the scope
* and automatically labels itself with the function name (i.e. "hello_world")
for (int i = 0; i < 100; i++)
/* Another scoped tracepoint, but we can set the label manually */
printf("2 * %d = %d\n", i, 2*i);
int main(int argc, char** argv)
/* initialize HawkTracer library */
ht_init(argc, argv);
HT_ErrorCode error_code;
/* Create a listener, it'll handle all the HawkTracer events */
HT_FileDumpListener* listener = ht_file_dump_listener_create("hello-world-out.htdump", 2048, &error_code);
/* Creating listener might fail (e.g. file can't be open),
* so we have to check the status
if (!listener)
printf("Unable to create listener. Error code: %d\n", error_code);
return -1;
/* Register listener to the global timeline */
ht_timeline_register_listener(ht_global_timeline_get(), ht_file_dump_listener_callback, listener);
/* Run the actual code */
/* Flush all the buffered events in a timeline */
/* Unregister all the listeners from the global timeline, so we can safely destroy them */
/* Destroy listeners */
/* Uninitialize HawkTracer library */
return 0;
You can’t perform that action at this time.