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

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

Issue 12211008: Add a benchmarking_extension API to call TCMalloc's HeapProfilerDump(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed the comment Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/renderer/memory_benchmarking_extension.h"
6
7 #include "base/string_util.h"
8 #include "content/public/renderer/render_thread.h"
9
10 #if !defined(NO_TCMALLOC) && defined(OS_LINUX)
11 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h"
12 #endif // !defined(NO_TCMALLOC) && defined(OS_LINUX)
13
14 namespace {
15
16 const char kMemoryBenchmarkingExtensionName[] = "v8/MemoryBenchmarking";
17
18 }
19
20 namespace {
21
22 class MemoryBenchmarkingWrapper : public v8::Extension {
23 public:
24 MemoryBenchmarkingWrapper() :
25 v8::Extension(kMemoryBenchmarkingExtensionName,
26 "if (typeof(chrome) == 'undefined') {"
27 " chrome = {};"
28 "};"
29 "if (typeof(chrome.memoryBenchmarking) == 'undefined') {"
30 " chrome.memoryBenchmarking = {};"
31 "};"
32 "chrome.memoryBenchmarking.isHeapProfilerRunning = function() {"
33 " native function IsHeapProfilerRunning();"
34 " return IsHeapProfilerRunning();"
35 "};"
36 "chrome.memoryBenchmarking.heapProfilerDump = function(reason) {"
37 " native function HeapProfilerDump();"
38 " HeapProfilerDump(reason);"
39 "};"
40 ) {}
41
42 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
43 v8::Handle<v8::String> name) {
44 if (name->Equals(v8::String::New("IsHeapProfilerRunning")))
45 return v8::FunctionTemplate::New(IsHeapProfilerRunning);
46 else if (name->Equals(v8::String::New("HeapProfilerDump")))
47 return v8::FunctionTemplate::New(HeapProfilerDump);
48
49 return v8::Handle<v8::FunctionTemplate>();
50 }
51
52 static v8::Handle<v8::Value> IsHeapProfilerRunning(
53 const v8::Arguments& args) {
54 #if !defined(NO_TCMALLOC) && defined(OS_LINUX)
55 return v8::Boolean::New(::IsHeapProfilerRunning());
56 #else
57 return v8::Boolean::New(false);
58 #endif // !defined(NO_TCMALLOC) && defined(OS_LINUX)
59 }
60
61 static v8::Handle<v8::Value> HeapProfilerDump(const v8::Arguments& args) {
62 #if !defined(NO_TCMALLOC) && defined(OS_LINUX)
63 std::string reason("benchmarking_extension");
64 if (args.Length() && args[0]->IsString())
65 reason = *v8::String::AsciiValue(args[0]);
66 ::HeapProfilerDump(reason.c_str());
67 #endif // !defined(NO_TCMALLOC) && defined(OS_LINUX)
68 return v8::Undefined();
69 }
70 };
71
72 } // namespace
73
74 namespace content {
75
76 v8::Extension* MemoryBenchmarkingExtension::Get() {
77 return new MemoryBenchmarkingWrapper();
78 }
79
80 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/memory_benchmarking_extension.h ('k') | content/renderer/render_thread_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698