Skip to content

Commit

Permalink
cc metrics: Some code cleanup.
Browse files Browse the repository at this point in the history
. Use indexed initializer when specifying the names for types.
. Avoid unnecessary construction of a std::string out of a const char*.
. Keep the list of sequence-types alphabetically sorted.

BUG=none

Change-Id: I8261c3ef3b1e5ab830042ad788f9fb2dc0810a9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1811197
Commit-Queue: Sadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: Behdad Bakhshinategh <behdadb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#698149}
  • Loading branch information
sadrulhc authored and Commit Bot committed Sep 19, 2019
1 parent 2bd930f commit 5488de7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
37 changes: 23 additions & 14 deletions cc/metrics/compositor_frame_reporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,34 @@
namespace cc {
namespace {

using StageType = CompositorFrameReporter::StageType;

constexpr int kMissedFrameReportTypeCount =
static_cast<int>(CompositorFrameReporter::MissedFrameReportTypes::
kMissedFrameReportTypeCount);
constexpr int kStageTypeCount =
static_cast<int>(CompositorFrameReporter::StageType::kStageTypeCount);
constexpr int kStageTypeCount = static_cast<int>(StageType::kStageTypeCount);
// For each possible FrameSequenceTrackerType there will be a UMA histogram
// plus one for general case.
constexpr int kFrameSequenceTrackerTypeCount =
static_cast<int>(FrameSequenceTrackerType::kMaxType) + 1;

// Names for CompositorFrameReporter::StageType, which should be updated in case
// of changes to the enum.
constexpr const char* kStageNames[]{
"BeginImplFrameToSendBeginMainFrame",
"SendBeginMainFrameToCommit",
"Commit",
"EndCommitToActivation",
"Activation",
"EndActivateToSubmitCompositorFrame",
"SubmitCompositorFrameToPresentationCompositorFrame",
"TotalLatency"};
constexpr const char* kStageNames[] = {
[static_cast<int>(StageType::kBeginImplFrameToSendBeginMainFrame)] =
"BeginImplFrameToSendBeginMainFrame",
[static_cast<int>(StageType::kSendBeginMainFrameToCommit)] =
"SendBeginMainFrameToCommit",
[static_cast<int>(StageType::kCommit)] = "Commit",
[static_cast<int>(StageType::kEndCommitToActivation)] =
"EndCommitToActivation",
[static_cast<int>(StageType::kActivation)] = "Activation",
[static_cast<int>(StageType::kEndActivateToSubmitCompositorFrame)] =
"EndActivateToSubmitCompositorFrame",
[static_cast<int>(
StageType::kSubmitCompositorFrameToPresentationCompositorFrame)] =
"SubmitCompositorFrameToPresentationCompositorFrame",
[static_cast<int>(StageType::kTotalLatency)] = "TotalLatency"};
static_assert(sizeof(kStageNames) / sizeof(kStageNames[0]) == kStageTypeCount,
"Compositor latency stages has changed.");

Expand All @@ -61,12 +68,14 @@ constexpr int kHistogramBucketCount = 50;
std::string HistogramName(const int report_type_index,
const int frame_sequence_tracker_type_index,
const int stage_type_index) {
std::string tracker_type_name = FrameSequenceTracker::
DCHECK_LE(frame_sequence_tracker_type_index,
FrameSequenceTrackerType::kMaxType);
const char* tracker_type_name = FrameSequenceTracker::
kFrameSequenceTrackerTypeNames[frame_sequence_tracker_type_index];
if (!tracker_type_name.empty())
tracker_type_name += ".";
DCHECK(tracker_type_name);
return base::StrCat({"CompositorLatency.",
kReportTypeNames[report_type_index], tracker_type_name,
*tracker_type_name ? "." : "",
kStageNames[stage_type_index]});
}
} // namespace
Expand Down
13 changes: 10 additions & 3 deletions cc/metrics/frame_sequence_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@

namespace cc {

const char* const FrameSequenceTracker::kFrameSequenceTrackerTypeNames[] = {
"CompositorAnimation", "MainThreadAnimation", "PinchZoom", "RAF",
"TouchScroll", "WheelScroll", "Universal", ""};
constexpr const char* FrameSequenceTracker::kFrameSequenceTrackerTypeNames[] = {
[FrameSequenceTrackerType::kCompositorAnimation] = "CompositorAnimation",
[FrameSequenceTrackerType::kMainThreadAnimation] = "MainThreadAnimation",
[FrameSequenceTrackerType::kPinchZoom] = "PinchZoom",
[FrameSequenceTrackerType::kRAF] = "RAF",
[FrameSequenceTrackerType::kTouchScroll] = "TouchScroll",
[FrameSequenceTrackerType::kUniversal] = "Universal",
[FrameSequenceTrackerType::kWheelScroll] = "WheelScroll",
[FrameSequenceTrackerType::kMaxType] = "",
};

namespace {

Expand Down
4 changes: 2 additions & 2 deletions cc/metrics/frame_sequence_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ enum FrameSequenceTrackerType {
kPinchZoom = 2,
kRAF = 3,
kTouchScroll = 4,
kWheelScroll = 5,
kUniversal = 6,
kUniversal = 5,
kWheelScroll = 6,
kMaxType
};

Expand Down

0 comments on commit 5488de7

Please sign in to comment.