#include "base/test/trace_event_analyzer.h"
#include <math.h>
#include <algorithm>
#include <optional>
#include <set>
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted_memory.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/strings/pattern.h"
#include "base/trace_event/trace_buffer.h"
#include "base/trace_event/trace_config.h"
#include "base/trace_event/trace_log.h"
#include "base/values.h"
namespace {
void OnTraceDataCollected(base::OnceClosure quit_closure,
base::trace_event::TraceResultBuffer* buffer,
const scoped_refptr<base::RefCountedString>& json,
bool has_more_events) { … }
}
namespace trace_analyzer {
TraceEvent::TraceEvent() : … { … }
TraceEvent::TraceEvent(TraceEvent&& other) = default;
TraceEvent::~TraceEvent() = default;
TraceEvent& TraceEvent::operator=(TraceEvent&& rhs) = default;
bool TraceEvent::SetFromJSON(const base::Value* event_value) { … }
double TraceEvent::GetAbsTimeToOtherEvent() const { … }
bool TraceEvent::GetArgAsString(const std::string& arg_name,
std::string* arg) const { … }
bool TraceEvent::GetArgAsNumber(const std::string& arg_name,
double* arg) const { … }
bool TraceEvent::GetArgAsDict(const std::string& arg_name,
base::Value::Dict* arg) const { … }
bool TraceEvent::HasStringArg(const std::string& arg_name) const { … }
bool TraceEvent::HasNumberArg(const std::string& arg_name) const { … }
bool TraceEvent::HasDictArg(const std::string& arg_name) const { … }
std::string TraceEvent::GetKnownArgAsString(const std::string& arg_name) const { … }
double TraceEvent::GetKnownArgAsDouble(const std::string& arg_name) const { … }
int TraceEvent::GetKnownArgAsInt(const std::string& arg_name) const { … }
bool TraceEvent::GetKnownArgAsBool(const std::string& arg_name) const { … }
base::Value::Dict TraceEvent::GetKnownArgAsDict(
const std::string& arg_name) const { … }
QueryNode::QueryNode(const Query& query) : … { … }
QueryNode::~QueryNode() = default;
Query::Query(TraceEventMember member)
: … { … }
Query::Query(TraceEventMember member, const std::string& arg_name)
: … { … }
Query::Query(const Query& query) = default;
Query::~Query() = default;
Query Query::String(const std::string& str) { … }
Query Query::Double(double num) { … }
Query Query::Int(int32_t num) { … }
Query Query::Uint(uint32_t num) { … }
Query Query::Bool(bool boolean) { … }
Query Query::Phase(char phase) { … }
Query Query::Pattern(const std::string& pattern) { … }
bool Query::Evaluate(const TraceEvent& event) const { … }
bool Query::CompareAsDouble(const TraceEvent& event, bool* result) const { … }
bool Query::CompareAsString(const TraceEvent& event, bool* result) const { … }
bool Query::EvaluateArithmeticOperator(const TraceEvent& event,
double* num) const { … }
bool Query::GetAsDouble(const TraceEvent& event, double* num) const { … }
bool Query::GetAsString(const TraceEvent& event, std::string* str) const { … }
const TraceEvent* Query::SelectTargetEvent(const TraceEvent* event,
TraceEventMember member) { … }
bool Query::GetMemberValueAsDouble(const TraceEvent& event,
double* num) const { … }
bool Query::GetMemberValueAsString(const TraceEvent& event,
std::string* str) const { … }
Query::Query(const std::string& str)
: … { … }
Query::Query(double num)
: … { … }
const Query& Query::left() const { … }
const Query& Query::right() const { … }
Query Query::operator==(const Query& rhs) const { … }
Query Query::operator!=(const Query& rhs) const { … }
Query Query::operator<(const Query& rhs) const { … }
Query Query::operator<=(const Query& rhs) const { … }
Query Query::operator>(const Query& rhs) const { … }
Query Query::operator>=(const Query& rhs) const { … }
Query Query::operator&&(const Query& rhs) const { … }
Query Query::operator||(const Query& rhs) const { … }
Query Query::operator!() const { … }
Query Query::operator+(const Query& rhs) const { … }
Query Query::operator-(const Query& rhs) const { … }
Query Query::operator*(const Query& rhs) const { … }
Query Query::operator/(const Query& rhs) const { … }
Query Query::operator%(const Query& rhs) const { … }
Query Query::operator-() const { … }
Query::Query(const Query& left, const Query& right, Operator binary_op)
: … { … }
Query::Query(const Query& left, Operator unary_op)
: … { … }
namespace {
size_t FindMatchingEvents(const std::vector<TraceEvent>& events,
const Query& query,
TraceEventVector* output,
bool ignore_metadata_events) { … }
bool ParseEventsFromJson(const std::string& json,
std::vector<TraceEvent>* output) { … }
}
TraceAnalyzer::TraceAnalyzer()
: … { … }
TraceAnalyzer::~TraceAnalyzer() = default;
std::unique_ptr<TraceAnalyzer> TraceAnalyzer::Create(
const std::string& json_events) { … }
bool TraceAnalyzer::SetEvents(const std::string& json_events) { … }
void TraceAnalyzer::AssociateBeginEndEvents() { … }
void TraceAnalyzer::AssociateAsyncBeginEndEvents(bool match_pid) { … }
void TraceAnalyzer::AssociateEvents(const Query& first,
const Query& second,
const Query& match) { … }
void TraceAnalyzer::MergeAssociatedEventArgs() { … }
size_t TraceAnalyzer::FindEvents(const Query& query, TraceEventVector* output) { … }
const TraceEvent* TraceAnalyzer::FindFirstOf(const Query& query) { … }
const TraceEvent* TraceAnalyzer::FindLastOf(const Query& query) { … }
const std::string& TraceAnalyzer::GetThreadName(
const TraceEvent::ProcessThreadID& thread) { … }
void TraceAnalyzer::ParseMetadata() { … }
void Start(const std::string& category_filter_string) { … }
std::unique_ptr<TraceAnalyzer> Stop() { … }
bool GetRateStats(const TraceEventVector& events,
RateStats* stats,
const RateStatsOptions* options) { … }
bool FindFirstOf(const TraceEventVector& events,
const Query& query,
size_t position,
size_t* return_index) { … }
bool FindLastOf(const TraceEventVector& events,
const Query& query,
size_t position,
size_t* return_index) { … }
bool FindClosest(const TraceEventVector& events,
const Query& query,
size_t position,
size_t* return_closest,
size_t* return_second_closest) { … }
size_t CountMatches(const TraceEventVector& events,
const Query& query,
size_t begin_position,
size_t end_position) { … }
}