summaryrefslogtreecommitdiff
path: root/src/google
diff options
context:
space:
mode:
authorcsilvers <csilvers@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2007-03-22 04:44:18 +0000
committercsilvers <csilvers@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2007-03-22 04:44:18 +0000
commitee5805f1296f8546c16f90d5427efa347a5f7338 (patch)
tree38870545181491e1e98bd7cd901d8d276d1bc223 /src/google
parentbc455d7b63949fab94ed9518d277866e95f08768 (diff)
downloadgperftools-ee5805f1296f8546c16f90d5427efa347a5f7338.tar.gz
Wed Oct 26 15:19:16 2005 Google Inc. <opensource@google.com>
* Decrease fragmentation in tcmalloc (lefevere) * Support for ARM in some of the thread-specific code (markus) * Turn off heap-checker for statically-linked binaries, which cause error leak reports now (etune) * Many pprof improvements, including a command-line interface (jeff) * CPU profiling now automatically affects all threads in linux 2.6. (Kernel bugs break CPU profiling and threads in linux 2.4 a bit.) ProfilerEnable() and ProfilerDisable() are deprecated. (sanjay) * tcmalloc now correctly intercepts memalign (m3b, maxim) * Syntax fix: added missing va_end()s. Helps non-gcc compiling (etune) * Fixed a few coredumper bugs: race condition after PTRACE_DETACH, ignore non-aligned stackframe pointers (markus, menage) * 64-bit cleanup, especially for spinlock code (etune) and mmap (sanjay) * Better support for finding threads in linux (markus) * tcmalloc now tracks those stack traces that allocate memory (sanjay) * Work around a weird setspecific problem (sanjay) * Fix tcmalloc overflow problems when an alloc is close to 2G/4G (sanjay) git-svn-id: http://gperftools.googlecode.com/svn/trunk@15 6b5cf1ce-ec42-a296-1ba9-69fdba395a50
Diffstat (limited to 'src/google')
-rw-r--r--src/google/heap-checker.h10
-rw-r--r--src/google/malloc_extension.h13
-rw-r--r--src/google/profiler.h77
3 files changed, 69 insertions, 31 deletions
diff --git a/src/google/heap-checker.h b/src/google/heap-checker.h
index ef6c343..c9607ca 100644
--- a/src/google/heap-checker.h
+++ b/src/google/heap-checker.h
@@ -484,9 +484,15 @@ class HeapLeakChecker {
static void DoMainHeapCheck();
// Type of task for UseProcMaps
- enum ProcMapsTask { RECORD_GLOBAL_DATA_LOCKED, DISABLE_LIBRARY_ALLOCS };
+ enum ProcMapsTask {
+ RECORD_GLOBAL_DATA_LOCKED,
+ DISABLE_LIBRARY_ALLOCS
+ };
+ // Success/Error Return codes for UseProcMaps.
+ enum ProcMapsResult { PROC_MAPS_USED, CANT_OPEN_PROC_MAPS,
+ NO_SHARED_LIBS_IN_PROC_MAPS };
// Read /proc/self/maps, parse it, and do the 'proc_maps_task' for each line.
- static void UseProcMaps(ProcMapsTask proc_maps_task);
+ static ProcMapsResult UseProcMaps(ProcMapsTask proc_maps_task);
// A ProcMapsTask to disable allocations from 'library'
// that is mapped to [start_address..end_address)
// (only if library is a certain system library).
diff --git a/src/google/malloc_extension.h b/src/google/malloc_extension.h
index 3de0955..e088154 100644
--- a/src/google/malloc_extension.h
+++ b/src/google/malloc_extension.h
@@ -79,6 +79,15 @@ class MallocExtension {
// contents of "*result" are preserved.
virtual void GetHeapSample(std::string* result);
+ // Get a string that contains the stack traces that caused growth in
+ // the addres sspace size. The format of the returned string is
+ // equivalent to the output of the heap profiler and can therefore
+ // be passed to "pprof".
+ //
+ // The generated data is *appended* to "*result". I.e., the old
+ // contents of "*result" are preserved.
+ virtual void GetHeapGrowthStacks(std::string* result);
+
// -------------------------------------------------------------------
// Control operations for getting and setting malloc implementation
// specific parameters. Some currently useful properties:
@@ -155,6 +164,10 @@ class MallocExtension {
// This is an internal extension. Callers should use the more
// convenient "GetHeapSample(string*)" method defined above.
virtual void** ReadStackTraces();
+
+ // Like ReadStackTraces(), but returns stack traces that caused growth
+ // in the address space size.
+ virtual void** ReadHeapGrowthStackTraces();
};
#endif // _GOOGLE_MALLOC_EXTENSION_H__
diff --git a/src/google/profiler.h b/src/google/profiler.h
index 249d7be..5eea0de 100644
--- a/src/google/profiler.h
+++ b/src/google/profiler.h
@@ -32,20 +32,28 @@
//
// Module for CPU profiling based on periodic pc-sampling.
//
-// To use this module, link it into your program. To activate it
-// at runtime, set the environment variable "CPUPROFILE" to be the
-// name of the file in which the profile data should be written.
-// (If you don't set the environment variable, no profiling will
-// happen, and the program should run without any slowdowns.)
+// To use this module, link it into your program. There should
+// be no slowdown caused by this unless you activate the profiler
+// using one of the steps given below.
//
-// Once you have done this, there are two ways to determine which
-// region(s) of code should be profiled:
+// To activate the profiler, do one of the following:
//
-// 1. If you set the "PROFILESELECTED" environment variable,
-// only regions of code that are surrounded with "ProfilerEnable()"
-// and "ProfilerDisable()" will be profiled.
-// 2. Otherwise, the main thread, and any thread that has had
-// ProfilerRegisterThread() called on it, will be profiled.
+// 1. Before starting the program, set the environment variable
+// "CPUPROFILE" to be the name of the file to which the profile
+// data should be written.
+//
+// 2. Programmatically, start and stop the profiler using
+// the routines "ProfilerStart(filename)" and "ProfilerStop()".
+//
+// All threads in the program are profiled whenever profiling is on.
+// There used to be a mechanism where a subset of the threads could be
+// profiled, but that functionality no longer exists (it would not
+// work correctly in new systems since the interval timer used by the
+// profiler is a per-address-space setting in new systems instead of
+// being a per-thread setting in 2.4 and earlier systems).
+//
+// Limitation: on 2.4 and earlier kernels, just the main thread will
+// be profiled.
//
// Use pprof to view the resulting profile output. If you have dot and
// gv installed, you can also get a graphical representation of CPU usage.
@@ -56,6 +64,8 @@
#ifndef _GOOGLE_PROFILER_H
#define _GOOGLE_PROFILER_H
+#include <time.h> // For time_t
+
// Start profiling and write profile info into fname.
extern bool ProfilerStart(const char* fname);
@@ -63,24 +73,35 @@ extern bool ProfilerStart(const char* fname);
// the currently accumulated profiling data will be cleared.
extern void ProfilerStop();
+// Flush any currently buffered profiling state to the profile file.
+// Has no effect if the profiler has not been started.
+extern void ProfilerFlush();
-// These functions have no effect if profiling has not been activated
-// globally (by specifying the "CPUPROFILE" environment variable or by
-// calling ProfilerStart() ).
-
-// Profile in the given thread. This is most usefully called when a
-// new thread is first entered. Note this may not work if
-// PROFILESELECTED is set.
-extern void ProfilerRegisterThread();
-// Turn profiling on and off, if PROFILESELECTED has been called.
+// DEPRECATED: these functions were used to enable/disable profiling
+// in the current thread, but no longer do anything.
extern void ProfilerEnable();
extern void ProfilerDisable();
-// Write out the current profile information to disk.
-extern void ProfilerFlush();
+// Returns true if profile is currently enabled
+extern bool ProfilingIsEnabledForAllThreads();
+
+// Routine for registering new threads with the profiler. This is
+// most usefully called when a new thread is first entered.
+extern void ProfilerRegisterThread();
+
+// Stores state about profiler's current status into "*state".
+struct ProfilerState {
+ bool enabled; // Is profiling currently enabled?
+ time_t start_time; // If enabled, when was profiling started?
+ char profile_name[1024]; // Name of profile file being written, or '\0'
+ int samples_gathered; // Number of samples gatheered to far (or 0)
+};
+extern void ProfilerGetCurrentState(ProfilerState* state);
// ------------------------- ProfilerThreadState -----------------------
+// DEPRECATED: this class is no longer needed.
+//
// A small helper class that allows a thread to periodically check if
// profiling has been enabled or disabled, and to react appropriately
// to ensure that activity in the current thread is included in the
@@ -92,15 +113,13 @@ extern void ProfilerFlush();
// profile_state.ThreadCheck();
// }
class ProfilerThreadState {
-public:
- ProfilerThreadState();
+ public:
+ ProfilerThreadState() { }
// Called in a thread to enable or disable profiling on the thread
// based on whether profiling is currently on or off.
- void ThreadCheck();
-
-private:
- bool was_enabled_; // True if profiling was on in our last call
+ // DEPRECATED: No longer needed
+ void ThreadCheck() { }
};
#endif /* _GOOGLE_PROFILER_H */