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

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: palmer's comments 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
« no previous file with comments | « content/content_common.gypi ('k') | content/renderer/render_thread_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
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
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))
OLDNEW
« no previous file with comments | « content/content_common.gypi ('k') | content/renderer/render_thread_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698