Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(810)

Unified Diff: runtime/vm/exceptions.cc

Issue 11478012: Provide a mechanism for dumping of heap profiles on predefined events. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/dart.cc ('k') | runtime/vm/heap.h » ('j') | runtime/vm/isolate.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/exceptions.cc
diff --git a/runtime/vm/exceptions.cc b/runtime/vm/exceptions.cc
index ba1dae4cab67ea1d0ddb4139066cd06e4713c278..214a32e30c2a43b22a42e948d0f655d4c759e164 100644
--- a/runtime/vm/exceptions.cc
+++ b/runtime/vm/exceptions.cc
@@ -9,6 +9,7 @@
#include "vm/debugger.h"
#include "vm/flags.h"
#include "vm/object.h"
+#include "vm/object_store.h"
#include "vm/stack_frame.h"
#include "vm/stub_code.h"
#include "vm/symbols.h"
@@ -16,7 +17,9 @@
namespace dart {
DEFINE_FLAG(bool, print_stacktrace_at_throw, false,
- "Prints a stack trace everytime a throw occurs.");
+ "Prints a stack trace everytime a throw occurs.");
+DEFINE_FLAG(bool, heap_profile_out_of_memory, false,
+ "Writes a heap profile on unhandled out-of-memory exceptions.");
const char* Exceptions::kCastErrorDstName = "type cast";
@@ -166,6 +169,22 @@ static void ThrowExceptionHelper(const Instance& incoming_exception,
// There are no dart invocation frames on the stack so we do not
// have a caller to return to.
ASSERT(!handler_exists);
+ if (FLAG_heap_profile_out_of_memory) {
+ Isolate* isolate = Isolate::Current();
+ Instance& out_of_memory =
+ Instance::Handle(isolate->object_store()->out_of_memory());
+ if (incoming_exception.Equals(out_of_memory)) {
+ Instance& out_of_memory =
+ Instance::Handle(isolate->object_store()->out_of_memory());
+ if (incoming_exception.Equals(out_of_memory)) {
siva 2012/12/07 00:33:02 The handle and if check seems to be repeated twice
cshapiro 2012/12/08 07:29:46 Sorry about that. I actually caught this earlier.
+ const char* format = "%s-out-of-memory.hprof";
+ intptr_t len = OS::SNPrint(NULL, 0, format, isolate->name());
+ char* filename = isolate->current_zone()->Alloc<char>(len + 1);
+ OS::SNPrint(filename, len + 1, format, isolate->name());
+ isolate->heap()->ProfileToFile(filename);
siva 2012/12/07 00:33:02 Why not change the signature of ProfileToFile to b
cshapiro 2012/12/08 07:29:46 Good idea. Done. (Saves ~3 places, actually.)
+ }
+ }
+ }
if (Isolate::UnhandledExceptionCallback() != NULL) {
// Notify embedder that an unhandled exception occurred.
Dart_EnterScope();
« no previous file with comments | « runtime/vm/dart.cc ('k') | runtime/vm/heap.h » ('j') | runtime/vm/isolate.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698