1 #include "hawktracer/ht_config.h"
2 #include "hawktracer/init.h"
3 #include "hawktracer/scoped_tracepoint.h"
4 #include "internal/registry.h"
5 #include "internal/feature.h"
6 #include "internal/command_line_parser.h"
7 
8 #ifdef HT_USE_PTHREADS
9 #  include "hawktracer/posix_mapped_tracepoint.h"
10 #endif
11 
12 
13 static int _ht_init_counter = 0;
14 
15 void
ht_init(int argc,char ** argv)16 ht_init(int argc, char** argv)
17 {
18     ht_command_line_parse_args(argc, argv);
19 
20     ht_registry_init();
21 
22     HT_REGISTER_EVENT_KLASS(HT_EndiannessInfoEvent);
23     HT_REGISTER_EVENT_KLASS(HT_Event);
24     HT_REGISTER_EVENT_KLASS(HT_EventKlassInfoEvent);
25     HT_REGISTER_EVENT_KLASS(HT_EventKlassFieldInfoEvent);
26     HT_REGISTER_EVENT_KLASS(HT_CallstackBaseEvent);
27     HT_REGISTER_EVENT_KLASS(HT_CallstackIntEvent);
28     HT_REGISTER_EVENT_KLASS(HT_CallstackStringEvent);
29     HT_REGISTER_EVENT_KLASS(HT_StringMappingEvent);
30     HT_REGISTER_EVENT_KLASS(HT_SystemInfoEvent);
31 
32     ht_feature_register_core_features();
33 
34 #ifdef HT_USE_PTHREADS
35     _ht_posix_mapped_tracepoint_init();
36 #endif
37 
38     _ht_init_counter++;
39 }
40 
41 HT_Boolean
ht_is_initialized(void)42 ht_is_initialized(void)
43 {
44     return _ht_init_counter > 0;
45 }
46 
47 void
ht_deinit(void)48 ht_deinit(void)
49 {
50     if (_ht_init_counter > 0 && --_ht_init_counter == 0)
51     {
52 #ifdef HT_USE_PTHREADS
53         _ht_posix_mapped_tracepoint_deinit();
54 #endif
55 
56         ht_registry_deinit();
57     }
58 }
59