Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | |
| 2 // Redistribution and use in source and binary forms, with or without | |
| 3 // modification, are permitted provided that the following conditions are | |
| 4 // met: | |
| 5 // | |
| 6 // * Redistributions of source code must retain the above copyright | |
| 7 // notice, this list of conditions and the following disclaimer. | |
| 8 // * Redistributions in binary form must reproduce the above | |
| 9 // copyright notice, this list of conditions and the following | |
| 10 // disclaimer in the documentation and/or other materials provided | |
| 11 // with the distribution. | |
| 12 // * Neither the name of Google Inc. nor the names of its | |
| 13 // contributors may be used to endorse or promote products derived | |
| 14 // from this software without specific prior written permission. | |
| 15 // | |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 27 | |
| 28 #ifndef V8_V8_PROFILER_H_ | |
| 29 #define V8_V8_PROFILER_H_ | |
| 30 | |
| 31 #include "v8.h" | |
| 32 | |
| 33 #ifdef _WIN32 | |
| 34 // Setup for Windows DLL export/import. See v8.h in this directory for | |
| 35 // information on how to build/use V8 as a DLL. | |
| 36 #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED) | |
| 37 #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\ | |
| 38 build configuration to ensure that at most one of these is set | |
| 39 #endif | |
| 40 | |
| 41 #ifdef BUILDING_V8_SHARED | |
| 42 #define V8EXPORT __declspec(dllexport) | |
| 43 #elif USING_V8_SHARED | |
| 44 #define V8EXPORT __declspec(dllimport) | |
| 45 #else | |
| 46 #define V8EXPORT | |
| 47 #endif | |
| 48 | |
| 49 #else // _WIN32 | |
| 50 | |
| 51 // Setup for Linux shared library export. See v8.h in this directory for | |
| 52 // information on how to build/use V8 as shared library. | |
| 53 #if defined(__GNUC__) && (__GNUC__ >= 4) && defined(V8_SHARED) | |
| 54 #define V8EXPORT __attribute__ ((visibility("default"))) | |
| 55 #else // defined(__GNUC__) && (__GNUC__ >= 4) | |
| 56 #define V8EXPORT | |
| 57 #endif // defined(__GNUC__) && (__GNUC__ >= 4) | |
| 58 | |
| 59 #endif // _WIN32 | |
| 60 | |
| 61 | |
| 62 /** | |
| 63 * Profiler support for the V8 JavaScript engine. | |
| 64 */ | |
| 65 namespace v8 { | |
| 66 | |
| 67 | |
| 68 /** | |
| 69 * CpuProfileNode represents a node in a call graph. | |
| 70 */ | |
| 71 class V8EXPORT CpuProfileNode { | |
| 72 public: | |
| 73 /** Returns function name (empty string for anonymous functions.) */ | |
| 74 Handle<String> GetFunctionName() const; | |
| 75 | |
| 76 /** Returns resource name for script from where the function originates. */ | |
| 77 Handle<Value> GetScriptResourceName() const; | |
| 78 | |
| 79 /** | |
| 80 * Returns the number, 1-based, of the line where the function originates. | |
| 81 * 0 means that no line number information is available. | |
| 82 */ | |
| 83 int GetLineNumber() const; | |
| 84 | |
| 85 /** | |
| 86 * Returns total (self + children) execution time of the function, | |
| 87 * in milliseconds, estimated by samples count. | |
| 88 */ | |
| 89 double GetTotalTime() const; | |
| 90 | |
| 91 /** | |
| 92 * Returns self execution time of the function, in milliseconds, | |
| 93 * estimated by samples count. | |
| 94 */ | |
| 95 double GetSelfTime() const; | |
| 96 | |
| 97 /** Returns the count of samples where function exists. */ | |
| 98 double GetTotalSamplesCount() const; | |
| 99 | |
| 100 /** Returns the count of samples where function was currently executing. */ | |
| 101 double GetSelfSamplesCount() const; | |
| 102 | |
| 103 /** Returns child nodes count of the node. */ | |
| 104 int GetChildrenCount() const; | |
| 105 | |
| 106 /** Retrieves a child node by index. */ | |
| 107 Handle<CpuProfileNode> GetChild(int index) const; | |
| 108 }; | |
| 109 | |
| 110 | |
| 111 /** | |
| 112 * CpuProfile contains a CPU profile in a form of 2 call trees: | |
|
Mads Ager (chromium)
2010/03/23 08:38:26
in a form -> in form
2 -> two?
| |
| 113 * - top-down (from main() down to functions that do all the work); | |
| 114 * - bottom-up call graph (in backward direction). | |
| 115 */ | |
| 116 class V8EXPORT CpuProfile { | |
| 117 public: | |
| 118 /** Returns CPU profile UID (assigned by the profiler.) */ | |
| 119 unsigned GetUid(); const; | |
| 120 | |
| 121 /** Returns CPU profile title. */ | |
| 122 Handle<String> GetTitle() const; | |
| 123 | |
| 124 /** Returns the root node of the bottom up call tree. */ | |
| 125 Handle<CpuProfileNode> GetBottomUpRoot() const; | |
| 126 | |
| 127 /** Returns the root node of the top down call tree. */ | |
| 128 Handle<CpuProfileNode> GetTopDownRoot() const; | |
| 129 }; | |
|
zundel
2010/03/26 13:49:15
One thing I love about the v8 profiling data is th
| |
| 130 | |
| 131 | |
| 132 /** | |
| 133 * Interface for controlling CPU profiling in V8. | |
| 134 */ | |
| 135 class V8EXPORT CpuProfiler { | |
| 136 public: | |
| 137 /** | |
| 138 * Returns the number of profiles collected (doesn't include | |
| 139 * profiles that are being collected at the moment of call.) | |
| 140 */ | |
| 141 static int GetProfilesCount(); | |
| 142 | |
| 143 /** Returns a profile by index. */ | |
| 144 static Handle<CpuProfile> GetProfile(int index); | |
| 145 | |
| 146 /** Returns a profile by uid. */ | |
| 147 static Handle<CpuProfile> GetProfile(unsigned uid); | |
| 148 | |
| 149 /** | |
| 150 * Starts collecting CPU profile. It is possible to have several | |
| 151 * collected profiles at once. Attempts to start collecting several | |
| 152 * profiles with the same title are silently ignored. */ | |
|
Mads Ager (chromium)
2010/03/23 08:38:26
Move '*/' to next line.
zundel
2010/03/26 12:53:33
Does this comment mean that you can start differen
zundel
2010/03/26 13:49:15
Should this function return a uid for use in GetPr
| |
| 153 static void StartProfiling(Handle<String> title = Handle<String>()); | |
|
zundel
2010/03/26 13:49:15
for starting/stopping profiles automatically, I do
| |
| 154 | |
| 155 /** | |
| 156 * Stops collecting CPU profile with a given title. If no title is | |
| 157 * given, finishes the last profile started. | |
| 158 */ | |
| 159 static void StopProfiling(Handle<String> title = Handle<String>()); | |
| 160 }; | |
| 161 | |
| 162 | |
| 163 } // namespace v8 | |
| 164 | |
| 165 | |
| 166 #undef V8EXPORT | |
| 167 | |
| 168 | |
| 169 #endif // V8_V8_PROFILER_H_ | |
| OLD | NEW |