Commit df362527 authored by khmel@chromium.org's avatar khmel@chromium.org Committed by Commit Bot

arc: Add CPU frequency info stat.

This adds CPU Frequency stats to ARC++ tracing tool.

TEST=Locally, unit_tests
BUG=b:141635977

Change-Id: Ib2645579d4d1be837f37ecacfd20364559768f7d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1825823
Commit-Queue: Yury Khmel <khmel@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700016}
parent 57e864f6
...@@ -146,22 +146,23 @@ TEST_F(ArcSystemModelTest, CloseRange) { ...@@ -146,22 +146,23 @@ TEST_F(ArcSystemModelTest, CloseRange) {
ArcSystemModel model; ArcSystemModel model;
model.memory_events().emplace_back( model.memory_events().emplace_back(
0 /* timestamp */, ArcValueEvent::Type::kGpuFreq, 100 /* value */); 0 /* timestamp */, ArcValueEvent::Type::kGpuFrequency, 100 /* value */);
model.memory_events().emplace_back( model.memory_events().emplace_back(
0 /* timestamp */, ArcValueEvent::Type::kCpuTemp, 20 /* value */); 0 /* timestamp */, ArcValueEvent::Type::kCpuTemperature, 20 /* value */);
model.memory_events().emplace_back( model.memory_events().emplace_back(
100 /* timestamp */, ArcValueEvent::Type::kGpuFreq, 150 /* value */); 100 /* timestamp */, ArcValueEvent::Type::kGpuFrequency, 150 /* value */);
model.memory_events().emplace_back( model.memory_events().emplace_back(200 /* timestamp */,
200 /* timestamp */, ArcValueEvent::Type::kCpuTemp, 50 /* value */); ArcValueEvent::Type::kCpuTemperature,
50 /* value */);
EXPECT_EQ(4u, model.memory_events().size()); EXPECT_EQ(4u, model.memory_events().size());
model.CloseRangeForValueEvents(200 /* timestamp */); model.CloseRangeForValueEvents(200 /* timestamp */);
// kGpuFreq is extended. // kGpuFrequency is extended.
ASSERT_EQ(5u, model.memory_events().size()); ASSERT_EQ(5u, model.memory_events().size());
EXPECT_EQ(ArcValueEvent(200 /* timestamp */, ArcValueEvent::Type::kGpuFreq, EXPECT_EQ(ArcValueEvent(200 /* timestamp */,
150 /* value */), ArcValueEvent::Type::kGpuFrequency, 150 /* value */),
model.memory_events().back()); model.memory_events().back());
} }
......
...@@ -42,6 +42,8 @@ const base::FilePath::CharType kGemInfoPath[] = ...@@ -42,6 +42,8 @@ const base::FilePath::CharType kGemInfoPath[] =
const base::FilePath::CharType kGemInfoPath[] = const base::FilePath::CharType kGemInfoPath[] =
FILE_PATH_LITERAL("/run/debugfs_gpu/i915_gem_objects"); FILE_PATH_LITERAL("/run/debugfs_gpu/i915_gem_objects");
#endif #endif
const base::FilePath::CharType kCpuFrequencyPath[] =
FILE_PATH_LITERAL("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq");
bool IsWhitespace(char c) { bool IsWhitespace(char c) {
return c == ' ' || c == '\t' || c == '\n'; return c == ' ' || c == '\t' || c == '\n';
...@@ -108,7 +110,14 @@ const base::FilePath& GetCpuTemperaturePathOnFileThread() { ...@@ -108,7 +110,14 @@ const base::FilePath& GetCpuTemperaturePathOnFileThread() {
return instance->path(); return instance->path();
} }
enum SystemReader { kZram = 0, kMemoryInfo, kGemInfo, kCpuTemperature, kTotal }; enum SystemReader {
kZram = 0,
kMemoryInfo,
kGemInfo,
kCpuTemperature,
kCpuFrequency,
kTotal
};
} // namespace } // namespace
...@@ -122,6 +131,7 @@ struct ArcSystemStatCollector::Sample { ...@@ -122,6 +131,7 @@ struct ArcSystemStatCollector::Sample {
int gem_objects = 0; int gem_objects = 0;
int gem_size_kb = 0; int gem_size_kb = 0;
int cpu_temperature = std::numeric_limits<int>::min(); int cpu_temperature = std::numeric_limits<int>::min();
int cpu_frequency = 0;
}; };
struct ArcSystemStatCollector::SystemReadersContext { struct ArcSystemStatCollector::SystemReadersContext {
...@@ -156,6 +166,12 @@ struct ArcSystemStatCollector::SystemReadersContext { ...@@ -156,6 +166,12 @@ struct ArcSystemStatCollector::SystemReadersContext {
LOG(ERROR) << "Failed to open cpu temperature file: " << cpu_temp_path.value(); LOG(ERROR) << "Failed to open cpu temperature file: " << cpu_temp_path.value();
} }
context->system_readers[SystemReader::kCpuFrequency].reset(
open(kCpuFrequencyPath, O_RDONLY));
if (!context->system_readers[SystemReader::kCpuFrequency].is_valid()) {
LOG(ERROR) << "Failed to open cpu frequency file: " << kCpuFrequencyPath;
}
return context; return context;
} }
...@@ -180,7 +196,7 @@ constexpr int ArcSystemStatCollector::kMemInfoColumns[]; ...@@ -180,7 +196,7 @@ constexpr int ArcSystemStatCollector::kMemInfoColumns[];
constexpr int ArcSystemStatCollector::kGemInfoColumns[]; constexpr int ArcSystemStatCollector::kGemInfoColumns[];
// static // static
constexpr int ArcSystemStatCollector::kCpuTempInfoColumns[]; constexpr int ArcSystemStatCollector::kOneValueColumns[];
ArcSystemStatCollector::ArcSystemStatCollector() {} ArcSystemStatCollector::ArcSystemStatCollector() {}
...@@ -235,7 +251,9 @@ void ArcSystemStatCollector::Flush(const base::TimeTicks& min_timestamp, ...@@ -235,7 +251,9 @@ void ArcSystemStatCollector::Flush(const base::TimeTicks& min_timestamp,
ArcValueEventTrimmer swap_wait(&system_model->memory_events(), ArcValueEventTrimmer swap_wait(&system_model->memory_events(),
ArcValueEvent::Type::kSwapWait); ArcValueEvent::Type::kSwapWait);
ArcValueEventTrimmer cpu_temperature(&system_model->memory_events(), ArcValueEventTrimmer cpu_temperature(&system_model->memory_events(),
ArcValueEvent::Type::kCpuTemp); ArcValueEvent::Type::kCpuTemperature);
ArcValueEventTrimmer cpu_frequency(&system_model->memory_events(),
ArcValueEvent::Type::kCpuFrequency);
while (sample_index < write_index_) { while (sample_index < write_index_) {
const Sample& sample = samples_[sample_index % samples_.size()]; const Sample& sample = samples_[sample_index % samples_.size()];
++sample_index; ++sample_index;
...@@ -254,6 +272,8 @@ void ArcSystemStatCollector::Flush(const base::TimeTicks& min_timestamp, ...@@ -254,6 +272,8 @@ void ArcSystemStatCollector::Flush(const base::TimeTicks& min_timestamp,
swap_wait.MaybeAdd(timestamp, sample.swap_waiting_time_ms); swap_wait.MaybeAdd(timestamp, sample.swap_waiting_time_ms);
if (sample.cpu_temperature > std::numeric_limits<int>::min()) if (sample.cpu_temperature > std::numeric_limits<int>::min())
cpu_temperature.MaybeAdd(timestamp, sample.cpu_temperature); cpu_temperature.MaybeAdd(timestamp, sample.cpu_temperature);
if (sample.cpu_frequency > 0)
cpu_frequency.MaybeAdd(timestamp, sample.cpu_frequency);
} }
// Trimmer may break time sequence for events of different types. However // Trimmer may break time sequence for events of different types. However
// time sequence of events of the same type should be preserved. // time sequence of events of the same type should be preserved.
...@@ -335,7 +355,7 @@ ArcSystemStatCollector::ReadSystemStatOnBackgroundThread( ...@@ -335,7 +355,7 @@ ArcSystemStatCollector::ReadSystemStatOnBackgroundThread(
sizeof(context->current_frame.gem_info)); sizeof(context->current_frame.gem_info));
static bool error_reported = false; static bool error_reported = false;
if (!error_reported) { if (!error_reported) {
LOG(ERROR) << "Failed to read gem info file: " << kGemInfoColumns; LOG(ERROR) << "Failed to read gem info file: " << kGemInfoPath;
error_reported = true; error_reported = true;
} }
} }
...@@ -343,7 +363,7 @@ ArcSystemStatCollector::ReadSystemStatOnBackgroundThread( ...@@ -343,7 +363,7 @@ ArcSystemStatCollector::ReadSystemStatOnBackgroundThread(
if (!context->system_readers[SystemReader::kCpuTemperature].is_valid() || if (!context->system_readers[SystemReader::kCpuTemperature].is_valid() ||
!ParseStatFile( !ParseStatFile(
context->system_readers[SystemReader::kCpuTemperature].get(), context->system_readers[SystemReader::kCpuTemperature].get(),
kCpuTempInfoColumns, &context->current_frame.cpu_temperature)) { kOneValueColumns, &context->current_frame.cpu_temperature)) {
context->current_frame.cpu_temperature = std::numeric_limits<int>::min(); context->current_frame.cpu_temperature = std::numeric_limits<int>::min();
static bool error_reported = false; static bool error_reported = false;
if (!error_reported) { if (!error_reported) {
...@@ -353,6 +373,17 @@ ArcSystemStatCollector::ReadSystemStatOnBackgroundThread( ...@@ -353,6 +373,17 @@ ArcSystemStatCollector::ReadSystemStatOnBackgroundThread(
} }
} }
if (!context->system_readers[SystemReader::kCpuFrequency].is_valid() ||
!ParseStatFile(context->system_readers[SystemReader::kCpuFrequency].get(),
kOneValueColumns, &context->current_frame.cpu_frequency)) {
context->current_frame.cpu_frequency = 0;
static bool error_reported = false;
if (!error_reported) {
LOG(ERROR) << "Failed to read cpu frequency : " << kCpuFrequencyPath;
error_reported = true;
}
}
return context; return context;
} }
...@@ -379,6 +410,7 @@ void ArcSystemStatCollector::UpdateSystemStatOnUiThread( ...@@ -379,6 +410,7 @@ void ArcSystemStatCollector::UpdateSystemStatOnUiThread(
context->current_frame.zram_stat[2] - previous_frame_.zram_stat[2]; context->current_frame.zram_stat[2] - previous_frame_.zram_stat[2];
} }
current_sample.cpu_temperature = context->current_frame.cpu_temperature; current_sample.cpu_temperature = context->current_frame.cpu_temperature;
current_sample.cpu_frequency = context->current_frame.cpu_frequency;
DCHECK_GE(current_sample.swap_sectors_read, 0); DCHECK_GE(current_sample.swap_sectors_read, 0);
DCHECK_GE(current_sample.swap_sectors_write, 0); DCHECK_GE(current_sample.swap_sectors_write, 0);
DCHECK_GE(current_sample.swap_waiting_time_ms, 0); DCHECK_GE(current_sample.swap_waiting_time_ms, 0);
......
...@@ -58,12 +58,11 @@ class ArcSystemStatCollector { ...@@ -58,12 +58,11 @@ class ArcSystemStatCollector {
-1, // End of sequence -1, // End of sequence
}; };
// Indices of fields to parse // Indices of fields to parse as one value.
// /sys/class/hwmon/hwmon*/temp*_input // For example: /sys/class/hwmon/hwmon*/temp*_input
// As an example:
// 30000 // 30000
static constexpr int kCpuTempInfoColumns[] = { static constexpr int kOneValueColumns[] = {
0, // Temperature in celsius * 1000. 0,
-1, // End of sequence -1, // End of sequence
}; };
...@@ -95,6 +94,8 @@ class ArcSystemStatCollector { ...@@ -95,6 +94,8 @@ class ArcSystemStatCollector {
int64_t gem_info[base::size(kGemInfoColumns) - 1] = {0}; int64_t gem_info[base::size(kGemInfoColumns) - 1] = {0};
// Temperature of CPU, Core 0. // Temperature of CPU, Core 0.
int64_t cpu_temperature = std::numeric_limits<int>::min(); int64_t cpu_temperature = std::numeric_limits<int>::min();
// CPU Frequency.
int64_t cpu_frequency = 0;
}; };
// Schedules reading System stat files in |ReadSystemStatOnBackgroundThread| // Schedules reading System stat files in |ReadSystemStatOnBackgroundThread|
......
...@@ -57,7 +57,7 @@ TEST_F(ArcSystemStatCollectorTest, Parse) { ...@@ -57,7 +57,7 @@ TEST_F(ArcSystemStatCollectorTest, Parse) {
int64_t cpu_temp; int64_t cpu_temp;
EXPECT_TRUE(ParseStatFile(OpenTestStatFile("temp1_input").get(), EXPECT_TRUE(ParseStatFile(OpenTestStatFile("temp1_input").get(),
ArcSystemStatCollector::kCpuTempInfoColumns, ArcSystemStatCollector::kOneValueColumns,
&cpu_temp)); &cpu_temp));
EXPECT_EQ(52000, cpu_temp); EXPECT_EQ(52000, cpu_temp);
} }
......
...@@ -313,7 +313,7 @@ bool HandleGpuFreq(ValueEvents* value_events, ...@@ -313,7 +313,7 @@ bool HandleGpuFreq(ValueEvents* value_events,
return false; return false;
} }
value_events->emplace_back(timestamp, ArcValueEvent::Type::kGpuFreq, value_events->emplace_back(timestamp, ArcValueEvent::Type::kGpuFrequency,
new_freq); new_freq);
return true; return true;
} }
......
...@@ -46,8 +46,9 @@ bool LoadValueEvents(const base::Value* value, ValueEvents* value_events) { ...@@ -46,8 +46,9 @@ bool LoadValueEvents(const base::Value* value, ValueEvents* value_events) {
case ArcValueEvent::Type::kSwapWait: case ArcValueEvent::Type::kSwapWait:
case ArcValueEvent::Type::kGemObjects: case ArcValueEvent::Type::kGemObjects:
case ArcValueEvent::Type::kGemSize: case ArcValueEvent::Type::kGemSize:
case ArcValueEvent::Type::kGpuFreq: case ArcValueEvent::Type::kGpuFrequency:
case ArcValueEvent::Type::kCpuTemp: case ArcValueEvent::Type::kCpuTemperature:
case ArcValueEvent::Type::kCpuFrequency:
break; break;
default: default:
return false; return false;
......
...@@ -22,8 +22,9 @@ struct ArcValueEvent { ...@@ -22,8 +22,9 @@ struct ArcValueEvent {
kSwapWait, kSwapWait,
kGemObjects, kGemObjects,
kGemSize, kGemSize,
kGpuFreq, kGpuFrequency,
kCpuTemp, kCpuTemperature,
kCpuFrequency,
}; };
ArcValueEvent(int64_t timestamp, Type type, int value); ArcValueEvent(int64_t timestamp, Type type, int value);
...@@ -40,8 +41,9 @@ struct ArcValueEvent { ...@@ -40,8 +41,9 @@ struct ArcValueEvent {
* kSwapWait - milliseconds. * kSwapWait - milliseconds.
* kGemObjects - number of objects * kGemObjects - number of objects
* kGemSize - kb * kGemSize - kb
* kGpuFreq - mhz * kGpuFrequency - mhz
* kCpuTemp - celsius * 1000 * kCpuTemperature - celsius * 1000
* kCpuFrequency - khz
*/ */
int value; int value;
}; };
......
...@@ -212,7 +212,7 @@ var valueAttributes = { ...@@ -212,7 +212,7 @@ var valueAttributes = {
scale: 1.0 / 1024.0, scale: 1.0 / 1024.0,
width: 1.0 width: 1.0
}, },
// kGpuFreq. // kGpuFrequency.
7: { 7: {
color: '#01579b', color: '#01579b',
minRange: 300.0, minRange: 300.0,
...@@ -220,7 +220,7 @@ var valueAttributes = { ...@@ -220,7 +220,7 @@ var valueAttributes = {
scale: 1.0, scale: 1.0,
width: 1.0 width: 1.0
}, },
// kCpuTemp. // kCpuTemperature.
8: { 8: {
color: '#ff3d00', color: '#ff3d00',
minRange: 20.0, minRange: 20.0,
...@@ -228,6 +228,14 @@ var valueAttributes = { ...@@ -228,6 +228,14 @@ var valueAttributes = {
scale: 1.0 / 1000.0, scale: 1.0 / 1000.0,
width: 1.0 width: 1.0
}, },
// kCpuFrequency.
9: {
color: '#ff80ab',
minRange: 300.0,
name: 'CPU Mhz.',
scale: 1.0 / 1000.0,
width: 1.0
},
}; };
/** /**
...@@ -1650,7 +1658,13 @@ function setGraphicBuffersModel(model) { ...@@ -1650,7 +1658,13 @@ function setGraphicBuffersModel(model) {
cpusBands.setModel(model); cpusBands.setModel(model);
cpusBands.addChartToExistingArea(0 /* top */, cpusBands.height); cpusBands.addChartToExistingArea(0 /* top */, cpusBands.height);
cpusBands.addChartSources( cpusBands.addChartSources(
[new Events(model.system.memory, 8 /* kCpuTemp */, 8 /* kCpuTemp */)], [new Events(
model.system.memory, 8 /* kCpuTemperature */,
8 /* kCpuTemperature */)],
true /* smooth */);
cpusBands.addChartSources(
[new Events(
model.system.memory, 9 /* kCpuFrequency */, 9 /* kCpuFrequency */)],
true /* smooth */); true /* smooth */);
cpusBands.setVSync(vsyncEvents); cpusBands.setVSync(vsyncEvents);
...@@ -1701,7 +1715,8 @@ function setGraphicBuffersModel(model) { ...@@ -1701,7 +1715,8 @@ function setGraphicBuffersModel(model) {
chromeBands.addChartToExistingArea(0 /* top */, chromeBands.height); chromeBands.addChartToExistingArea(0 /* top */, chromeBands.height);
chromeBands.addChartSources( chromeBands.addChartSources(
[new Events(model.system.memory, 7 /* kGpuFreq */, 7 /* kGpuFreq */)], [new Events(
model.system.memory, 7 /* kGpuFrequency */, 7 /* kGpuFrequency */)],
false /* smooth */); false /* smooth */);
......
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