[tracing] Fix flow id plumbing through histogram
Following up on https://chromium-review.googlesource.com/c/chromium/src/+/6233616 I realized that the callback is invoked as a task, so the thread local event id isn't plumbed correctly. The solution I'm proposing here is to grab the event id directly in histogram impl (FindAndRunCallbacks), and forward it to callbacks, without changing the histogram API. Drive-by: IWYU fixes. Bug: 40257548 Change-Id: Ibf5ac1c4e96f0eff63b108d1acf3e550579f6ee5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6302393 Reviewed-by: Luc Nguyen <lucnguyen@google.com> Reviewed-by: Etienne Bergeron <etienneb@chromium.org> Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org> Cr-Commit-Position: refs/heads/main@{#1426581}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
1064c21b84
commit
178bde2f65
base
metrics
trace_event
content/browser
services/tracing/public/cpp
@ -80,6 +80,7 @@ void BackgroundTracingAgentImpl::OnHistogramChanged(
|
||||
const std::string& rule_id,
|
||||
base::Histogram::Sample32 histogram_lower_value,
|
||||
base::Histogram::Sample32 histogram_upper_value,
|
||||
std::optional<uint64_t> event_id,
|
||||
std::string_view histogram_name,
|
||||
uint64_t name_hash,
|
||||
base::Histogram::Sample32 actual_value) {
|
||||
@ -89,8 +90,8 @@ void BackgroundTracingAgentImpl::OnHistogramChanged(
|
||||
}
|
||||
|
||||
auto track = perfetto::NamedTrack("HistogramSamples");
|
||||
uint64_t flow_id = base::trace_event::HistogramScope::GetFlowId().value_or(
|
||||
base::trace_event::GetNextGlobalTraceId());
|
||||
uint64_t flow_id =
|
||||
event_id.value_or(base::trace_event::GetNextGlobalTraceId());
|
||||
TRACE_EVENT("toplevel,latency", "HistogramSampleTrigger", track,
|
||||
[&](perfetto::EventContext ctx) {
|
||||
perfetto::protos::pbzero::ChromeHistogramSample* new_sample =
|
||||
|
@ -49,6 +49,7 @@ class COMPONENT_EXPORT(BACKGROUND_TRACING_CPP) BackgroundTracingAgentImpl
|
||||
void OnHistogramChanged(const std::string& rule_id,
|
||||
base::Histogram::Sample32 reference_lower_value,
|
||||
base::Histogram::Sample32 reference_upper_value,
|
||||
std::optional<uint64_t> event_id,
|
||||
std::string_view histogram_name,
|
||||
uint64_t name_hash,
|
||||
base::Histogram::Sample32 actual_value);
|
||||
|
@ -136,6 +136,7 @@ void HistogramSamplesDataSource::OnStop(const StopArgs&) {
|
||||
void HistogramSamplesDataSource::OnMetricSample(
|
||||
std::optional<base::HistogramBase::Sample32> reference_lower_value,
|
||||
std::optional<base::HistogramBase::Sample32> reference_upper_value,
|
||||
std::optional<uint64_t> event_id,
|
||||
std::string_view histogram_name,
|
||||
uint64_t name_hash,
|
||||
base::HistogramBase::Sample32 sample) {
|
||||
@ -143,18 +144,20 @@ void HistogramSamplesDataSource::OnMetricSample(
|
||||
(reference_upper_value && sample > reference_upper_value)) {
|
||||
return;
|
||||
}
|
||||
OnMetricSampleImpl(histogram_name, name_hash, sample,
|
||||
OnMetricSampleImpl(event_id, histogram_name, name_hash, sample,
|
||||
reinterpret_cast<uintptr_t>(this));
|
||||
}
|
||||
|
||||
void HistogramSamplesDataSource::OnAnyMetricSample(
|
||||
std::string_view histogram_name,
|
||||
uint64_t name_hash,
|
||||
base::HistogramBase::Sample32 sample) {
|
||||
OnMetricSampleImpl(histogram_name, name_hash, sample, std::nullopt);
|
||||
base::HistogramBase::Sample32 sample,
|
||||
std::optional<uint64_t> event_id) {
|
||||
OnMetricSampleImpl(event_id, histogram_name, name_hash, sample, std::nullopt);
|
||||
}
|
||||
|
||||
void HistogramSamplesDataSource::OnMetricSampleImpl(
|
||||
std::optional<uint64_t> event_id,
|
||||
std::string_view histogram_name,
|
||||
uint64_t name_hash,
|
||||
base::HistogramBase::Sample32 sample,
|
||||
@ -186,6 +189,9 @@ void HistogramSamplesDataSource::OnMetricSampleImpl(
|
||||
event->set_name_iid(1);
|
||||
event->add_category_iids(1);
|
||||
event->set_type(::perfetto::protos::pbzero::TrackEvent::TYPE_INSTANT);
|
||||
if (event_id) {
|
||||
event->add_flow_ids(*event_id);
|
||||
}
|
||||
|
||||
perfetto::protos::pbzero::ChromeHistogramSample* new_sample =
|
||||
event->set_chrome_histogram_sample();
|
||||
|
@ -46,15 +46,18 @@ class COMPONENT_EXPORT(TRACING_CPP) HistogramSamplesDataSource
|
||||
void OnMetricSample(
|
||||
std::optional<base::HistogramBase::Sample32> reference_lower_value,
|
||||
std::optional<base::HistogramBase::Sample32> reference_upper_value,
|
||||
std::optional<uint64_t> event_id,
|
||||
std::string_view histogram_name,
|
||||
uint64_t name_hash,
|
||||
base::HistogramBase::Sample32 actual_value);
|
||||
static void OnAnyMetricSample(std::string_view histogram_name,
|
||||
uint64_t name_hash,
|
||||
base::HistogramBase::Sample32 sample);
|
||||
base::HistogramBase::Sample32 sample,
|
||||
std::optional<uint64_t> event_id);
|
||||
// `instance` identifies the instance that registered a callback, or nullopt
|
||||
// if this is a global callback.
|
||||
static void OnMetricSampleImpl(std::string_view histogram_name,
|
||||
static void OnMetricSampleImpl(std::optional<uint64_t> event_id,
|
||||
std::string_view histogram_name,
|
||||
uint64_t name_hash,
|
||||
base::HistogramBase::Sample32 sample,
|
||||
std::optional<uintptr_t> instance);
|
||||
|
Reference in New Issue
Block a user