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