| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project 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 #ifndef V8_V8_PLATFORM_H_ | 5 #ifndef V8_V8_PLATFORM_H_ |
| 6 #define V8_V8_PLATFORM_H_ | 6 #define V8_V8_PLATFORM_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <memory> | |
| 11 #include <string> | |
| 12 | 10 |
| 13 namespace v8 { | 11 namespace v8 { |
| 14 | 12 |
| 15 class Isolate; | 13 class Isolate; |
| 16 | 14 |
| 17 /** | 15 /** |
| 18 * A Task represents a unit of work. | 16 * A Task represents a unit of work. |
| 19 */ | 17 */ |
| 20 class Task { | 18 class Task { |
| 21 public: | 19 public: |
| 22 virtual ~Task() = default; | 20 virtual ~Task() {} |
| 23 | 21 |
| 24 virtual void Run() = 0; | 22 virtual void Run() = 0; |
| 25 }; | 23 }; |
| 26 | 24 |
| 25 |
| 27 /** | 26 /** |
| 28 * An IdleTask represents a unit of work to be performed in idle time. | 27 * An IdleTask represents a unit of work to be performed in idle time. |
| 29 * The Run method is invoked with an argument that specifies the deadline in | 28 * The Run method is invoked with an argument that specifies the deadline in |
| 30 * seconds returned by MonotonicallyIncreasingTime(). | 29 * seconds returned by MonotonicallyIncreasingTime(). |
| 31 * The idle task is expected to complete by this deadline. | 30 * The idle task is expected to complete by this deadline. |
| 32 */ | 31 */ |
| 33 class IdleTask { | 32 class IdleTask { |
| 34 public: | 33 public: |
| 35 virtual ~IdleTask() = default; | 34 virtual ~IdleTask() {} |
| 36 virtual void Run(double deadline_in_seconds) = 0; | 35 virtual void Run(double deadline_in_seconds) = 0; |
| 37 }; | 36 }; |
| 38 | 37 |
| 39 /** | |
| 40 * The interface represents complex arguments to trace events. | |
| 41 */ | |
| 42 class ConvertableToTraceFormat { | |
| 43 public: | |
| 44 virtual ~ConvertableToTraceFormat() = default; | |
| 45 | |
| 46 /** | |
| 47 * Append the class info to the provided |out| string. The appended | |
| 48 * data must be a valid JSON object. Strings must be properly quoted, and | |
| 49 * escaped. There is no processing applied to the content after it is | |
| 50 * appended. | |
| 51 */ | |
| 52 virtual void AppendAsTraceFormat(std::string* out) const = 0; | |
| 53 }; | |
| 54 | 38 |
| 55 /** | 39 /** |
| 56 * V8 Platform abstraction layer. | 40 * V8 Platform abstraction layer. |
| 57 * | 41 * |
| 58 * The embedder has to provide an implementation of this interface before | 42 * The embedder has to provide an implementation of this interface before |
| 59 * initializing the rest of V8. | 43 * initializing the rest of V8. |
| 60 */ | 44 */ |
| 61 class Platform { | 45 class Platform { |
| 62 public: | 46 public: |
| 63 /** | 47 /** |
| 64 * This enum is used to indicate whether a task is potentially long running, | 48 * This enum is used to indicate whether a task is potentially long running, |
| 65 * or causes a long wait. The embedder might want to use this hint to decide | 49 * or causes a long wait. The embedder might want to use this hint to decide |
| 66 * whether to execute the task on a dedicated thread. | 50 * whether to execute the task on a dedicated thread. |
| 67 */ | 51 */ |
| 68 enum ExpectedRuntime { | 52 enum ExpectedRuntime { |
| 69 kShortRunningTask, | 53 kShortRunningTask, |
| 70 kLongRunningTask | 54 kLongRunningTask |
| 71 }; | 55 }; |
| 72 | 56 |
| 73 virtual ~Platform() = default; | 57 virtual ~Platform() {} |
| 74 | 58 |
| 75 /** | 59 /** |
| 76 * Gets the number of threads that are used to execute background tasks. Is | 60 * Gets the number of threads that are used to execute background tasks. Is |
| 77 * used to estimate the number of tasks a work package should be split into. | 61 * used to estimate the number of tasks a work package should be split into. |
| 78 * A return value of 0 means that there are no background threads available. | 62 * A return value of 0 means that there are no background threads available. |
| 79 * Note that a value of 0 won't prohibit V8 from posting tasks using | 63 * Note that a value of 0 won't prohibit V8 from posting tasks using |
| 80 * |CallOnBackgroundThread|. | 64 * |CallOnBackgroundThread|. |
| 81 */ | 65 */ |
| 82 virtual size_t NumberOfAvailableBackgroundThreads() { return 0; } | 66 virtual size_t NumberOfAvailableBackgroundThreads() { return 0; } |
| 83 | 67 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 * tracing and the category of the particular trace are enabled. It is not | 148 * tracing and the category of the particular trace are enabled. It is not |
| 165 * advisable to call this function on its own; it is really only meant to be | 149 * advisable to call this function on its own; it is really only meant to be |
| 166 * used by the trace macros. The returned handle can be used by | 150 * used by the trace macros. The returned handle can be used by |
| 167 * UpdateTraceEventDuration to update the duration of COMPLETE events. | 151 * UpdateTraceEventDuration to update the duration of COMPLETE events. |
| 168 */ | 152 */ |
| 169 virtual uint64_t AddTraceEvent( | 153 virtual uint64_t AddTraceEvent( |
| 170 char phase, const uint8_t* category_enabled_flag, const char* name, | 154 char phase, const uint8_t* category_enabled_flag, const char* name, |
| 171 const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args, | 155 const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args, |
| 172 const char** arg_names, const uint8_t* arg_types, | 156 const char** arg_names, const uint8_t* arg_types, |
| 173 const uint64_t* arg_values, unsigned int flags) { | 157 const uint64_t* arg_values, unsigned int flags) { |
| 174 return AddTraceEvent(phase, category_enabled_flag, name, scope, id, bind_id, | |
| 175 num_args, arg_names, arg_types, arg_values, nullptr, | |
| 176 flags); | |
| 177 } | |
| 178 | |
| 179 /** | |
| 180 * Adds a trace event to the platform tracing system. This function call is | |
| 181 * usually the result of a TRACE_* macro from trace_event_common.h when | |
| 182 * tracing and the category of the particular trace are enabled. It is not | |
| 183 * advisable to call this function on its own; it is really only meant to be | |
| 184 * used by the trace macros. The returned handle can be used by | |
| 185 * UpdateTraceEventDuration to update the duration of COMPLETE events. | |
| 186 */ | |
| 187 virtual uint64_t AddTraceEvent( | |
| 188 char phase, const uint8_t* category_enabled_flag, const char* name, | |
| 189 const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args, | |
| 190 const char** arg_names, const uint8_t* arg_types, | |
| 191 const uint64_t* arg_values, | |
| 192 std::unique_ptr<ConvertableToTraceFormat>* arg_convertables, | |
| 193 unsigned int flags) { | |
| 194 return 0; | 158 return 0; |
| 195 } | 159 } |
| 196 | 160 |
| 197 /** | 161 /** |
| 198 * Sets the duration field of a COMPLETE trace event. It must be called with | 162 * Sets the duration field of a COMPLETE trace event. It must be called with |
| 199 * the handle returned from AddTraceEvent(). | 163 * the handle returned from AddTraceEvent(). |
| 200 **/ | 164 **/ |
| 201 virtual void UpdateTraceEventDuration(const uint8_t* category_enabled_flag, | 165 virtual void UpdateTraceEventDuration(const uint8_t* category_enabled_flag, |
| 202 const char* name, uint64_t handle) {} | 166 const char* name, uint64_t handle) {} |
| 203 | 167 |
| 204 class TraceStateObserver { | 168 class TraceStateObserver { |
| 205 public: | 169 public: |
| 206 virtual ~TraceStateObserver() = default; | 170 virtual ~TraceStateObserver() = default; |
| 207 virtual void OnTraceEnabled() = 0; | 171 virtual void OnTraceEnabled() = 0; |
| 208 virtual void OnTraceDisabled() = 0; | 172 virtual void OnTraceDisabled() = 0; |
| 209 }; | 173 }; |
| 210 | 174 |
| 211 /** Adds tracing state change observer. */ | 175 /** Adds tracing state change observer. */ |
| 212 virtual void AddTraceStateObserver(TraceStateObserver*) {} | 176 virtual void AddTraceStateObserver(TraceStateObserver*) {} |
| 213 | 177 |
| 214 /** Removes tracing state change observer. */ | 178 /** Removes tracing state change observer. */ |
| 215 virtual void RemoveTraceStateObserver(TraceStateObserver*) {} | 179 virtual void RemoveTraceStateObserver(TraceStateObserver*) {} |
| 216 }; | 180 }; |
| 217 | 181 |
| 218 } // namespace v8 | 182 } // namespace v8 |
| 219 | 183 |
| 220 #endif // V8_V8_PLATFORM_H_ | 184 #endif // V8_V8_PLATFORM_H_ |
| OLD | NEW |