Skip to content

Commit

Permalink
Small performance tweak: avoid calling time() if we don't need it
Browse files Browse the repository at this point in the history
  • Loading branch information
iivlev authored and alk committed Jun 26, 2016
1 parent db8d483 commit 06f4ce6
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/heap-profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit 06f4ce6

Please sign in to comment.