Chromium Code Reviews| Index: content/renderer/memory_benchmarking_extension.cc |
| diff --git a/content/renderer/memory_benchmarking_extension.cc b/content/renderer/memory_benchmarking_extension.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4e55390f3328b119a0f8588d6e9c6d5389c27e2b |
| --- /dev/null |
| +++ b/content/renderer/memory_benchmarking_extension.cc |
| @@ -0,0 +1,80 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/renderer/memory_benchmarking_extension.h" |
| + |
| +#include "base/string_util.h" |
| +#include "content/public/renderer/render_thread.h" |
| + |
| +#if !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) |
|
piman
2013/02/06 18:11:51
nit: on chromeos=1 OS_LINUX is still defined so yo
Dai Mikurube (NOT FULLTIME)
2013/02/07 00:41:42
Removed.
|
| +#include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" |
| +#endif // !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) |
| + |
| +namespace { |
| + |
| +const char kMemoryBenchmarkingExtensionName[] = "v8/MemoryBenchmarking"; |
| + |
| +} |
| + |
| +namespace { |
| + |
| +class MemoryBenchmarkingWrapper : public v8::Extension { |
| + public: |
| + MemoryBenchmarkingWrapper() : |
| + v8::Extension(kMemoryBenchmarkingExtensionName, |
| + "if (typeof(chrome) == 'undefined') {" |
| + " chrome = {};" |
| + "};" |
| + "if (typeof(chrome.memoryBenchmarking) == 'undefined') {" |
| + " chrome.memoryBenchmarking = {};" |
| + "};" |
| + "chrome.memoryBenchmarking.isHeapProfilerRunning = function() {" |
| + " native function IsHeapProfilerRunning();" |
| + " return IsHeapProfilerRunning();" |
| + "};" |
| + "chrome.memoryBenchmarking.heapProfilerDump = function(reason) {" |
| + " native function HeapProfilerDump();" |
| + " HeapProfilerDump(reason);" |
| + "};" |
| + ) {} |
| + |
| + virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( |
| + v8::Handle<v8::String> name) { |
| + if (name->Equals(v8::String::New("IsHeapProfilerRunning"))) |
| + return v8::FunctionTemplate::New(IsHeapProfilerRunning); |
| + else if (name->Equals(v8::String::New("HeapProfilerDump"))) |
| + return v8::FunctionTemplate::New(HeapProfilerDump); |
| + |
| + return v8::Handle<v8::FunctionTemplate>(); |
| + } |
| + |
| + static v8::Handle<v8::Value> IsHeapProfilerRunning( |
| + const v8::Arguments& args) { |
| +#if !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) |
| + return v8::Boolean::New(::IsHeapProfilerRunning()); |
| +#else |
| + return v8::Boolean::New(false); |
| +#endif // !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) |
| + } |
| + |
| + static v8::Handle<v8::Value> HeapProfilerDump(const v8::Arguments& args) { |
| +#if !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) |
| + std::string reason("benchmarking_extension"); |
| + if (args.Length() && args[0]->IsString()) |
| + reason = *v8::String::AsciiValue(args[0]); |
| + ::HeapProfilerDump(reason.c_str()); |
| +#endif // !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) |
| + return v8::Undefined(); |
| + } |
| +}; |
| + |
| +} // namespace |
| + |
| +namespace content { |
| + |
| +v8::Extension* MemoryBenchmarkingExtension::Get() { |
| + return new MemoryBenchmarkingWrapper(); |
| +} |
| + |
| +} // namespace content |