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

Side by Side Diff: content/renderer/memory_benchmarking_extension.cc

Issue 15082004: Adds chrome.memoryBenchmarking.heapProfilerDump for the browser process. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removes return value Created 7 years, 7 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
OLDNEW
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"
Dai Mikurube (NOT FULLTIME) 2013/05/15 10:24:04 This "heap-profiler.h" should be included only whe
bulach 2013/05/15 10:58:29 Done.
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 {
23 public: 23 public:
24 MemoryBenchmarkingWrapper() : 24 MemoryBenchmarkingWrapper() :
25 v8::Extension(kMemoryBenchmarkingExtensionName, 25 v8::Extension(kMemoryBenchmarkingExtensionName,
26 "if (typeof(chrome) == 'undefined') {" 26 "if (typeof(chrome) == 'undefined') {"
27 " chrome = {};" 27 " chrome = {};"
28 "};" 28 "};"
29 "if (typeof(chrome.memoryBenchmarking) == 'undefined') {" 29 "if (typeof(chrome.memoryBenchmarking) == 'undefined') {"
30 " chrome.memoryBenchmarking = {};" 30 " chrome.memoryBenchmarking = {};"
31 "};" 31 "};"
32 "chrome.memoryBenchmarking.isHeapProfilerRunning = function() {" 32 "chrome.memoryBenchmarking.isHeapProfilerRunning = function() {"
33 " native function IsHeapProfilerRunning();" 33 " native function IsHeapProfilerRunning();"
34 " return IsHeapProfilerRunning();" 34 " return IsHeapProfilerRunning();"
35 "};" 35 "};"
36 "chrome.memoryBenchmarking.heapProfilerDump = function(reason) {" 36 "chrome.memoryBenchmarking.heapProfilerDump = "
37 " function(reason, process) {"
Dai Mikurube (NOT FULLTIME) 2013/05/15 10:24:04 I wonder if we could order it as (process_type, re
bulach 2013/05/15 10:58:29 sounds reasonable, done.
37 " native function HeapProfilerDump();" 38 " native function HeapProfilerDump();"
38 " return HeapProfilerDump(reason);" 39 " return HeapProfilerDump(reason, process);"
Dai Mikurube (NOT FULLTIME) 2013/05/15 10:36:55 Same argument order for this HeapProfilerDump(). A
bulach 2013/05/15 10:58:29 Done.
39 "};" 40 "};"
40 ) {} 41 ) {}
41 42
42 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 43 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
43 v8::Handle<v8::String> name) OVERRIDE { 44 v8::Handle<v8::String> name) OVERRIDE {
44 if (name->Equals(v8::String::New("IsHeapProfilerRunning"))) 45 if (name->Equals(v8::String::New("IsHeapProfilerRunning")))
45 return v8::FunctionTemplate::New(IsHeapProfilerRunning); 46 return v8::FunctionTemplate::New(IsHeapProfilerRunning);
46 else if (name->Equals(v8::String::New("HeapProfilerDump"))) 47 else if (name->Equals(v8::String::New("HeapProfilerDump")))
47 return v8::FunctionTemplate::New(HeapProfilerDump); 48 return v8::FunctionTemplate::New(HeapProfilerDump);
48 49
49 return v8::Handle<v8::FunctionTemplate>(); 50 return v8::Handle<v8::FunctionTemplate>();
50 } 51 }
51 52
52 static v8::Handle<v8::Value> IsHeapProfilerRunning( 53 static v8::Handle<v8::Value> IsHeapProfilerRunning(
53 const v8::Arguments& args) { 54 const v8::Arguments& args) {
54 #if !defined(NO_TCMALLOC) && defined(OS_LINUX)
55 return v8::Boolean::New(::IsHeapProfilerRunning()); 55 return v8::Boolean::New(::IsHeapProfilerRunning());
56 #else 56 }
57 return v8::Boolean::New(false); 57
58 #endif // !defined(NO_TCMALLOC) && defined(OS_LINUX) 58 static void HeapProfilerDumpBrowser(const std::string& reason) {
59 content::RenderThreadImpl::current()->Send(
60 new MemoryBenchmarkHostMsg_HeapProfilerDump(reason));
59 } 61 }
60 62
61 static v8::Handle<v8::Value> HeapProfilerDump(const v8::Arguments& args) { 63 static v8::Handle<v8::Value> HeapProfilerDump(const v8::Arguments& args) {
62 #if !defined(NO_TCMALLOC) && defined(OS_LINUX)
63 char dumped_filename_buffer[1000];
64 std::string reason("benchmarking_extension"); 64 std::string reason("benchmarking_extension");
65 if (args.Length() && args[0]->IsString()) 65 if (args.Length() && args[0]->IsString())
66 reason = *v8::String::AsciiValue(args[0]); 66 reason = *v8::String::AsciiValue(args[0]);
67 ::HeapProfilerDumpWithFileName(reason.c_str(), 67 std::string process;
68 dumped_filename_buffer, 68 if (args.Length() > 1 && args[1]->IsString())
69 sizeof(dumped_filename_buffer)); 69 process = *v8::String::AsciiValue(args[1]);
70 return v8::String::New(dumped_filename_buffer); 70 if (process == "browser") {
71 #endif // !defined(NO_TCMALLOC) && defined(OS_LINUX) 71 content::RenderThreadImpl::current()->Send(
72 new MemoryBenchmarkHostMsg_HeapProfilerDump(reason));
73 } else {
74 ::HeapProfilerDump(reason.c_str());
75 }
72 return v8::Undefined(); 76 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))
Dai Mikurube (NOT FULLTIME) 2013/05/15 10:24:04 I think these functions (at least chrome.memoryBen
bulach 2013/05/15 10:58:29 hmm.. see the comment from palmer, I suppose if we
Dai Mikurube (NOT FULLTIME) 2013/05/15 12:04:20 Hmm, makes sense. Ok. :)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698