Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/profiler_extension.h" | 5 #include "webkit/extensions/v8/profiler_extension.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #if defined(QUANTIFY) | 9 #if defined(QUANTIFY) |
| 10 // this #define is used to prevent people from directly using pure.h | 10 // this #define is used to prevent people from directly using pure.h |
| 11 // instead of profiler.h | 11 // instead of profiler.h |
| 12 #define PURIFY_PRIVATE_INCLUDE | 12 #define PURIFY_PRIVATE_INCLUDE |
| 13 #include "base/third_party/purify/pure.h" | 13 #include "base/third_party/purify/pure.h" |
| 14 #endif // QUANTIFY | 14 #endif // QUANTIFY |
| 15 | 15 |
| 16 #if defined(USE_TCMALLOC) && defined(OS_LINUX) | 16 #if defined(USE_TCMALLOC) && defined(OS_POSIX) && !defined(OS_MACOSX) |
| 17 #include "third_party/tcmalloc/chromium/src/google/profiler.h" | 17 #include "third_party/tcmalloc/chromium/src/google/profiler.h" |
|
Lei Zhang
2011/05/24 00:11:32
does tcmalloc work on non-Linux Unices?
| |
| 18 #endif | 18 #endif |
| 19 | 19 |
| 20 namespace extensions_v8 { | 20 namespace extensions_v8 { |
| 21 | 21 |
| 22 const char kProfilerExtensionName[] = "v8/Profiler"; | 22 const char kProfilerExtensionName[] = "v8/Profiler"; |
| 23 | 23 |
| 24 class ProfilerWrapper : public v8::Extension { | 24 class ProfilerWrapper : public v8::Extension { |
| 25 public: | 25 public: |
| 26 ProfilerWrapper() : | 26 ProfilerWrapper() : |
| 27 v8::Extension(kProfilerExtensionName, | 27 v8::Extension(kProfilerExtensionName, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 } else if (name->Equals(v8::String::New("ProfilerSetThreadName"))) { | 64 } else if (name->Equals(v8::String::New("ProfilerSetThreadName"))) { |
| 65 return v8::FunctionTemplate::New(ProfilerSetThreadName); | 65 return v8::FunctionTemplate::New(ProfilerSetThreadName); |
| 66 } | 66 } |
| 67 return v8::Handle<v8::FunctionTemplate>(); | 67 return v8::Handle<v8::FunctionTemplate>(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 static v8::Handle<v8::Value> ProfilerStart( | 70 static v8::Handle<v8::Value> ProfilerStart( |
| 71 const v8::Arguments& args) { | 71 const v8::Arguments& args) { |
| 72 #if defined(QUANTIFY) | 72 #if defined(QUANTIFY) |
| 73 QuantifyStartRecordingData(); | 73 QuantifyStartRecordingData(); |
| 74 #elif defined(USE_TCMALLOC) && defined(OS_LINUX) | 74 #elif defined(USE_TCMALLOC) && defined(OS_POSIX) && !defined(OS_MACOSX) |
| 75 ::ProfilerStart("chrome-profile"); | 75 ::ProfilerStart("chrome-profile"); |
| 76 #endif | 76 #endif |
| 77 return v8::Undefined(); | 77 return v8::Undefined(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 static v8::Handle<v8::Value> ProfilerStop( | 80 static v8::Handle<v8::Value> ProfilerStop( |
| 81 const v8::Arguments& args) { | 81 const v8::Arguments& args) { |
| 82 #if defined(QUANTIFY) | 82 #if defined(QUANTIFY) |
| 83 QuantifyStopRecordingData(); | 83 QuantifyStopRecordingData(); |
| 84 #elif defined(USE_TCMALLOC) && defined(OS_LINUX) | 84 #elif defined(USE_TCMALLOC) && defined(OS_POSIX) && !defined(OS_MACOSX) |
| 85 ::ProfilerStop(); | 85 ::ProfilerStop(); |
| 86 #endif | 86 #endif |
| 87 return v8::Undefined(); | 87 return v8::Undefined(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 static v8::Handle<v8::Value> ProfilerClearData( | 90 static v8::Handle<v8::Value> ProfilerClearData( |
| 91 const v8::Arguments& args) { | 91 const v8::Arguments& args) { |
| 92 #if defined(QUANTIFY) | 92 #if defined(QUANTIFY) |
| 93 QuantifyClearData(); | 93 QuantifyClearData(); |
| 94 #endif | 94 #endif |
| 95 return v8::Undefined(); | 95 return v8::Undefined(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 static v8::Handle<v8::Value> ProfilerFlush( | 98 static v8::Handle<v8::Value> ProfilerFlush( |
| 99 const v8::Arguments& args) { | 99 const v8::Arguments& args) { |
| 100 #if defined(USE_TCMALLOC) && defined(OS_LINUX) | 100 #if defined(USE_TCMALLOC) && defined(OS_POSIX) && !defined(OS_MACOSX) |
| 101 ::ProfilerFlush(); | 101 ::ProfilerFlush(); |
| 102 #endif | 102 #endif |
| 103 return v8::Undefined(); | 103 return v8::Undefined(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 | 106 |
| 107 static v8::Handle<v8::Value> ProfilerSetThreadName( | 107 static v8::Handle<v8::Value> ProfilerSetThreadName( |
| 108 const v8::Arguments& args) { | 108 const v8::Arguments& args) { |
| 109 if (args.Length() >= 1 && args[0]->IsString()) { | 109 if (args.Length() >= 1 && args[0]->IsString()) { |
| 110 v8::Local<v8::String> inputString = args[0]->ToString(); | 110 v8::Local<v8::String> inputString = args[0]->ToString(); |
| 111 char nameBuffer[256]; | 111 char nameBuffer[256]; |
| 112 inputString->WriteAscii(nameBuffer, 0, sizeof(nameBuffer)-1); | 112 inputString->WriteAscii(nameBuffer, 0, sizeof(nameBuffer)-1); |
| 113 #if defined(QUANTIFY) | 113 #if defined(QUANTIFY) |
| 114 // make a copy since the Quantify function takes a char*, not const char* | 114 // make a copy since the Quantify function takes a char*, not const char* |
| 115 char buffer[512]; | 115 char buffer[512]; |
| 116 base::snprintf(buffer, arraysize(buffer)-1, "%s", name); | 116 base::snprintf(buffer, arraysize(buffer)-1, "%s", name); |
| 117 QuantifySetThreadName(buffer); | 117 QuantifySetThreadName(buffer); |
| 118 #endif | 118 #endif |
| 119 } | 119 } |
| 120 return v8::Undefined(); | 120 return v8::Undefined(); |
| 121 } | 121 } |
| 122 }; | 122 }; |
| 123 | 123 |
| 124 v8::Extension* ProfilerExtension::Get() { | 124 v8::Extension* ProfilerExtension::Get() { |
| 125 return new ProfilerWrapper(); | 125 return new ProfilerWrapper(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 } // namespace extensions_v8 | 128 } // namespace extensions_v8 |
| OLD | NEW |