OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "webkit/extensions/v8/heap_profiler_extension.h" | 5 #include "webkit/extensions/v8/heap_profiler_extension.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 | 8 |
9 #if defined(LINUX_USE_TCMALLOC) | 9 #if defined(OS_LINUX) && defined(USE_TCMALLOC) |
10 #include "third_party/tcmalloc/chromium/src/google/heap-profiler.h" | 10 #include "third_party/tcmalloc/chromium/src/google/heap-profiler.h" |
11 #endif | 11 #endif |
12 | 12 |
13 namespace extensions_v8 { | 13 namespace extensions_v8 { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 const char kHeapProfilerExtensionName[] = "v8/HeapProfiler"; | 17 const char kHeapProfilerExtensionName[] = "v8/HeapProfiler"; |
18 | 18 |
19 class HeapProfilerWrapper : public v8::Extension { | 19 class HeapProfilerWrapper : public v8::Extension { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 if (name->Equals(v8::String::New("HeapProfilerStart"))) { | 53 if (name->Equals(v8::String::New("HeapProfilerStart"))) { |
54 return v8::FunctionTemplate::New(HeapProfilerStart); | 54 return v8::FunctionTemplate::New(HeapProfilerStart); |
55 } else if (name->Equals(v8::String::New("HeapProfilerStop"))) { | 55 } else if (name->Equals(v8::String::New("HeapProfilerStop"))) { |
56 return v8::FunctionTemplate::New(HeapProfilerStop); | 56 return v8::FunctionTemplate::New(HeapProfilerStop); |
57 } else if (name->Equals(v8::String::New("HeapProfilerDump"))) { | 57 } else if (name->Equals(v8::String::New("HeapProfilerDump"))) { |
58 return v8::FunctionTemplate::New(HeapProfilerDump); | 58 return v8::FunctionTemplate::New(HeapProfilerDump); |
59 } | 59 } |
60 return v8::Handle<v8::FunctionTemplate>(); | 60 return v8::Handle<v8::FunctionTemplate>(); |
61 } | 61 } |
62 | 62 |
63 #if defined(LINUX_USE_TCMALLOC) | 63 #if defined(OS_LINUX) && defined(USE_TCMALLOC) |
64 static v8::Handle<v8::Value> HeapProfilerStart(const v8::Arguments& args) { | 64 static v8::Handle<v8::Value> HeapProfilerStart(const v8::Arguments& args) { |
65 if (args.Length() >= 1 && args[0]->IsString()) { | 65 if (args.Length() >= 1 && args[0]->IsString()) { |
66 v8::Local<v8::String> js_prefix = args[0]->ToString(); | 66 v8::Local<v8::String> js_prefix = args[0]->ToString(); |
67 char prefix[256]; | 67 char prefix[256]; |
68 js_prefix->WriteAscii(prefix, 0, arraysize(prefix) - 1); | 68 js_prefix->WriteAscii(prefix, 0, arraysize(prefix) - 1); |
69 ::HeapProfilerStart(prefix); | 69 ::HeapProfilerStart(prefix); |
70 } | 70 } |
71 return v8::Undefined(); | 71 return v8::Undefined(); |
72 } | 72 } |
73 | 73 |
(...skipping 28 matching lines...) Expand all Loading... |
102 #endif | 102 #endif |
103 }; | 103 }; |
104 | 104 |
105 } // namespace | 105 } // namespace |
106 | 106 |
107 v8::Extension* HeapProfilerExtension::Get() { | 107 v8::Extension* HeapProfilerExtension::Get() { |
108 return new HeapProfilerWrapper; | 108 return new HeapProfilerWrapper; |
109 } | 109 } |
110 | 110 |
111 } // namespace extensions_v8 | 111 } // namespace extensions_v8 |
OLD | NEW |