OLD | NEW |
---|---|
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 2003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2014 HeapObjectsTracker tracker; | 2014 HeapObjectsTracker tracker; |
2015 CompileRun("var a = 1.2"); | 2015 CompileRun("var a = 1.2"); |
2016 CompileRun("var a = 1.2; var b = 1.0; var c = 1.0;"); | 2016 CompileRun("var a = 1.2; var b = 1.0; var c = 1.0;"); |
2017 CompileRun( | 2017 CompileRun( |
2018 "var a = [];" | 2018 "var a = [];" |
2019 "for (var i = 0; i < 5; ++i)" | 2019 "for (var i = 0; i < 5; ++i)" |
2020 " a[i] = i;\n" | 2020 " a[i] = i;\n" |
2021 "for (var i = 0; i < 3; ++i)" | 2021 "for (var i = 0; i < 3; ++i)" |
2022 " a.shift();\n"); | 2022 " a.shift();\n"); |
2023 } | 2023 } |
2024 | |
2025 | |
2026 static const char* record_allocation_traces_source = | |
2027 "var topFunctions = [];\n" | |
2028 "var global = this;\n" | |
2029 "var calls = 0;\n" | |
2030 "function generateFunctions(width, depth) {\n" | |
2031 " var script = [];\n" | |
2032 " for (var i = 0; i < width; i++) {\n" | |
2033 " for (var j = 0; j < depth; j++) {\n" | |
2034 " script.push('function f_' + i + '_' + j + '(x) {\\n');\n" | |
2035 " script.push(' try {\\n');\n" | |
2036 " if (j < depth-2) {\n" | |
2037 " 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.
| |
2038 " } else if (j == depth - 2) {\n" | |
2039 " 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.
| |
2040 " } else if (j == depth - 1) {\n" | |
2041 " script.push(' /*++calls; empty */\\n');\n" | |
2042 " }\n" | |
2043 " script.push(' } catch (e) {}\\n');\n" | |
2044 " script.push('}\\n');\n" | |
2045 " \n" | |
2046 " }\n" | |
2047 " }\n" | |
2048 " var script = script.join('');\n" | |
2049 " global.eval(script);\n" | |
2050 " for (var i = 0; i < width; i++) {\n" | |
2051 " topFunctions.push(this['f_' + i + '_0']);\n" | |
2052 " }\n" | |
2053 "}\n" | |
2054 "\n" | |
2055 "var width = 5;\n" | |
2056 "var depth = 5;\n" | |
2057 "generateFunctions(width, depth);\n" | |
2058 "var instances = [];\n" | |
2059 "function start() {\n" | |
2060 " for (var i = 0; i < width; i++) {\n" | |
2061 " instances.push(topFunctions[i](0));\n" | |
2062 " }\n" | |
2063 "}\n" | |
2064 "\n" | |
2065 "for (var i = 0; i < 1000; i++) start();\n"; | |
2066 | |
2067 | |
2068 class StreamPrinter : public v8::OutputStream { | |
2069 public: | |
2070 virtual void EndOfStream() { | |
2071 } | |
2072 virtual int GetChunkSize() { return 1024; } | |
2073 virtual WriteResult WriteAsciiChunk(char* data, int size) { | |
2074 // for (int i = 0; i < size; i++) { | |
2075 // printf("%c", data[i]); | |
2076 // } | |
2077 return kContinue; | |
2078 } | |
2079 }; | |
2080 | |
2081 TEST(RecordAllocationTraces) { | |
2082 v8::HandleScope scope(v8::Isolate::GetCurrent()); | |
2083 LocalContext env; | |
2084 HeapObjectsTracker tracker; | |
2085 | |
2086 CompileRun(record_allocation_traces_source); | |
2087 | |
2088 | |
2089 // Print heap snapshot with collected allocation traces. | |
2090 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | |
2091 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot( | |
2092 v8::String::New("Test")); | |
2093 StreamPrinter printer; | |
2094 snapshot->Serialize(&printer, v8::HeapSnapshot::kJSON); | |
2095 } | |
OLD | NEW |