[tracing] Plumb event id between histogram samples, slices and triggers.
This CL adds a histogram scoper to connect flow id to observers, to links histogram samples to semantically related events in tracing. This is more robust and extensible than the previous solution based on hashing histogram names. Bug: 40257548 Change-Id: Ib1d5d5da42c84ff548a16b622f8932eb5dd206ba Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6233616 Reviewed-by: Gabriel Charette <gab@chromium.org> Reviewed-by: Dave Tapuska <dtapuska@chromium.org> Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org> Reviewed-by: Giovanni Ortuno Urquidi <ortuno@chromium.org> Cr-Commit-Position: refs/heads/main@{#1418857}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
af3c4fb362
commit
226632b457
base
content/browser
scheduler
responsiveness
tracing
services/tracing/public
cpp
background_tracing
mojom
third_party/blink
@ -8,6 +8,7 @@
|
||||
|
||||
#include "base/metrics/metrics_hashes.h"
|
||||
#include "base/metrics/statistics_recorder.h"
|
||||
#include "base/trace_event/histogram_scope.h"
|
||||
#include "base/trace_event/trace_event.h"
|
||||
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
|
||||
#include "services/tracing/public/cpp/perfetto/macros.h"
|
||||
@ -51,25 +52,28 @@ void BackgroundTracingAgentImpl::ClearUMACallback(
|
||||
|
||||
bool BackgroundTracingAgentImpl::DoEmitNamedTrigger(
|
||||
const std::string& trigger_name,
|
||||
std::optional<int32_t> value) {
|
||||
std::optional<int32_t> value,
|
||||
uint64_t flow_id) {
|
||||
TRACE_EVENT_INSTANT("latency", "NamedTrigger",
|
||||
base::trace_event::TriggerFlow(trigger_name, value));
|
||||
DoEmitNamedTriggerImpl(trigger_name, value);
|
||||
perfetto::Flow::Global(flow_id));
|
||||
DoEmitNamedTriggerImpl(trigger_name, value, flow_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
void BackgroundTracingAgentImpl::DoEmitNamedTriggerImpl(
|
||||
const std::string& trigger_name,
|
||||
std::optional<int32_t> value) {
|
||||
std::optional<int32_t> value,
|
||||
uint64_t flow_id) {
|
||||
if (!task_runner_->RunsTasksInCurrentSequence()) {
|
||||
task_runner_->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(&BackgroundTracingAgentImpl::DoEmitNamedTriggerImpl,
|
||||
weak_factory_.GetWeakPtr(), trigger_name, value));
|
||||
weak_factory_.GetWeakPtr(), trigger_name, value,
|
||||
flow_id));
|
||||
return;
|
||||
}
|
||||
client_->OnTriggerBackgroundTrace(
|
||||
tracing::mojom::BackgroundTracingRule::New(trigger_name), value);
|
||||
tracing::mojom::BackgroundTracingRule::New(trigger_name), value, flow_id);
|
||||
}
|
||||
|
||||
void BackgroundTracingAgentImpl::OnHistogramChanged(
|
||||
@ -83,18 +87,22 @@ void BackgroundTracingAgentImpl::OnHistogramChanged(
|
||||
actual_value > histogram_upper_value) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t flow_id = base::trace_event::HistogramScope::GetFlowId().value_or(
|
||||
base::trace_event::GetNextGlobalTraceId());
|
||||
|
||||
TRACE_EVENT("toplevel,latency", "HistogramSampleTrigger",
|
||||
[&](perfetto::EventContext ctx) {
|
||||
perfetto::protos::pbzero::ChromeHistogramSample* new_sample =
|
||||
ctx.event()->set_chrome_histogram_sample();
|
||||
new_sample->set_name_hash(name_hash);
|
||||
new_sample->set_sample(actual_value);
|
||||
base::trace_event::TriggerFlow(histogram_name,
|
||||
actual_value)(ctx);
|
||||
perfetto::Flow::Global(flow_id)(ctx);
|
||||
});
|
||||
|
||||
client_->OnTriggerBackgroundTrace(
|
||||
tracing::mojom::BackgroundTracingRule::New(rule_id), actual_value);
|
||||
tracing::mojom::BackgroundTracingRule::New(rule_id), actual_value,
|
||||
flow_id);
|
||||
}
|
||||
|
||||
} // namespace tracing
|
||||
|
@ -42,7 +42,8 @@ class COMPONENT_EXPORT(BACKGROUND_TRACING_CPP) BackgroundTracingAgentImpl
|
||||
|
||||
// base::trace_event::NamedTriggerManager
|
||||
bool DoEmitNamedTrigger(const std::string& trigger_name,
|
||||
std::optional<int32_t> value) override;
|
||||
std::optional<int32_t> value,
|
||||
uint64_t flow_id) override;
|
||||
|
||||
private:
|
||||
void OnHistogramChanged(const std::string& rule_id,
|
||||
@ -53,7 +54,8 @@ class COMPONENT_EXPORT(BACKGROUND_TRACING_CPP) BackgroundTracingAgentImpl
|
||||
base::Histogram::Sample32 actual_value);
|
||||
|
||||
void DoEmitNamedTriggerImpl(const std::string& trigger_name,
|
||||
std::optional<int32_t> value);
|
||||
std::optional<int32_t> value,
|
||||
uint64_t flow_id);
|
||||
|
||||
mojo::Remote<mojom::BackgroundTracingAgentClient> client_;
|
||||
base::Time histogram_last_changed_;
|
||||
|
@ -24,7 +24,8 @@ class BackgroundTracingAgentClientRecorder
|
||||
void OnInitialized() override { ++on_initialized_count_; }
|
||||
|
||||
void OnTriggerBackgroundTrace(tracing::mojom::BackgroundTracingRulePtr rule,
|
||||
std::optional<int32_t> value) override {
|
||||
std::optional<int32_t> value,
|
||||
uint64_t flow_id) override {
|
||||
++on_trigger_background_trace_count_;
|
||||
on_trigger_background_trace_rule_id_ = rule->rule_id;
|
||||
}
|
||||
|
@ -15,7 +15,9 @@ interface BackgroundTracingAgentClient {
|
||||
OnInitialized();
|
||||
// Called when a monitored histogram trigger is hit. Histograms are monitored
|
||||
// by calling BackgroundTracingAgent::SetUMACallback().
|
||||
OnTriggerBackgroundTrace(BackgroundTracingRule rule, int32? histogram_value);
|
||||
OnTriggerBackgroundTrace(BackgroundTracingRule rule,
|
||||
int32? histogram_value,
|
||||
uint64 flow_id);
|
||||
};
|
||||
|
||||
// This interface is used to allow clients (the browser process) to monitor for
|
||||
|
Reference in New Issue
Block a user