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

Side by Side Diff: src/d8.cc

Issue 8055029: Add experimental support for tracing the state of the VM heap to a file Base URL: http://v8.googlecode.com/svn/branches/experimental/heap-visualization/
Patch Set: Created 9 years, 2 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/api.cc ('k') | src/execution.cc » ('j') | src/spaces.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 i::SmartArrayPointer<char> DumbLineEditor::Prompt(const char* prompt) { 106 i::SmartArrayPointer<char> DumbLineEditor::Prompt(const char* prompt) {
107 static const int kBufferSize = 256; 107 static const int kBufferSize = 256;
108 char buffer[kBufferSize]; 108 char buffer[kBufferSize];
109 printf("%s", prompt); 109 printf("%s", prompt);
110 char* str = fgets(buffer, kBufferSize, stdin); 110 char* str = fgets(buffer, kBufferSize, stdin);
111 return i::SmartArrayPointer<char>(str ? i::StrDup(str) : str); 111 return i::SmartArrayPointer<char>(str ? i::StrDup(str) : str);
112 } 112 }
113 113
114 114
115 class FileHeapVisualizer : public v8::HeapVisualizer {
116 public:
117 explicit FileHeapVisualizer(const char* path) {
118 file_ = i::OS::FOpen(path, "w");
119 }
120
121 ~FileHeapVisualizer() {
122 if (file_ != NULL) fclose(file_);
123 }
124
125 void Write(const char* buf, int len) {
126 fwrite(reinterpret_cast<const void*>(buf), 1, len, file_);
127 }
128
129 bool open_succeeded() { return file_ != NULL; }
130
131 private:
132 FILE* file_;
133 };
134
135
115 CounterMap* Shell::counter_map_; 136 CounterMap* Shell::counter_map_;
116 i::OS::MemoryMappedFile* Shell::counters_file_ = NULL; 137 i::OS::MemoryMappedFile* Shell::counters_file_ = NULL;
117 CounterCollection Shell::local_counters_; 138 CounterCollection Shell::local_counters_;
118 CounterCollection* Shell::counters_ = &local_counters_; 139 CounterCollection* Shell::counters_ = &local_counters_;
119 i::Mutex* Shell::context_mutex_(i::OS::CreateMutex()); 140 i::Mutex* Shell::context_mutex_(i::OS::CreateMutex());
120 Persistent<Context> Shell::utility_context_; 141 Persistent<Context> Shell::utility_context_;
121 LineEditor* Shell::console = NULL; 142 LineEditor* Shell::console = NULL;
122 #endif // V8_SHARED 143 #endif // V8_SHARED
123 144
124 Persistent<Context> Shell::evaluation_context_; 145 Persistent<Context> Shell::evaluation_context_;
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 649
629 #ifdef ENABLE_DEBUGGER_SUPPORT 650 #ifdef ENABLE_DEBUGGER_SUPPORT
630 // Start the in-process debugger if requested. 651 // Start the in-process debugger if requested.
631 if (i::FLAG_debugger && !i::FLAG_debugger_agent) { 652 if (i::FLAG_debugger && !i::FLAG_debugger_agent) {
632 v8::Debug::SetDebugEventListener(HandleDebugEvent); 653 v8::Debug::SetDebugEventListener(HandleDebugEvent);
633 } 654 }
634 #endif // ENABLE_DEBUGGER_SUPPORT 655 #endif // ENABLE_DEBUGGER_SUPPORT
635 } 656 }
636 #endif // V8_SHARED 657 #endif // V8_SHARED
637 658
638
639 #ifdef COMPRESS_STARTUP_DATA_BZ2 659 #ifdef COMPRESS_STARTUP_DATA_BZ2
640 class BZip2Decompressor : public v8::StartupDataDecompressor { 660 class BZip2Decompressor : public v8::StartupDataDecompressor {
641 public: 661 public:
642 virtual ~BZip2Decompressor() { } 662 virtual ~BZip2Decompressor() { }
643 663
644 protected: 664 protected:
645 virtual int DecompressData(char* raw_data, 665 virtual int DecompressData(char* raw_data,
646 int* raw_data_size, 666 int* raw_data_size,
647 const char* compressed_data, 667 const char* compressed_data,
648 int compressed_data_size) { 668 int compressed_data_size) {
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 // Keep using the same context in the interactive shell. 1277 // Keep using the same context in the interactive shell.
1258 evaluation_context_ = context; 1278 evaluation_context_ = context;
1259 #ifndef V8_SHARED 1279 #ifndef V8_SHARED
1260 // If the interactive debugger is enabled make sure to activate 1280 // If the interactive debugger is enabled make sure to activate
1261 // it before running the files passed on the command line. 1281 // it before running the files passed on the command line.
1262 if (i::FLAG_debugger) { 1282 if (i::FLAG_debugger) {
1263 InstallUtilityScript(); 1283 InstallUtilityScript();
1264 } 1284 }
1265 #endif // V8_SHARED 1285 #endif // V8_SHARED
1266 } 1286 }
1287
1288 if (i::FLAG_trace_heap) {
1289 FileHeapVisualizer* visualizer =
1290 new FileHeapVisualizer(i::FLAG_trace_heap_file);
1291 if (visualizer->open_succeeded()) {
1292 RegisterHeapVisualizer(visualizer);
1293 } else {
1294 delete visualizer;
1295 }
1296 }
1297
1267 { 1298 {
1268 Context::Scope cscope(context); 1299 Context::Scope cscope(context);
1269 options.isolate_sources[0].Execute(); 1300 options.isolate_sources[0].Execute();
1270 } 1301 }
1271 if (!options.last_run) { 1302 if (!options.last_run) {
1272 context.Dispose(); 1303 context.Dispose();
1273 } 1304 }
1274 1305
1275 #ifndef V8_SHARED 1306 #ifndef V8_SHARED
1276 // Start preemption if threads have been created and preemption is enabled. 1307 // Start preemption if threads have been created and preemption is enabled.
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1357 } 1388 }
1358 1389
1359 } // namespace v8 1390 } // namespace v8
1360 1391
1361 1392
1362 #ifndef GOOGLE3 1393 #ifndef GOOGLE3
1363 int main(int argc, char* argv[]) { 1394 int main(int argc, char* argv[]) {
1364 return v8::Shell::Main(argc, argv); 1395 return v8::Shell::Main(argc, argv);
1365 } 1396 }
1366 #endif 1397 #endif
OLDNEW
« no previous file with comments | « src/api.cc ('k') | src/execution.cc » ('j') | src/spaces.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698