summaryrefslogtreecommitdiff
path: root/trace.h
blob: 367910ad92a6f59dbc8ae56efb2ec3339657c508 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef _TRACE_H
#define _TRACE_H

#include "timing.h"

#include <string>
#include <map>

namespace ledger {

extern bool trace_mode;

void trace(const std::string& cat, const std::string& str);
void trace_push(const std::string& cat, const std::string& str,
		timing_t& timer);
void trace_pop(const std::string& cat, const std::string& str,
	       timing_t& timer);

#define TRACE(cat, msg)  if (trace_mode) trace(#cat, msg)
#define TRACE_(cat, msg) if (trace_mode) trace(#cat, msg)

#define TRACE_PUSH(cat, msg)					\
  timing_t timer_ ## cat(#cat);					\
  if (trace_mode) trace_push(#cat, msg, timer_ ## cat)

#define TRACE_POP(cat, msg)					\
  if (trace_mode) trace_pop(#cat, msg, timer_ ## cat)

typedef std::multimap<void *, std::string> live_objects_map;
typedef std::pair<void *, std::string>	   live_objects_pair;
typedef std::map<std::string, int>	   object_count_map;
typedef std::pair<std::string, int>	   object_count_pair;

extern live_objects_map live_objects;
extern object_count_map	ctor_count;
extern object_count_map	object_count;
extern object_count_map	live_count;

extern bool tracing_active;

bool trace_ctor(void * ptr, const std::string& name);
bool trace_dtor(void * ptr, const std::string& name);

void report_memory(std::ostream& out);

#define TRACE_CTOR(cls) CONFIRM(ledger::trace_ctor(this, cls))
#define TRACE_DTOR(cls) CONFIRM(ledger::trace_dtor(this, cls))

} // namespace ledger

#endif // _TRACE_H