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

Side by Side Diff: chrome/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 comments 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
« no previous file with comments | « chrome/renderer/memory_benchmarking_extension.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/renderer/memory_benchmarking_extension.h"
6
7 #include "base/string_util.h"
8 #include "chrome/common/benchmarking_messages.h"
9 #include "content/public/renderer/render_thread.h"
10 #if !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS))
jochen (gone - plz use gerrit) 2013/02/06 11:57:57 #if clauses should come after all includes with an
Dai Mikurube (NOT FULLTIME) 2013/02/06 12:24:45 Done.
11 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h"
12 #endif // !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS))
13 #include "v8/include/v8.h"
14
15 const char kMemoryBenchmarkingExtensionName[] = "v8/MemoryBenchmarking";
jochen (gone - plz use gerrit) 2013/02/06 11:57:57 should also go into an anonymous namespace
Dai Mikurube (NOT FULLTIME) 2013/02/06 12:24:45 Done.
16
17 namespace extensions_v8 {
18
19 class MemoryBenchmarkingWrapper : public v8::Extension {
jochen (gone - plz use gerrit) 2013/02/06 11:57:57 this class and the static functions below should g
Dai Mikurube (NOT FULLTIME) 2013/02/06 12:24:45 In an anonymous namespace, how can I call MemoryBe
jochen (gone - plz use gerrit) 2013/02/06 12:31:41 I meant that the Wrapper should go into the anon n
Dai Mikurube (NOT FULLTIME) 2013/02/06 12:38:01 Makes sense. Done.
20 public:
21 MemoryBenchmarkingWrapper() :
22 v8::Extension(kMemoryBenchmarkingExtensionName,
jochen (gone - plz use gerrit) 2013/02/06 11:57:57 usually, we put the code in a .js file in the reso
Dai Mikurube (NOT FULLTIME) 2013/02/06 12:24:45 Almost all the benchmarking_extension does this.
jochen (gone - plz use gerrit) 2013/02/06 12:31:41 I'd argue they do it wrong :)
23 "if (typeof(chrome) == 'undefined') {"
24 " chrome = {};"
jochen (gone - plz use gerrit) 2013/02/06 12:31:41 this should be just chrome = chrome || {}; chrom
Dai Mikurube (NOT FULLTIME) 2013/02/06 12:38:01 IIRC, they have different meaning in JS. I'm not
25 "};"
26 "if (typeof(chrome.benchmarking) == 'undefined') {"
27 " chrome.benchmarking = {};"
28 "};"
29 "chrome.benchmarking.isHeapProfilerRunning = function() {"
30 " native function IsHeapProfilerRunning();"
31 " return IsHeapProfilerRunning();"
32 "};"
33 "chrome.benchmarking.heapProfilerDump = function(reason) {"
34 " native function HeapProfilerDump();"
35 " HeapProfilerDump(reason);"
36 "};"
37 ) {}
38
39 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
40 v8::Handle<v8::String> name) {
41 if (name->Equals(v8::String::New("IsHeapProfilerRunning"))) {
jochen (gone - plz use gerrit) 2013/02/06 12:31:41 no { } for single-line bodies
Dai Mikurube (NOT FULLTIME) 2013/02/06 12:38:01 Done.
42 return v8::FunctionTemplate::New(IsHeapProfilerRunning);
43 } else if (name->Equals(v8::String::New("HeapProfilerDump"))) {
44 return v8::FunctionTemplate::New(HeapProfilerDump);
45 }
46
47 return v8::Handle<v8::FunctionTemplate>();
48 }
49
50 static v8::Handle<v8::Value>
51 IsHeapProfilerRunning(const v8::Arguments& args) {
jochen (gone - plz use gerrit) 2013/02/06 11:57:57 i think you should wrap after IsHeapProfilerRunnin
Dai Mikurube (NOT FULLTIME) 2013/02/06 12:24:45 Done.
52 #if !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS))
53 return v8::Boolean::New(::IsHeapProfilerRunning());
54 #else
55 return v8::Boolean::New(false);
56 #endif // !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS))
57 }
58
59 static v8::Handle<v8::Value> HeapProfilerDump(const v8::Arguments& args) {
60 #if !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS))
61 char reason[256];
jochen (gone - plz use gerrit) 2013/02/06 11:57:57 why not std::string reason("benchmarking_extensi
Dai Mikurube (NOT FULLTIME) 2013/02/06 12:24:45 Done. I didn't know AsciiValue(). I did the same
62 if (args.Length() && args[0]->IsString())
63 args[0]->ToString()->WriteAscii(reason, 0, sizeof(reason) - 1);
64 else
65 base::strlcpy(reason, "benchmarking_extension", sizeof(reason));
66
67 ::HeapProfilerDump(reason);
68 #endif // !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS))
69 return v8::Undefined();
70 }
71 };
72
73 v8::Extension* MemoryBenchmarkingExtension::Get() {
74 return new MemoryBenchmarkingWrapper();
75 }
76
77 } // namespace extensions_v8
OLDNEW
« no previous file with comments | « chrome/renderer/memory_benchmarking_extension.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698