From 1dd93d965dfd38670326a1b4f2d678ad773e329e Mon Sep 17 00:00:00 2001 From: ulan Date: Thu, 30 Apr 2015 05:14:34 -0700 Subject: [PATCH] Add flag to print stack-trace after n allocations. BUG= Review URL: https://codereview.chromium.org/1104353003 Cr-Commit-Position: refs/heads/master@{#28161} --- src/flag-definitions.h | 2 ++ src/heap/heap-inl.h | 10 ++++++++-- src/isolate.cc | 18 +++++++++--------- src/isolate.h | 6 ++++-- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/flag-definitions.h b/src/flag-definitions.h index cfa1ff2f93..62fd19878a 100644 --- a/src/flag-definitions.h +++ b/src/flag-definitions.h @@ -603,6 +603,8 @@ DEFINE_BOOL(print_max_heap_committed, false, "in name=value format on exit") DEFINE_BOOL(trace_gc_verbose, false, "print more details following each garbage collection") +DEFINE_INT(trace_allocation_stack_interval, -1, + "print stack trace after free-list allocations") DEFINE_BOOL(trace_fragmentation, false, "report fragmentation for old space") DEFINE_BOOL(trace_fragmentation_verbose, false, "report fragmentation for old space (detailed)") diff --git a/src/heap/heap-inl.h b/src/heap/heap-inl.h index 12c46069eb..38deb1f31d 100644 --- a/src/heap/heap-inl.h +++ b/src/heap/heap-inl.h @@ -213,9 +213,9 @@ void Heap::OnAllocationEvent(HeapObject* object, int size_in_bytes) { profiler->AllocationEvent(object->address(), size_in_bytes); } - if (FLAG_verify_predictable) { - ++allocations_count_; + ++allocations_count_; + if (FLAG_verify_predictable) { UpdateAllocationsHash(object); UpdateAllocationsHash(size_in_bytes); @@ -225,6 +225,12 @@ void Heap::OnAllocationEvent(HeapObject* object, int size_in_bytes) { PrintAlloctionsHash(); } } + + if (FLAG_trace_allocation_stack_interval > 0) { + if (allocations_count_ % FLAG_trace_allocation_stack_interval == 0) { + isolate()->PrintStack(stdout, Isolate::kPrintStackConcise); + } + } } diff --git a/src/isolate.cc b/src/isolate.cc index ff94105834..b548fb3870 100644 --- a/src/isolate.cc +++ b/src/isolate.cc @@ -667,14 +667,14 @@ Handle Isolate::CaptureCurrentStackTrace( } -void Isolate::PrintStack(FILE* out) { +void Isolate::PrintStack(FILE* out, PrintStackMode mode) { if (stack_trace_nesting_level_ == 0) { stack_trace_nesting_level_++; StringStream::ClearMentionedObjectCache(this); HeapStringAllocator allocator; StringStream accumulator(&allocator); incomplete_message_ = &accumulator; - PrintStack(&accumulator); + PrintStack(&accumulator, mode); accumulator.OutputToFile(out); InitializeLoggingAndCounters(); accumulator.Log(this); @@ -701,7 +701,7 @@ static void PrintFrames(Isolate* isolate, } -void Isolate::PrintStack(StringStream* accumulator) { +void Isolate::PrintStack(StringStream* accumulator, PrintStackMode mode) { // The MentionedObjectCache is not GC-proof at the moment. DisallowHeapAllocation no_gc; DCHECK(StringStream::IsMentionedObjectCacheClear(this)); @@ -712,12 +712,12 @@ void Isolate::PrintStack(StringStream* accumulator) { accumulator->Add( "\n==== JS stack trace =========================================\n\n"); PrintFrames(this, accumulator, StackFrame::OVERVIEW); - - accumulator->Add( - "\n==== Details ================================================\n\n"); - PrintFrames(this, accumulator, StackFrame::DETAILS); - - accumulator->PrintMentionedObjectCache(this); + if (mode == kPrintStackVerbose) { + accumulator->Add( + "\n==== Details ================================================\n\n"); + PrintFrames(this, accumulator, StackFrame::DETAILS); + accumulator->PrintMentionedObjectCache(this); + } accumulator->Add("=====================\n\n"); } diff --git a/src/isolate.h b/src/isolate.h index b9f842e767..37d832d25d 100644 --- a/src/isolate.h +++ b/src/isolate.h @@ -712,9 +712,11 @@ class Isolate { int frame_limit, StackTrace::StackTraceOptions options); + enum PrintStackMode { kPrintStackConcise, kPrintStackVerbose }; void PrintCurrentStackTrace(FILE* out); - void PrintStack(StringStream* accumulator); - void PrintStack(FILE* out); + void PrintStack(StringStream* accumulator, + PrintStackMode mode = kPrintStackVerbose); + void PrintStack(FILE* out, PrintStackMode mode = kPrintStackVerbose); Handle StackTraceString(); NO_INLINE(void PushStackTraceAndDie(unsigned int magic, Object* object,