Update Files
This commit is contained in:
9
v8/include/libplatform/DEPS
Normal file
9
v8/include/libplatform/DEPS
Normal file
@ -0,0 +1,9 @@
|
||||
include_rules = [
|
||||
"+libplatform/libplatform-export.h",
|
||||
]
|
||||
|
||||
specific_include_rules = {
|
||||
"libplatform\.h": [
|
||||
"+libplatform/v8-tracing.h",
|
||||
],
|
||||
}
|
29
v8/include/libplatform/libplatform-export.h
Executable file
29
v8/include/libplatform/libplatform-export.h
Executable file
@ -0,0 +1,29 @@
|
||||
// Copyright 2016 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef V8_LIBPLATFORM_LIBPLATFORM_EXPORT_H_
|
||||
#define V8_LIBPLATFORM_LIBPLATFORM_EXPORT_H_
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
#ifdef BUILDING_V8_PLATFORM_SHARED
|
||||
#define V8_PLATFORM_EXPORT __declspec(dllexport)
|
||||
#elif USING_V8_PLATFORM_SHARED
|
||||
#define V8_PLATFORM_EXPORT __declspec(dllimport)
|
||||
#else
|
||||
#define V8_PLATFORM_EXPORT
|
||||
#endif // BUILDING_V8_PLATFORM_SHARED
|
||||
|
||||
#else // defined(_WIN32)
|
||||
|
||||
// Setup for Linux shared library export.
|
||||
#ifdef BUILDING_V8_PLATFORM_SHARED
|
||||
#define V8_PLATFORM_EXPORT __attribute__((visibility("default")))
|
||||
#else
|
||||
#define V8_PLATFORM_EXPORT
|
||||
#endif
|
||||
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
#endif // V8_LIBPLATFORM_LIBPLATFORM_EXPORT_H_
|
106
v8/include/libplatform/libplatform.h
Executable file
106
v8/include/libplatform/libplatform.h
Executable file
@ -0,0 +1,106 @@
|
||||
// Copyright 2014 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef V8_LIBPLATFORM_LIBPLATFORM_H_
|
||||
#define V8_LIBPLATFORM_LIBPLATFORM_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "libplatform/libplatform-export.h"
|
||||
#include "libplatform/v8-tracing.h"
|
||||
#include "v8-platform.h" // NOLINT(build/include_directory)
|
||||
#include "v8config.h" // NOLINT(build/include_directory)
|
||||
|
||||
namespace v8 {
|
||||
namespace platform {
|
||||
|
||||
enum class IdleTaskSupport { kDisabled, kEnabled };
|
||||
enum class InProcessStackDumping { kDisabled, kEnabled };
|
||||
|
||||
enum class MessageLoopBehavior : bool {
|
||||
kDoNotWait = false,
|
||||
kWaitForWork = true
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a new instance of the default v8::Platform implementation.
|
||||
*
|
||||
* The caller will take ownership of the returned pointer. |thread_pool_size|
|
||||
* is the number of worker threads to allocate for background jobs. If a value
|
||||
* of zero is passed, a suitable default based on the current number of
|
||||
* processors online will be chosen.
|
||||
* If |idle_task_support| is enabled then the platform will accept idle
|
||||
* tasks (IdleTasksEnabled will return true) and will rely on the embedder
|
||||
* calling v8::platform::RunIdleTasks to process the idle tasks.
|
||||
* If |tracing_controller| is nullptr, the default platform will create a
|
||||
* v8::platform::TracingController instance and use it.
|
||||
*/
|
||||
V8_PLATFORM_EXPORT std::unique_ptr<v8::Platform> NewDefaultPlatform(
|
||||
int thread_pool_size = 0,
|
||||
IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
|
||||
InProcessStackDumping in_process_stack_dumping =
|
||||
InProcessStackDumping::kDisabled,
|
||||
std::unique_ptr<v8::TracingController> tracing_controller = {});
|
||||
|
||||
/**
|
||||
* The same as NewDefaultPlatform but disables the worker thread pool.
|
||||
* It must be used with the --single-threaded V8 flag.
|
||||
*/
|
||||
V8_PLATFORM_EXPORT std::unique_ptr<v8::Platform>
|
||||
NewSingleThreadedDefaultPlatform(
|
||||
IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
|
||||
InProcessStackDumping in_process_stack_dumping =
|
||||
InProcessStackDumping::kDisabled,
|
||||
std::unique_ptr<v8::TracingController> tracing_controller = {});
|
||||
|
||||
/**
|
||||
* Returns a new instance of the default v8::JobHandle implementation.
|
||||
*
|
||||
* The job will be executed by spawning up to |num_worker_threads| many worker
|
||||
* threads on the provided |platform| with the given |priority|.
|
||||
*/
|
||||
V8_PLATFORM_EXPORT std::unique_ptr<v8::JobHandle> NewDefaultJobHandle(
|
||||
v8::Platform* platform, v8::TaskPriority priority,
|
||||
std::unique_ptr<v8::JobTask> job_task, size_t num_worker_threads);
|
||||
|
||||
/**
|
||||
* Pumps the message loop for the given isolate.
|
||||
*
|
||||
* The caller has to make sure that this is called from the right thread.
|
||||
* Returns true if a task was executed, and false otherwise. If the call to
|
||||
* PumpMessageLoop is nested within another call to PumpMessageLoop, only
|
||||
* nestable tasks may run. Otherwise, any task may run. Unless requested through
|
||||
* the |behavior| parameter, this call does not block if no task is pending. The
|
||||
* |platform| has to be created using |NewDefaultPlatform|.
|
||||
*/
|
||||
V8_PLATFORM_EXPORT bool PumpMessageLoop(
|
||||
v8::Platform* platform, v8::Isolate* isolate,
|
||||
MessageLoopBehavior behavior = MessageLoopBehavior::kDoNotWait);
|
||||
|
||||
/**
|
||||
* Runs pending idle tasks for at most |idle_time_in_seconds| seconds.
|
||||
*
|
||||
* The caller has to make sure that this is called from the right thread.
|
||||
* This call does not block if no task is pending. The |platform| has to be
|
||||
* created using |NewDefaultPlatform|.
|
||||
*/
|
||||
V8_PLATFORM_EXPORT void RunIdleTasks(v8::Platform* platform,
|
||||
v8::Isolate* isolate,
|
||||
double idle_time_in_seconds);
|
||||
|
||||
/**
|
||||
* Notifies the given platform about the Isolate getting deleted soon. Has to be
|
||||
* called for all Isolates which are deleted - unless we're shutting down the
|
||||
* platform.
|
||||
*
|
||||
* The |platform| has to be created using |NewDefaultPlatform|.
|
||||
*
|
||||
*/
|
||||
V8_PLATFORM_EXPORT void NotifyIsolateShutdown(v8::Platform* platform,
|
||||
Isolate* isolate);
|
||||
|
||||
} // namespace platform
|
||||
} // namespace v8
|
||||
|
||||
#endif // V8_LIBPLATFORM_LIBPLATFORM_H_
|
333
v8/include/libplatform/v8-tracing.h
Executable file
333
v8/include/libplatform/v8-tracing.h
Executable file
@ -0,0 +1,333 @@
|
||||
// Copyright 2016 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef V8_LIBPLATFORM_V8_TRACING_H_
|
||||
#define V8_LIBPLATFORM_V8_TRACING_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#include "libplatform/libplatform-export.h"
|
||||
#include "v8-platform.h" // NOLINT(build/include_directory)
|
||||
|
||||
namespace perfetto {
|
||||
namespace trace_processor {
|
||||
class TraceProcessorStorage;
|
||||
}
|
||||
class TracingSession;
|
||||
}
|
||||
|
||||
namespace v8 {
|
||||
|
||||
namespace base {
|
||||
class Mutex;
|
||||
} // namespace base
|
||||
|
||||
namespace platform {
|
||||
namespace tracing {
|
||||
|
||||
class TraceEventListener;
|
||||
|
||||
const int kTraceMaxNumArgs = 2;
|
||||
|
||||
class V8_PLATFORM_EXPORT TraceObject {
|
||||
public:
|
||||
union ArgValue {
|
||||
uint64_t as_uint;
|
||||
int64_t as_int;
|
||||
double as_double;
|
||||
const void* as_pointer;
|
||||
const char* as_string;
|
||||
};
|
||||
|
||||
TraceObject() = default;
|
||||
~TraceObject();
|
||||
void Initialize(
|
||||
char phase, const uint8_t* category_enabled_flag, const char* name,
|
||||
const char* scope, uint64_t id, uint64_t bind_id, int num_args,
|
||||
const char** arg_names, const uint8_t* arg_types,
|
||||
const uint64_t* arg_values,
|
||||
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
|
||||
unsigned int flags, int64_t timestamp, int64_t cpu_timestamp);
|
||||
void UpdateDuration(int64_t timestamp, int64_t cpu_timestamp);
|
||||
void InitializeForTesting(
|
||||
char phase, const uint8_t* category_enabled_flag, const char* name,
|
||||
const char* scope, uint64_t id, uint64_t bind_id, int num_args,
|
||||
const char** arg_names, const uint8_t* arg_types,
|
||||
const uint64_t* arg_values,
|
||||
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
|
||||
unsigned int flags, int pid, int tid, int64_t ts, int64_t tts,
|
||||
uint64_t duration, uint64_t cpu_duration);
|
||||
|
||||
int pid() const { return pid_; }
|
||||
int tid() const { return tid_; }
|
||||
char phase() const { return phase_; }
|
||||
const uint8_t* category_enabled_flag() const {
|
||||
return category_enabled_flag_;
|
||||
}
|
||||
const char* name() const { return name_; }
|
||||
const char* scope() const { return scope_; }
|
||||
uint64_t id() const { return id_; }
|
||||
uint64_t bind_id() const { return bind_id_; }
|
||||
int num_args() const { return num_args_; }
|
||||
const char** arg_names() { return arg_names_; }
|
||||
uint8_t* arg_types() { return arg_types_; }
|
||||
ArgValue* arg_values() { return arg_values_; }
|
||||
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables() {
|
||||
return arg_convertables_;
|
||||
}
|
||||
unsigned int flags() const { return flags_; }
|
||||
int64_t ts() { return ts_; }
|
||||
int64_t tts() { return tts_; }
|
||||
uint64_t duration() { return duration_; }
|
||||
uint64_t cpu_duration() { return cpu_duration_; }
|
||||
|
||||
private:
|
||||
int pid_;
|
||||
int tid_;
|
||||
char phase_;
|
||||
const char* name_;
|
||||
const char* scope_;
|
||||
const uint8_t* category_enabled_flag_;
|
||||
uint64_t id_;
|
||||
uint64_t bind_id_;
|
||||
int num_args_ = 0;
|
||||
const char* arg_names_[kTraceMaxNumArgs];
|
||||
uint8_t arg_types_[kTraceMaxNumArgs];
|
||||
ArgValue arg_values_[kTraceMaxNumArgs];
|
||||
std::unique_ptr<v8::ConvertableToTraceFormat>
|
||||
arg_convertables_[kTraceMaxNumArgs];
|
||||
char* parameter_copy_storage_ = nullptr;
|
||||
unsigned int flags_;
|
||||
int64_t ts_;
|
||||
int64_t tts_;
|
||||
uint64_t duration_;
|
||||
uint64_t cpu_duration_;
|
||||
|
||||
// Disallow copy and assign
|
||||
TraceObject(const TraceObject&) = delete;
|
||||
void operator=(const TraceObject&) = delete;
|
||||
};
|
||||
|
||||
class V8_PLATFORM_EXPORT TraceWriter {
|
||||
public:
|
||||
TraceWriter() = default;
|
||||
virtual ~TraceWriter() = default;
|
||||
virtual void AppendTraceEvent(TraceObject* trace_event) = 0;
|
||||
virtual void Flush() = 0;
|
||||
|
||||
static TraceWriter* CreateJSONTraceWriter(std::ostream& stream);
|
||||
static TraceWriter* CreateJSONTraceWriter(std::ostream& stream,
|
||||
const std::string& tag);
|
||||
|
||||
static TraceWriter* CreateSystemInstrumentationTraceWriter();
|
||||
|
||||
private:
|
||||
// Disallow copy and assign
|
||||
TraceWriter(const TraceWriter&) = delete;
|
||||
void operator=(const TraceWriter&) = delete;
|
||||
};
|
||||
|
||||
class V8_PLATFORM_EXPORT TraceBufferChunk {
|
||||
public:
|
||||
explicit TraceBufferChunk(uint32_t seq);
|
||||
|
||||
void Reset(uint32_t new_seq);
|
||||
bool IsFull() const { return next_free_ == kChunkSize; }
|
||||
TraceObject* AddTraceEvent(size_t* event_index);
|
||||
TraceObject* GetEventAt(size_t index) { return &chunk_[index]; }
|
||||
|
||||
uint32_t seq() const { return seq_; }
|
||||
size_t size() const { return next_free_; }
|
||||
|
||||
static const size_t kChunkSize = 64;
|
||||
|
||||
private:
|
||||
size_t next_free_ = 0;
|
||||
TraceObject chunk_[kChunkSize];
|
||||
uint32_t seq_;
|
||||
|
||||
// Disallow copy and assign
|
||||
TraceBufferChunk(const TraceBufferChunk&) = delete;
|
||||
void operator=(const TraceBufferChunk&) = delete;
|
||||
};
|
||||
|
||||
class V8_PLATFORM_EXPORT TraceBuffer {
|
||||
public:
|
||||
TraceBuffer() = default;
|
||||
virtual ~TraceBuffer() = default;
|
||||
|
||||
virtual TraceObject* AddTraceEvent(uint64_t* handle) = 0;
|
||||
virtual TraceObject* GetEventByHandle(uint64_t handle) = 0;
|
||||
virtual bool Flush() = 0;
|
||||
|
||||
static const size_t kRingBufferChunks = 1024;
|
||||
|
||||
static TraceBuffer* CreateTraceBufferRingBuffer(size_t max_chunks,
|
||||
TraceWriter* trace_writer);
|
||||
|
||||
private:
|
||||
// Disallow copy and assign
|
||||
TraceBuffer(const TraceBuffer&) = delete;
|
||||
void operator=(const TraceBuffer&) = delete;
|
||||
};
|
||||
|
||||
// Options determines how the trace buffer stores data.
|
||||
enum TraceRecordMode {
|
||||
// Record until the trace buffer is full.
|
||||
RECORD_UNTIL_FULL,
|
||||
|
||||
// Record until the user ends the trace. The trace buffer is a fixed size
|
||||
// and we use it as a ring buffer during recording.
|
||||
RECORD_CONTINUOUSLY,
|
||||
|
||||
// Record until the trace buffer is full, but with a huge buffer size.
|
||||
RECORD_AS_MUCH_AS_POSSIBLE,
|
||||
|
||||
// Echo to console. Events are discarded.
|
||||
ECHO_TO_CONSOLE,
|
||||
};
|
||||
|
||||
class V8_PLATFORM_EXPORT TraceConfig {
|
||||
public:
|
||||
typedef std::vector<std::string> StringList;
|
||||
|
||||
static TraceConfig* CreateDefaultTraceConfig();
|
||||
|
||||
TraceConfig() : enable_systrace_(false), enable_argument_filter_(false) {}
|
||||
TraceRecordMode GetTraceRecordMode() const { return record_mode_; }
|
||||
const StringList& GetEnabledCategories() const {
|
||||
return included_categories_;
|
||||
}
|
||||
bool IsSystraceEnabled() const { return enable_systrace_; }
|
||||
bool IsArgumentFilterEnabled() const { return enable_argument_filter_; }
|
||||
|
||||
void SetTraceRecordMode(TraceRecordMode mode) { record_mode_ = mode; }
|
||||
void EnableSystrace() { enable_systrace_ = true; }
|
||||
void EnableArgumentFilter() { enable_argument_filter_ = true; }
|
||||
|
||||
void AddIncludedCategory(const char* included_category);
|
||||
|
||||
bool IsCategoryGroupEnabled(const char* category_group) const;
|
||||
|
||||
private:
|
||||
TraceRecordMode record_mode_;
|
||||
bool enable_systrace_ : 1;
|
||||
bool enable_argument_filter_ : 1;
|
||||
StringList included_categories_;
|
||||
|
||||
// Disallow copy and assign
|
||||
TraceConfig(const TraceConfig&) = delete;
|
||||
void operator=(const TraceConfig&) = delete;
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define V8_PLATFORM_NON_EXPORTED_BASE(code) \
|
||||
__pragma(warning(suppress : 4275)) code
|
||||
#else
|
||||
#define V8_PLATFORM_NON_EXPORTED_BASE(code) code
|
||||
#endif // defined(_MSC_VER)
|
||||
|
||||
class V8_PLATFORM_EXPORT TracingController
|
||||
: public V8_PLATFORM_NON_EXPORTED_BASE(v8::TracingController) {
|
||||
public:
|
||||
TracingController();
|
||||
~TracingController() override;
|
||||
|
||||
#if defined(V8_USE_PERFETTO)
|
||||
// Must be called before StartTracing() if V8_USE_PERFETTO is true. Provides
|
||||
// the output stream for the JSON trace data.
|
||||
void InitializeForPerfetto(std::ostream* output_stream);
|
||||
// Provide an optional listener for testing that will receive trace events.
|
||||
// Must be called before StartTracing().
|
||||
void SetTraceEventListenerForTesting(TraceEventListener* listener);
|
||||
#else // defined(V8_USE_PERFETTO)
|
||||
// The pointer returned from GetCategoryGroupEnabled() points to a value with
|
||||
// zero or more of the following bits. Used in this class only. The
|
||||
// TRACE_EVENT macros should only use the value as a bool. These values must
|
||||
// be in sync with macro values in TraceEvent.h in Blink.
|
||||
enum CategoryGroupEnabledFlags {
|
||||
// Category group enabled for the recording mode.
|
||||
ENABLED_FOR_RECORDING = 1 << 0,
|
||||
// Category group enabled by SetEventCallbackEnabled().
|
||||
ENABLED_FOR_EVENT_CALLBACK = 1 << 2,
|
||||
// Category group enabled to export events to ETW.
|
||||
ENABLED_FOR_ETW_EXPORT = 1 << 3
|
||||
};
|
||||
|
||||
// Takes ownership of |trace_buffer|.
|
||||
void Initialize(TraceBuffer* trace_buffer);
|
||||
|
||||
// v8::TracingController implementation.
|
||||
const uint8_t* GetCategoryGroupEnabled(const char* category_group) override;
|
||||
uint64_t AddTraceEvent(
|
||||
char phase, const uint8_t* category_enabled_flag, const char* name,
|
||||
const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
|
||||
const char** arg_names, const uint8_t* arg_types,
|
||||
const uint64_t* arg_values,
|
||||
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
|
||||
unsigned int flags) override;
|
||||
uint64_t AddTraceEventWithTimestamp(
|
||||
char phase, const uint8_t* category_enabled_flag, const char* name,
|
||||
const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
|
||||
const char** arg_names, const uint8_t* arg_types,
|
||||
const uint64_t* arg_values,
|
||||
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
|
||||
unsigned int flags, int64_t timestamp) override;
|
||||
void UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
|
||||
const char* name, uint64_t handle) override;
|
||||
|
||||
static const char* GetCategoryGroupName(const uint8_t* category_enabled_flag);
|
||||
#endif // !defined(V8_USE_PERFETTO)
|
||||
|
||||
void AddTraceStateObserver(
|
||||
v8::TracingController::TraceStateObserver* observer) override;
|
||||
void RemoveTraceStateObserver(
|
||||
v8::TracingController::TraceStateObserver* observer) override;
|
||||
|
||||
void StartTracing(TraceConfig* trace_config);
|
||||
void StopTracing();
|
||||
|
||||
protected:
|
||||
#if !defined(V8_USE_PERFETTO)
|
||||
virtual int64_t CurrentTimestampMicroseconds();
|
||||
virtual int64_t CurrentCpuTimestampMicroseconds();
|
||||
#endif // !defined(V8_USE_PERFETTO)
|
||||
|
||||
private:
|
||||
#if !defined(V8_USE_PERFETTO)
|
||||
void UpdateCategoryGroupEnabledFlag(size_t category_index);
|
||||
void UpdateCategoryGroupEnabledFlags();
|
||||
#endif // !defined(V8_USE_PERFETTO)
|
||||
|
||||
std::unique_ptr<base::Mutex> mutex_;
|
||||
std::unique_ptr<TraceConfig> trace_config_;
|
||||
std::atomic_bool recording_{false};
|
||||
std::unordered_set<v8::TracingController::TraceStateObserver*> observers_;
|
||||
|
||||
#if defined(V8_USE_PERFETTO)
|
||||
std::ostream* output_stream_ = nullptr;
|
||||
std::unique_ptr<perfetto::trace_processor::TraceProcessorStorage>
|
||||
trace_processor_;
|
||||
TraceEventListener* listener_for_testing_ = nullptr;
|
||||
std::unique_ptr<perfetto::TracingSession> tracing_session_;
|
||||
#else // !defined(V8_USE_PERFETTO)
|
||||
std::unique_ptr<TraceBuffer> trace_buffer_;
|
||||
#endif // !defined(V8_USE_PERFETTO)
|
||||
|
||||
// Disallow copy and assign
|
||||
TracingController(const TracingController&) = delete;
|
||||
void operator=(const TracingController&) = delete;
|
||||
};
|
||||
|
||||
#undef V8_PLATFORM_NON_EXPORTED_BASE
|
||||
|
||||
} // namespace tracing
|
||||
} // namespace platform
|
||||
} // namespace v8
|
||||
|
||||
#endif // V8_LIBPLATFORM_V8_TRACING_H_
|
Reference in New Issue
Block a user