SF - plumbing game mode for metrics (part 2)
Update TimeStats to take in the game mode from layer for all the frames.
Bug: 186025682
Test: statsd_testdrive 10063
Test: atest libsurfaceflinger_unittest
Change-Id: If95a8c91940228a8925ae9e4e21656d1b492a2ba
diff --git a/services/surfaceflinger/TimeStats/timestatsproto/TimeStatsHelper.cpp b/services/surfaceflinger/TimeStats/timestatsproto/TimeStatsHelper.cpp
index a7e7db2..ffb2f09 100644
--- a/services/surfaceflinger/TimeStats/timestatsproto/TimeStatsHelper.cpp
+++ b/services/surfaceflinger/TimeStats/timestatsproto/TimeStatsHelper.cpp
@@ -122,6 +122,20 @@
return result;
}
+std::string TimeStatsHelper::TimeStatsLayer::toString(int32_t gameMode) const {
+ switch (gameMode) {
+ case TimeStatsHelper::GameModeUnsupported:
+ return "GameModeUnsupported";
+ case TimeStatsHelper::GameModeStandard:
+ return "GameModeStandard";
+ case TimeStatsHelper::GameModePerformance:
+ return "GameModePerformance";
+ case TimeStatsHelper::GameModeBattery:
+ return "GameModeBattery";
+ default:
+ return "GameModeUnspecified";
+ }
+}
std::string TimeStatsHelper::TimeStatsLayer::toString() const {
std::string result = "\n";
StringAppendF(&result, "displayRefreshRate = %d fps\n", displayRefreshRateBucket);
@@ -129,6 +143,7 @@
StringAppendF(&result, "uid = %d\n", uid);
StringAppendF(&result, "layerName = %s\n", layerName.c_str());
StringAppendF(&result, "packageName = %s\n", packageName.c_str());
+ StringAppendF(&result, "gameMode = %s\n", toString(gameMode).c_str());
StringAppendF(&result, "totalFrames = %d\n", totalFrames);
StringAppendF(&result, "droppedFrames = %d\n", droppedFrames);
StringAppendF(&result, "lateAcquireFrames = %d\n", lateAcquireFrames);
diff --git a/services/surfaceflinger/TimeStats/timestatsproto/include/timestatsproto/TimeStatsHelper.h b/services/surfaceflinger/TimeStats/timestatsproto/include/timestatsproto/TimeStatsHelper.h
index 2b37ffe..2afff8d 100644
--- a/services/surfaceflinger/TimeStats/timestatsproto/include/timestatsproto/TimeStatsHelper.h
+++ b/services/surfaceflinger/TimeStats/timestatsproto/include/timestatsproto/TimeStatsHelper.h
@@ -77,6 +77,18 @@
std::string toString() const;
};
+ /**
+ * GameMode of the layer. GameModes are set by SysUI through WMShell.
+ * Actual game mode definitions are managed by GameManager.java
+ * The values defined here should always be in sync with the ones in GameManager.
+ */
+ enum GameMode {
+ GameModeUnsupported = 0,
+ GameModeStandard = 1,
+ GameModePerformance = 2,
+ GameModeBattery = 3,
+ };
+
class TimeStatsLayer {
public:
uid_t uid;
@@ -84,6 +96,7 @@
std::string packageName;
int32_t displayRefreshRateBucket = 0;
int32_t renderRateBucket = 0;
+ int32_t gameMode = 0;
int32_t totalFrames = 0;
int32_t droppedFrames = 0;
int32_t lateAcquireFrames = 0;
@@ -93,6 +106,7 @@
std::unordered_map<std::string, Histogram> deltas;
std::string toString() const;
+ std::string toString(int32_t gameMode) const;
SFTimeStatsLayerProto toProto() const;
};
@@ -123,24 +137,19 @@
struct LayerStatsKey {
uid_t uid = 0;
std::string layerName;
+ int32_t gameMode = 0;
struct Hasher {
size_t operator()(const LayerStatsKey& key) const {
- size_t result = std::hash<uid_t>{}(key.uid);
- return HashCombine(result, std::hash<std::string>{}(key.layerName));
+ size_t uidHash = std::hash<uid_t>{}(key.uid);
+ size_t layerNameHash = std::hash<std::string>{}(key.layerName);
+ size_t gameModeHash = std::hash<int32_t>{}(key.gameMode);
+ return HashCombine(uidHash, HashCombine(layerNameHash, gameModeHash));
}
};
bool operator==(const LayerStatsKey& o) const {
- return uid == o.uid && layerName == o.layerName;
- }
- };
-
- struct LayerStatsHasher {
- size_t operator()(const std::pair<uid_t, std::string>& p) const {
- // Normally this isn't a very good hash function due to symmetry reasons,
- // but these are distinct types so this should be good enough
- return std::hash<uid_t>{}(p.first) ^ std::hash<std::string>{}(p.second);
+ return uid == o.uid && layerName == o.layerName && gameMode == o.gameMode;
}
};