OLD | NEW |
| (Empty) |
1 /* Copyright (c) 2005, Google Inc. | |
2 * All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 * | |
30 * --- | |
31 * Author: Sanjay Ghemawat | |
32 * | |
33 * Module for heap-profiling. | |
34 * | |
35 * For full(er) information, see doc/heapprofile.html | |
36 * | |
37 * This module can be linked into your program with | |
38 * no slowdown caused by this unless you activate the profiler | |
39 * using one of the following methods: | |
40 * | |
41 * 1. Before starting the program, set the environment variable | |
42 * "HEAPPROFILE" to be the name of the file to which the profile | |
43 * data should be written. | |
44 * | |
45 * 2. Programmatically, start and stop the profiler using the | |
46 * routines "HeapProfilerStart(filename)" and "HeapProfilerStop()". | |
47 * | |
48 */ | |
49 | |
50 #ifndef BASE_HEAP_PROFILER_H_ | |
51 #define BASE_HEAP_PROFILER_H_ | |
52 | |
53 #include <stddef.h> | |
54 | |
55 /* Annoying stuff for windows; makes sure clients can import these functions */ | |
56 #ifndef PERFTOOLS_DLL_DECL | |
57 # ifdef _WIN32 | |
58 # define PERFTOOLS_DLL_DECL __declspec(dllimport) | |
59 # else | |
60 # define PERFTOOLS_DLL_DECL | |
61 # endif | |
62 #endif | |
63 | |
64 /* All this code should be usable from within C apps. */ | |
65 #ifdef __cplusplus | |
66 extern "C" { | |
67 #endif | |
68 | |
69 /* Start profiling and arrange to write profile data to file names | |
70 * of the form: "prefix.0000", "prefix.0001", ... | |
71 */ | |
72 PERFTOOLS_DLL_DECL void HeapProfilerStart(const char* prefix); | |
73 | |
74 /* Returns non-zero if we are currently profiling the heap. (Returns | |
75 * an int rather than a bool so it's usable from C.) This is true | |
76 * between calls to HeapProfilerStart() and HeapProfilerStop(), and | |
77 * also if the program has been run with HEAPPROFILER, or some other | |
78 * way to turn on whole-program profiling. | |
79 */ | |
80 int IsHeapProfilerRunning(); | |
81 | |
82 /* Stop heap profiling. Can be restarted again with HeapProfilerStart(), | |
83 * but the currently accumulated profiling information will be cleared. | |
84 */ | |
85 PERFTOOLS_DLL_DECL void HeapProfilerStop(); | |
86 | |
87 /* Dump a profile now - can be used for dumping at a hopefully | |
88 * quiescent state in your program, in order to more easily track down | |
89 * memory leaks. Will include the reason in the logged message | |
90 */ | |
91 PERFTOOLS_DLL_DECL void HeapProfilerDump(const char *reason); | |
92 | |
93 /* Generate current heap profiling information. | |
94 * Returns an empty string when heap profiling is not active. | |
95 * The returned pointer is a '\0'-terminated string allocated using malloc() | |
96 * and should be free()-ed as soon as the caller does not need it anymore. | |
97 */ | |
98 PERFTOOLS_DLL_DECL char* GetHeapProfile(); | |
99 | |
100 #ifdef __cplusplus | |
101 } // extern "C" | |
102 #endif | |
103 | |
104 #endif /* BASE_HEAP_PROFILER_H_ */ | |
OLD | NEW |