| Index: content/renderer/memory_benchmarking_extension.cc
|
| diff --git a/content/renderer/memory_benchmarking_extension.cc b/content/renderer/memory_benchmarking_extension.cc
|
| index 2dbfbda58c2923a096f5bf607516c61975fcd1f6..9838d957b04d7943c261a8e445242a0813f64b99 100644
|
| --- a/content/renderer/memory_benchmarking_extension.cc
|
| +++ b/content/renderer/memory_benchmarking_extension.cc
|
| @@ -5,11 +5,19 @@
|
| #include "content/renderer/memory_benchmarking_extension.h"
|
|
|
| #include "base/string_util.h"
|
| +#include "content/common/memory_benchmark_messages.h"
|
| #include "content/public/renderer/render_thread.h"
|
| -
|
| -#if !defined(NO_TCMALLOC) && defined(OS_LINUX)
|
| +#include "content/renderer/render_view_impl.h"
|
| +#if !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_ANDROID))
|
| +#define HAS_MEMORY_BENCHMARK 1
|
| #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h"
|
| -#endif // !defined(NO_TCMALLOC) && defined(OS_LINUX)
|
| +#endif
|
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
|
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
|
| +
|
| +using content::RenderViewImpl;
|
| +using WebKit::WebFrame;
|
| +using WebKit::WebView;
|
|
|
| namespace {
|
|
|
| @@ -51,24 +59,48 @@ class MemoryBenchmarkingWrapper : public v8::Extension {
|
|
|
| static v8::Handle<v8::Value> IsHeapProfilerRunning(
|
| const v8::Arguments& args) {
|
| -#if !defined(NO_TCMALLOC) && defined(OS_LINUX)
|
| +#if defined(HAS_MEMORY_BENCHMARK)
|
| return v8::Boolean::New(::IsHeapProfilerRunning());
|
| #else
|
| return v8::Boolean::New(false);
|
| -#endif // !defined(NO_TCMALLOC) && defined(OS_LINUX)
|
| +#endif // defined(HAS_MEMORY_BENCHMARK)
|
| + }
|
| +
|
| +#if defined(HAS_MEMORY_BENCHMARK)
|
| + static v8::Handle<v8::Value> HeapProfilerDumpBrowser() {
|
| + WebFrame* web_frame = WebFrame::frameForCurrentContext();
|
| + if (!web_frame)
|
| + return v8::Undefined();
|
| +
|
| + WebView* web_view = web_frame->view();
|
| + if (!web_view)
|
| + return v8::Undefined();
|
| +
|
| + RenderViewImpl* render_view_impl = RenderViewImpl::FromWebView(web_view);
|
| + if (!render_view_impl)
|
| + return v8::Undefined();
|
| + std::string dump_file_name;
|
| +
|
| + render_view_impl->Send(
|
| + new MemoryBenchmarkHostMsg_HeapProfilerDump(
|
| + render_view_impl->routing_id(), &dump_file_name));
|
| + return v8::String::New(dump_file_name.c_str());
|
| }
|
| +#endif // defined(HAS_MEMORY_BENCHMARK)
|
|
|
| static v8::Handle<v8::Value> HeapProfilerDump(const v8::Arguments& args) {
|
| -#if !defined(NO_TCMALLOC) && defined(OS_LINUX)
|
| +#if defined(HAS_MEMORY_BENCHMARK)
|
| char dumped_filename_buffer[1000];
|
| std::string reason("benchmarking_extension");
|
| if (args.Length() && args[0]->IsString())
|
| reason = *v8::String::AsciiValue(args[0]);
|
| + if (reason == "browser")
|
| + return HeapProfilerDumpBrowser();
|
| ::HeapProfilerDumpWithFileName(reason.c_str(),
|
| dumped_filename_buffer,
|
| sizeof(dumped_filename_buffer));
|
| return v8::String::New(dumped_filename_buffer);
|
| -#endif // !defined(NO_TCMALLOC) && defined(OS_LINUX)
|
| +#endif // defined(HAS_MEMORY_BENCHMARK)
|
| return v8::Undefined();
|
| }
|
| };
|
|
|