summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchappedm@gmail.com <chappedm@gmail.com@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2012-11-03 15:40:01 +0000
committerchappedm@gmail.com <chappedm@gmail.com@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2012-11-03 15:40:01 +0000
commit87699c97cc07b30fc2765415853ae685f7bc45f2 (patch)
tree9d95e8cf9e8dab136d0b5465c267beeb99be5e94
parent4eb6946d689bbaa74f8be78265f6d6ff9ae04ab2 (diff)
downloadgperftools-87699c97cc07b30fc2765415853ae685f7bc45f2.tar.gz
issue-478: Added the heap profiler tunnable setting HEAP_PROFILER_TIME_INTERVAL used to dump heap profiles on a specified time interval.
git-svn-id: http://gperftools.googlecode.com/svn/trunk@169 6b5cf1ce-ec42-a296-1ba9-69fdba395a50
-rw-r--r--doc/heapprofile.html11
-rw-r--r--src/heap-profiler.cc14
2 files changed, 24 insertions, 1 deletions
diff --git a/doc/heapprofile.html b/doc/heapprofile.html
index 5c64c9b..67861d5 100644
--- a/doc/heapprofile.html
+++ b/doc/heapprofile.html
@@ -91,7 +91,7 @@ environment variables.</p>
<td><code>HEAP_PROFILE_ALLOCATION_INTERVAL</code></td>
<td>default: 1073741824 (1 Gb)</td>
<td>
- Dump heap profiling information once every specified number of
+ Dump heap profiling information each time the specified number of
bytes has been allocated by the program.
</td>
</tr>
@@ -106,6 +106,15 @@ environment variables.</p>
</tr>
<tr valign=top>
+ <td><code>HEAP_PROFILE_TIME_INTERVAL</code></td>
+ <td>default: 104857600 (100 Mb)</td>
+ <td>
+ Dump heap profiling information each time the specified
+ number of seconds has elapsed.
+ </td>
+</tr>
+
+<tr valign=top>
<td><code>HEAP_PROFILE_MMAP</code></td>
<td>default: false</td>
<td>
diff --git a/src/heap-profiler.cc b/src/heap-profiler.cc
index 09a3911..eae2e08 100644
--- a/src/heap-profiler.cc
+++ b/src/heap-profiler.cc
@@ -107,6 +107,10 @@ DEFINE_int64(heap_profile_inuse_interval,
"If non-zero, dump heap profiling information whenever "
"the high-water memory usage mark increases by the specified "
"number of bytes.");
+DEFINE_int64(heap_profile_time_interval,
+ EnvToInt64("HEAP_PROFILE_TIME_INTERVAL", 0),
+ "If non-zero, dump heap profiling information once every "
+ "specified number of seconds since the last dump.");
DEFINE_bool(mmap_log,
EnvToBool("HEAP_PROFILE_MMAP_LOG", false),
"Should mmap/munmap calls be logged?");
@@ -168,6 +172,7 @@ static int dump_count = 0; // How many dumps so far
static int64 last_dump_alloc = 0; // alloc_size when did we last dump
static int64 last_dump_free = 0; // free_size when did we last dump
static int64 high_water_mark = 0; // In-use-bytes at last high-water dump
+static int64 last_dump_time = 0; // The time of the last dump
static HeapProfileTable* heap_profile = NULL; // the heap profile table
@@ -264,6 +269,7 @@ static void MaybeDumpProfileLocked() {
const int64 inuse_bytes = total.alloc_size - total.free_size;
bool need_to_dump = false;
char buf[128];
+ int64 current_time = time(NULL);
if (FLAGS_heap_profile_allocation_interval > 0 &&
total.alloc_size >=
last_dump_alloc + FLAGS_heap_profile_allocation_interval) {
@@ -284,6 +290,13 @@ static void MaybeDumpProfileLocked() {
snprintf(buf, sizeof(buf), "%"PRId64" MB currently in use",
inuse_bytes >> 20);
need_to_dump = true;
+ } else if (FLAGS_heap_profile_time_interval > 0 &&
+ current_time - last_dump_time >=
+ FLAGS_heap_profile_time_interval) {
+ snprintf(buf, sizeof(buf), "%d sec since the last dump",
+ current_time - last_dump_time);
+ need_to_dump = true;
+ last_dump_time = current_time;
}
if (need_to_dump) {
DumpProfileLocked(buf);
@@ -447,6 +460,7 @@ extern "C" void HeapProfilerStart(const char* prefix) {
last_dump_alloc = 0;
last_dump_free = 0;
high_water_mark = 0;
+ last_dump_time = 0;
// We do not reset dump_count so if the user does a sequence of
// HeapProfilerStart/HeapProfileStop, we will get a continuous