Debian Codegraph @

CodeLite/performance.h

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // copyright : (C) 2009 by Eran Ifrah
5 // file name : performance.h
6 //
7 // -------------------------------------------------------------------------
8 // A
9 // _____ _ _ _ _
10 // / __ \ | | | | (_) |
11 // | / \/ ___ __| | ___| | _| |_ ___
12 // | | / _ \ / _ |/ _ \ | | | __/ _ )
13 // | \__/\ (_) | (_| | __/ |___| | || __/
14 // \____/\___/ \__,_|\___\_____/_|\__\___|
15 //
16 // F i l e
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 //////////////////////////////////////////////////////////////////////////////
24 //////////////////////////////////////////////////////////////////////////////
25
26 #ifndef __PERFORMANCE_H__
27 #define __PERFORMANCE_H__
28
29 // Usage: in your file that you want to profile, first do this:
30 // #define __PERFORMANCE
31 // #include "performance.h"
32 // (Just comment out the #define __PERFORMANCE when you're done.)
33 //
34 // Then use any of these forms in functions that you want to profile:
35 //
36 // PERF_FUNCTION(); -- put this at the very top of any function to profile the whole function.
37 //
38 // PERF_BLOCK("Your Comment Here") { -- put this around parts of a function you want to profile
39 // [your code here]
40 // }
41 //
42 // PERF_START("Your Comment Here"); -- use this instead when the braces of PERF_BLOCK won't work for you because of scoping issues
43 // [your code here]
44 // PERF_END();
45 //
46 // Output is sent to file "codelite.perf" in the startup directory. The file is opened automatically for you. It is
47 // overwritten on each run.
48 //
49 // Output format is XML, so you can use xml tools, or view the file in a folding editor. Looks like this:
50 // <block name="Function Signature|Your Comment">
51 // <block ...>
52 // ...
53 // </block>
54 // ...
55 // <elapsed .../>
56 // </block>
57 //
58 // The <elapsed> element shows the time spent for the entire block it is in, and includes an optional "unaccounted"
59 // attribute for any ticks not counted by inner blocks (so you know how much time you're missing from profiled
60 // subfunctions).
61
62 #include "codelite_exports.h"
63
64 #ifdef __PERFORMANCE
65 #ifdef __WXMSW__
66 //Uncomment this to globally disable all profiling
67 //#undef __PERFORMANCE
68 #else
69 // Don't change this
70 #undef __PERFORMANCE
71 #endif
72 #endif
73
74 #ifdef __PERFORMANCE
75
76 extern WXDLLIMPEXP_CL void PERF_START(const char* func_name);
77 extern WXDLLIMPEXP_CL void PERF_END();
78 extern WXDLLIMPEXP_CL void PERF_OUTPUT(const char* path);
79
80 struct WXDLLIMPEXP_CL PERF_CLASS {
81 PERF_CLASS(const char *name) : count(0) { PERF_START(name); }
82 ~PERF_CLASS() { PERF_END(); }
83
84 int count;
85 };
86
87 #define PERF_FUNCTION() PERF_CLASS PERF_OBJ(__PRETTY_FUNCTION__)
88 #define PERF_REPEAT(nm,n) for (PERF_CLASS PERF_OBJ(nm); PERF_OBJ.count < (n); PERF_OBJ.count++)
89 #define PERF_BLOCK(nm) PERF_REPEAT(nm,1)
90
91 #else
92
93 #define PERF_START(func_name)
94 #define PERF_END()
95 #define PERF_OUTPUT(path)
96 #define PERF_FUNCTION()
97 #define PERF_REPEAT(nm,n)
98 #define PERF_BLOCK(nm)
99
100 #endif
101
102 #endif // __PERFORMANCE_H__