mirror of
https://github.com/gperftools/gperftools
synced 2025-01-03 13:12:02 +00:00
Small performance tweak: avoid calling time() if we don't need it
This commit is contained in:
parent
db8d483609
commit
06f4ce65c2
@ -272,7 +272,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) {
|
||||
@ -293,13 +293,15 @@ 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), "%" PRId64 " sec since the last dump",
|
||||
current_time - last_dump_time);
|
||||
need_to_dump = true;
|
||||
last_dump_time = current_time;
|
||||
} else if (FLAGS_heap_profile_time_interval > 0 ) {
|
||||
int64 current_time = time(NULL);
|
||||
if (current_time - last_dump_time >=
|
||||
FLAGS_heap_profile_time_interval) {
|
||||
snprintf(buf, sizeof(buf), "%" PRId64 " 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);
|
||||
|
Loading…
Reference in New Issue
Block a user