OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/memory_benchmarking_extension.h" | 5 #include "content/renderer/memory_benchmarking_extension.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "content/public/renderer/render_thread.h" | 8 #include "content/common/memory_benchmark_messages.h" |
9 #include "content/renderer/render_thread_impl.h" | |
10 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" | |
9 | 11 |
10 #if !defined(NO_TCMALLOC) && defined(OS_LINUX) | 12 #if defined(USE_TCMALLOC) && (defined(OS_LINUX) || defined(OS_ANDROID)) |
11 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" | |
12 #endif // !defined(NO_TCMALLOC) && defined(OS_LINUX) | |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 const char kMemoryBenchmarkingExtensionName[] = "v8/MemoryBenchmarking"; | 16 const char kMemoryBenchmarkingExtensionName[] = "v8/MemoryBenchmarking"; |
17 | 17 |
18 } | 18 } |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 class MemoryBenchmarkingWrapper : public v8::Extension { | 22 class MemoryBenchmarkingWrapper : public v8::Extension { |
(...skipping 21 matching lines...) Expand all Loading... | |
44 if (name->Equals(v8::String::New("IsHeapProfilerRunning"))) | 44 if (name->Equals(v8::String::New("IsHeapProfilerRunning"))) |
45 return v8::FunctionTemplate::New(IsHeapProfilerRunning); | 45 return v8::FunctionTemplate::New(IsHeapProfilerRunning); |
46 else if (name->Equals(v8::String::New("HeapProfilerDump"))) | 46 else if (name->Equals(v8::String::New("HeapProfilerDump"))) |
47 return v8::FunctionTemplate::New(HeapProfilerDump); | 47 return v8::FunctionTemplate::New(HeapProfilerDump); |
48 | 48 |
49 return v8::Handle<v8::FunctionTemplate>(); | 49 return v8::Handle<v8::FunctionTemplate>(); |
50 } | 50 } |
51 | 51 |
52 static v8::Handle<v8::Value> IsHeapProfilerRunning( | 52 static v8::Handle<v8::Value> IsHeapProfilerRunning( |
53 const v8::Arguments& args) { | 53 const v8::Arguments& args) { |
54 #if !defined(NO_TCMALLOC) && defined(OS_LINUX) | |
55 return v8::Boolean::New(::IsHeapProfilerRunning()); | 54 return v8::Boolean::New(::IsHeapProfilerRunning()); |
56 #else | 55 } |
57 return v8::Boolean::New(false); | 56 |
58 #endif // !defined(NO_TCMALLOC) && defined(OS_LINUX) | 57 static v8::Handle<v8::Value> HeapProfilerDumpBrowser() { |
58 base::FilePath dump_file_name; | |
59 | |
60 content::RenderThreadImpl::current()->Send( | |
61 new MemoryBenchmarkHostMsg_HeapProfilerDump(&dump_file_name)); | |
62 return v8::String::New(dump_file_name.value().c_str(), | |
63 dump_file_name.value().length()); | |
59 } | 64 } |
60 | 65 |
61 static v8::Handle<v8::Value> HeapProfilerDump(const v8::Arguments& args) { | 66 static v8::Handle<v8::Value> HeapProfilerDump(const v8::Arguments& args) { |
62 #if !defined(NO_TCMALLOC) && defined(OS_LINUX) | |
63 char dumped_filename_buffer[1000]; | 67 char dumped_filename_buffer[1000]; |
64 std::string reason("benchmarking_extension"); | 68 std::string reason("benchmarking_extension"); |
65 if (args.Length() && args[0]->IsString()) | 69 if (args.Length() && args[0]->IsString()) |
66 reason = *v8::String::AsciiValue(args[0]); | 70 reason = *v8::String::AsciiValue(args[0]); |
71 if (reason == "browser") | |
Dai Mikurube (NOT FULLTIME)
2013/05/14 20:15:08
Ahh, sorry, I overlooked the important part. I fo
| |
72 return HeapProfilerDumpBrowser(); | |
67 ::HeapProfilerDumpWithFileName(reason.c_str(), | 73 ::HeapProfilerDumpWithFileName(reason.c_str(), |
palmer
2013/05/10 19:53:53
So, the renderer asks the browser for a FilePath (
Dai Mikurube (NOT FULLTIME)
2013/05/10 20:41:30
Yes, this is used under a very limited situation,
| |
68 dumped_filename_buffer, | 74 dumped_filename_buffer, |
69 sizeof(dumped_filename_buffer)); | 75 sizeof(dumped_filename_buffer)); |
70 return v8::String::New(dumped_filename_buffer); | 76 return v8::String::New(dumped_filename_buffer); |
71 #endif // !defined(NO_TCMALLOC) && defined(OS_LINUX) | |
72 return v8::Undefined(); | |
73 } | 77 } |
74 }; | 78 }; |
75 | 79 |
76 } // namespace | 80 } // namespace |
77 | 81 |
78 namespace content { | 82 namespace content { |
79 | 83 |
80 v8::Extension* MemoryBenchmarkingExtension::Get() { | 84 v8::Extension* MemoryBenchmarkingExtension::Get() { |
81 return new MemoryBenchmarkingWrapper(); | 85 return new MemoryBenchmarkingWrapper(); |
82 } | 86 } |
83 | 87 |
84 } // namespace content | 88 } // namespace content |
89 | |
90 #endif // defined(USE_TCMALLOC) && (defined(OS_LINUX) || defined(OS_ANDROID)) | |
OLD | NEW |