1 /* Copyright (c) 2005, Google Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
31 * Author: Sanjay Ghemawat
33 * Module for heap-profiling.
35 * For full(er) information, see doc/heapprofile.html
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:
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.
45 * 2. Programmatically, start and stop the profiler using the
46 * routines "HeapProfilerStart(filename)" and "HeapProfilerStop()".
50 #ifndef BASE_HEAP_PROFILER_H_
51 #define BASE_HEAP_PROFILER_H_
55 /* Annoying stuff for windows; makes sure clients can import these functions */
56 #ifndef PERFTOOLS_DLL_DECL
58 # define PERFTOOLS_DLL_DECL __declspec(dllimport)
60 # define PERFTOOLS_DLL_DECL
64 /* All this code should be usable from within C apps. */
69 /* Start profiling and arrange to write profile data to file names
70 * of the form: "prefix.0000", "prefix.0001", ...
72 PERFTOOLS_DLL_DECL
void HeapProfilerStart(const char* prefix
);
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.
80 int IsHeapProfilerRunning();
82 /* Stop heap profiling. Can be restarted again with HeapProfilerStart(),
83 * but the currently accumulated profiling information will be cleared.
85 PERFTOOLS_DLL_DECL
void HeapProfilerStop();
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
91 PERFTOOLS_DLL_DECL
void HeapProfilerDump(const char *reason
);
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.
98 PERFTOOLS_DLL_DECL
char* GetHeapProfile();
104 #endif /* BASE_HEAP_PROFILER_H_ */