| Index: base/debug/trace_event.h
|
| diff --git a/base/debug/trace_event.h b/base/debug/trace_event.h
|
| index e7b3f90066ac8631099d0f39a8558ec517b7f810..cf78fd0833898592e5f15487971e866cf4f5457f 100644
|
| --- a/base/debug/trace_event.h
|
| +++ b/base/debug/trace_event.h
|
| @@ -97,6 +97,7 @@
|
|
|
| #include "build/build_config.h"
|
|
|
| +#include <map>
|
| #include <string>
|
| #include <vector>
|
|
|
| @@ -311,6 +312,7 @@
|
| namespace base {
|
|
|
| class RefCountedString;
|
| +class Value;
|
|
|
| namespace debug {
|
|
|
| @@ -403,6 +405,10 @@ class BASE_EXPORT TraceValue {
|
| return value;
|
| }
|
|
|
| + bool is_string() const {
|
| + return type_ == TRACE_TYPE_STRING || type_ == TRACE_TYPE_STATIC_STRING;
|
| + }
|
| +
|
| void AppendAsJSON(std::string* out) const;
|
|
|
| Type type() const {
|
| @@ -429,7 +435,7 @@ class BASE_EXPORT TraceValue {
|
| return value_.as_pointer;
|
| }
|
| const char* as_string() const {
|
| - DCHECK(type_ == TRACE_TYPE_STRING || type_ == TRACE_TYPE_STATIC_STRING);
|
| + DCHECK(is_string());
|
| return value_.as_string;
|
| }
|
| const char** as_assignable_string() {
|
| @@ -451,6 +457,64 @@ class BASE_EXPORT TraceValue {
|
| Value value_;
|
| };
|
|
|
| +// TestTraceEvent is a more convenient form of the TraceEvent class to make
|
| +// tracing-based tests easier to write.
|
| +struct TestTraceEvent {
|
| + // PidTid contains a Process ID and Thread ID.
|
| + struct PidTid {
|
| + PidTid() : pid(0), tid(0) {}
|
| + PidTid(int pid, int tid) : pid(pid), tid(tid) {}
|
| + bool operator< (PidTid rhs) const {
|
| + if (pid != rhs.pid)
|
| + return pid < rhs.pid;
|
| + return tid < rhs.tid;
|
| + }
|
| + int pid;
|
| + int tid;
|
| + };
|
| +
|
| + TestTraceEvent();
|
| + TestTraceEvent(const base::Value* event_value);
|
| + ~TestTraceEvent();
|
| +
|
| + // Convert JSON string to array of TestTraceEvent.
|
| + // |output| is appended with the parsed events.
|
| + static bool ParseEventsFromJson(const std::string& json,
|
| + std::vector<TestTraceEvent>* output);
|
| +
|
| + bool operator< (const TestTraceEvent& rhs) const {
|
| + return timestamp < rhs.timestamp;
|
| + }
|
| +
|
| + // Returns duration if it's available.
|
| + bool GetDuration(double* duration) const;
|
| +
|
| + // Return the argument value if it exists.
|
| + bool IsArg(const std::string& name) const;
|
| + // Return the argument value if it exists and it is a string.
|
| + bool GetArgAsString(const std::string& name, std::string* arg) const;
|
| + // Return the argument value if it exists and it is a number.
|
| + bool GetArgAsNumber(const std::string& name, double* arg) const;
|
| +
|
| + // Called by TraceAnalyzer to associate two events.
|
| + void SetAssociatedEvent(TestTraceEvent* event);
|
| +
|
| + // Process ID and Thread ID.
|
| + PidTid pid_tid;
|
| + // Time since epoch in microseconds.
|
| + // Stored as double to match its JSON representation.
|
| + double timestamp;
|
| + TraceEventPhase phase;
|
| + std::string category;
|
| + std::string name;
|
| + // All numbers and bool values from TraceEvent args are cast to double.
|
| + // bool becomes 1.0 (true) or 0.0 (false).
|
| + std::map<std::string, double> arg_numbers;
|
| + std::map<std::string, std::string> arg_strings;
|
| + // Set by TraceAnalyzer to point between matching BEGIN and END events.
|
| + const TestTraceEvent* associated_event;
|
| +};
|
| +
|
| // Output records are "Events" and can be obtained via the
|
| // OutputCallback whenever the tracing system decides to flush. This
|
| // can happen at any time, on any thread, or you can programatically
|
|
|