diff options
author | Ram Chandrasekar <rkumbako@codeaurora.org> | 2020-08-06 14:39:40 -0700 |
---|---|---|
committer | Ram Chandrasekar <rkumbako@codeaurora.org> | 2020-08-06 16:01:48 -0700 |
commit | 72110b5283c86afae170bb00ed5147496d6d780d (patch) | |
tree | b0995eecf000c930843bb2c63bed79d56ef9e35b /thermalCommon.cpp | |
parent | dac8f7dd5a799e95196072ac7ac0ff6b944867b0 (diff) |
thermal-hal: Re-size cpu usage vector based on cpu count
Re-size cpu usage vector to cpu count size before filling in the data.
This will ensure that sufficient memory is allocated before populating
the data.
Change-Id: I7a1d109cf3ec8403ca61beed9a9eab4287a3d33c
Diffstat (limited to 'thermalCommon.cpp')
-rw-r--r-- | thermalCommon.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/thermalCommon.cpp b/thermalCommon.cpp index 642573f..308086c 100644 --- a/thermalCommon.cpp +++ b/thermalCommon.cpp @@ -505,7 +505,7 @@ void ThermalCommon::initThreshold(struct therm_sensor sensor) return; } -int ThermalCommon::get_cpu_usages(hidl_vec<CpuUsage> *list) { +int ThermalCommon::get_cpu_usages(hidl_vec<CpuUsage>& list) { int vals, cpu_num, online; ssize_t read; uint64_t user, nice, system, idle, active, total; @@ -516,6 +516,7 @@ int ThermalCommon::get_cpu_usages(hidl_vec<CpuUsage> *list) { FILE *file; FILE *cpu_file; + list.resize(ncpus); file = fopen(CPU_USAGE_FILE, "r"); if (file == NULL) { LOG(ERROR) << "failed to open:" << CPU_USAGE_FILE << @@ -574,10 +575,10 @@ int ThermalCommon::get_cpu_usages(hidl_vec<CpuUsage> *list) { } fclose(cpu_file); - (*list)[cpu_num].name = std::string("CPU") + std::to_string(cpu_num); - (*list)[cpu_num].active = active; - (*list)[cpu_num].total = total; - (*list)[cpu_num].isOnline = online; + list[cpu_num].name = std::string("CPU") + std::to_string(cpu_num); + list[cpu_num].active = active; + list[cpu_num].total = total; + list[cpu_num].isOnline = online; cpu++; } fclose(file); |