xref: /haiku/src/apps/cortex/support/ProfileBlock.h (revision 1e36cfc2721ef13a187c6f7354dc9cbc485e89d3)
1 // ProfileBlock.h
2 // e.moon 19may99
3 //
4 // Quick'n'dirty profiling tool: create a ProfileBlock on the
5 // stack, giving it a name and a ProfileTarget to reference.
6 // Automatically writes an entry in the target once the
7 // object goes out of scope.
8 
9 #ifndef __PROFILEBLOCK_H__
10 #define __PROFILEBLOCK_H__
11 
12 #include "ProfileTarget.h"
13 #include <KernelKit.h>
14 
15 #include "cortex_defs.h"
16 __BEGIN_CORTEX_NAMESPACE
17 
18 class ProfileBlock {
19 public:					// ctor/dtor
20 	ProfileBlock(ProfileTarget& target, const char* name) :
21 		m_target(target),
22 		m_name(name),
23 		m_initTime(system_time()) {}
24 
25 	~ProfileBlock() {
26 		m_target.addBlockEntry(m_name, system_time()-m_initTime);
27 	}
28 
29 private:
30 	ProfileTarget&		m_target;
31 	const char* const		m_name;
32 	bigtime_t					m_initTime;
33 };
34 
35 __END_CORTEX_NAMESPACE
36 #endif /* __PROFILEBLOCK_H__ */
37