Commit 78ba8b7b authored by Xida Chen's avatar Xida Chen Committed by Commit Bot

[Code health] Unify two tracker type name array

We have kFrameSequenceTrackerTypeNames defined in the
compositor_frame_reporter.cc and kBuiltinSequences defined in the
frame_sequence_tracker.cc, where these two essential represents the same
thing. This is problematic, that when we add an entry in one place, the
other place must be adding that entry too.

This CL defines kFrameSequenceTrackerTypeNames as static in the
CompositorFrameReporter class and then FrameSequenceTracker can just
use it.

No behavior change should be introduced.

Bug: None
Change-Id: I0dc9e40be82d147615e1aa61afb1a7d8750390e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1774831
Commit-Queue: Xida Chen <xidachen@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#692053}
parent cbe2bc9f
......@@ -10,6 +10,7 @@
#include "base/strings/strcat.h"
#include "base/trace_event/trace_event.h"
#include "cc/base/rolling_time_delta_history.h"
#include "cc/metrics/frame_sequence_tracker.h"
namespace cc {
namespace {
......@@ -51,14 +52,6 @@ static_assert(sizeof(kStageNames) / sizeof(kStageNames[0]) == kStageTypeCount,
constexpr const char* kReportTypeNames[]{"", "MissedFrame.",
"MissedFrameLatencyIncrease."};
constexpr const char* kFrameSequenceTrackerTypeNames[]{"CompositorAnimation.",
"MainThreadAnimation.",
"PinchZoom.",
"RAF.",
"TouchScroll.",
"WheelScroll.",
""};
static_assert(sizeof(kReportTypeNames) / sizeof(kReportTypeNames[0]) ==
kMissedFrameReportTypeCount,
"Compositor latency report types has changed.");
......@@ -77,11 +70,13 @@ std::string HistogramName(const char* compositor_type,
const int report_type_index,
const int frame_sequence_tracker_type_index,
const int stage_type_index) {
return base::StrCat(
{compositor_type, "CompositorLatency.",
kReportTypeNames[report_type_index],
kFrameSequenceTrackerTypeNames[frame_sequence_tracker_type_index],
kStageNames[stage_type_index]});
std::string tracker_type_name = FrameSequenceTracker::
kFrameSequenceTrackerTypeNames[frame_sequence_tracker_type_index];
if (!tracker_type_name.empty())
tracker_type_name += ".";
return base::StrCat({compositor_type, "CompositorLatency.",
kReportTypeNames[report_type_index], tracker_type_name,
kStageNames[stage_type_index]});
}
} // namespace
......
......@@ -16,6 +16,10 @@
namespace cc {
const char* const FrameSequenceTracker::kFrameSequenceTrackerTypeNames[] = {
"CompositorAnimation", "MainThreadAnimation", "PinchZoom", "RAF",
"TouchScroll", "WheelScroll", ""};
namespace {
enum class ThreadType {
......@@ -23,16 +27,8 @@ enum class ThreadType {
kCompositor,
};
constexpr const char* const kBuiltinSequences[] = {
[FrameSequenceTrackerType::kCompositorAnimation] = "CompositorAnimation",
[FrameSequenceTrackerType::kMainThreadAnimation] = "MainThreadAnimation",
[FrameSequenceTrackerType::kPinchZoom] = "PinchZoom",
[FrameSequenceTrackerType::kRAF] = "RAF",
[FrameSequenceTrackerType::kTouchScroll] = "TouchScroll",
[FrameSequenceTrackerType::kWheelScroll] = "WheelScroll",
};
constexpr int kBuiltinSequenceNum = base::size(kBuiltinSequences);
constexpr int kBuiltinSequenceNum =
base::size(FrameSequenceTracker::kFrameSequenceTrackerTypeNames);
constexpr int kMaximumHistogramIndex = 2 * kBuiltinSequenceNum;
int GetIndexForMetric(ThreadType thread_type, FrameSequenceTrackerType type) {
......@@ -158,8 +154,10 @@ FrameSequenceTracker* FrameSequenceTrackerCollection::GetTrackerForTesting(
FrameSequenceTracker::FrameSequenceTracker(FrameSequenceTrackerType type)
: type_(type) {
DCHECK_LT(type_, FrameSequenceTrackerType::kMaxType);
TRACE_EVENT_ASYNC_BEGIN1("cc,benchmark", "FrameSequenceTracker", this, "name",
TRACE_STR_COPY(kBuiltinSequences[type_]));
TRACE_EVENT_ASYNC_BEGIN1(
"cc,benchmark", "FrameSequenceTracker", this, "name",
TRACE_STR_COPY(
FrameSequenceTracker::kFrameSequenceTrackerTypeNames[type_]));
}
FrameSequenceTracker::~FrameSequenceTracker() {
......@@ -374,9 +372,9 @@ void FrameSequenceTracker::ThroughputData::ReportHistogram(
const ThroughputData& data) {
DCHECK_LT(sequence_type, FrameSequenceTrackerType::kMaxType);
const std::string sequence_length_name =
base::StrCat({"Graphics.Smoothness.FrameSequenceLength.",
kBuiltinSequences[sequence_type]});
const std::string sequence_length_name = base::StrCat(
{"Graphics.Smoothness.FrameSequenceLength.",
FrameSequenceTracker::kFrameSequenceTrackerTypeNames[sequence_type]});
STATIC_HISTOGRAM_POINTER_GROUP(
sequence_length_name, sequence_type, FrameSequenceTrackerType::kMaxType,
Add(data.frames_expected),
......@@ -390,9 +388,9 @@ void FrameSequenceTracker::ThroughputData::ReportHistogram(
if (data.frames_expected < kMinFramesForThroughputMetric)
return;
const std::string name =
base::StrCat({"Graphics.Smoothness.Throughput.", thread_name, ".",
kBuiltinSequences[sequence_type]});
const std::string name = base::StrCat(
{"Graphics.Smoothness.Throughput.", thread_name, ".",
FrameSequenceTracker::kFrameSequenceTrackerTypeNames[sequence_type]});
const int percent =
static_cast<int>(100 * data.frames_produced / data.frames_expected);
STATIC_HISTOGRAM_POINTER_GROUP(
......
......@@ -113,6 +113,8 @@ class CC_EXPORT FrameSequenceTracker {
kReadyForTermination,
};
static const char* const kFrameSequenceTrackerTypeNames[];
~FrameSequenceTracker();
FrameSequenceTracker(const FrameSequenceTracker&) = delete;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment