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

Unified Diff: test/cctest/test-heap-profiler.cc

Issue 27227005: Record allocation stack traces (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
Index: test/cctest/test-heap-profiler.cc
diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc
index 6b452960b5ecb3c6746459583213b4e6e653ead3..a023e561fce66befe7acffc95ae0a27653247254 100644
--- a/test/cctest/test-heap-profiler.cc
+++ b/test/cctest/test-heap-profiler.cc
@@ -2021,3 +2021,75 @@ TEST(HeapObjectsTracker) {
"for (var i = 0; i < 3; ++i)"
" a.shift();\n");
}
+
+
+static const char* record_allocation_traces_source =
+"var topFunctions = [];\n"
+"var global = this;\n"
+"var calls = 0;\n"
+"function generateFunctions(width, depth) {\n"
+" var script = [];\n"
+" for (var i = 0; i < width; i++) {\n"
+" for (var j = 0; j < depth; j++) {\n"
+" script.push('function f_' + i + '_' + j + '(x) {\\n');\n"
+" script.push(' try {\\n');\n"
+" if (j < depth-2) {\n"
+" script.push(' return f_' + i + '_' + (j+1) + '(x+1);\\n');\n"
loislo 2013/10/16 15:14:08 80 symbols
yurys 2013/10/17 15:27:35 Done.
+" } else if (j == depth - 2) {\n"
+" script.push(' return new f_' + i + '_' + (depth - 1) + '();\\n');\n"
loislo 2013/10/16 15:14:08 80 symbols
yurys 2013/10/17 15:27:35 Done.
+" } else if (j == depth - 1) {\n"
+" script.push(' /*++calls; empty */\\n');\n"
+" }\n"
+" script.push(' } catch (e) {}\\n');\n"
+" script.push('}\\n');\n"
+" \n"
+" }\n"
+" }\n"
+" var script = script.join('');\n"
+" global.eval(script);\n"
+" for (var i = 0; i < width; i++) {\n"
+" topFunctions.push(this['f_' + i + '_0']);\n"
+" }\n"
+"}\n"
+"\n"
+"var width = 5;\n"
+"var depth = 5;\n"
+"generateFunctions(width, depth);\n"
+"var instances = [];\n"
+"function start() {\n"
+" for (var i = 0; i < width; i++) {\n"
+" instances.push(topFunctions[i](0));\n"
+" }\n"
+"}\n"
+"\n"
+"for (var i = 0; i < 1000; i++) start();\n";
+
+
+class StreamPrinter : public v8::OutputStream {
+ public:
+ virtual void EndOfStream() {
+ }
+ virtual int GetChunkSize() { return 1024; }
+ virtual WriteResult WriteAsciiChunk(char* data, int size) {
+// for (int i = 0; i < size; i++) {
+// printf("%c", data[i]);
+// }
+ return kContinue;
+ }
+};
+
+TEST(RecordAllocationTraces) {
+ v8::HandleScope scope(v8::Isolate::GetCurrent());
+ LocalContext env;
+ HeapObjectsTracker tracker;
+
+ CompileRun(record_allocation_traces_source);
+
+
+ // Print heap snapshot with collected allocation traces.
+ v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
+ const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(
+ v8::String::New("Test"));
+ StreamPrinter printer;
+ snapshot->Serialize(&printer, v8::HeapSnapshot::kJSON);
+}

Powered by Google App Engine
This is Rietveld 408576698