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