void cpu_linux::parse_cstates_start(void) { ifstream file; DIR *dir; struct dirent *entry; char filename[256]; int len; len = snprintf(filename, sizeof(filename), "/sys/devices/system/cpu/cpu%i/cpuidle", number); dir = opendir(filename); if (!dir) return; /* For each C-state, there is a stateX directory which * contains a 'usage' and a 'time' (duration) file */ while ((entry = readdir(dir))) { char linux_name[64]; char human_name[64]; uint64_t usage = 0; uint64_t duration = 0; if (strlen(entry->d_name) < 3) continue; pt_strcpy(linux_name, entry->d_name); pt_strcpy(human_name, linux_name); snprintf(filename + len, sizeof(filename) - len, "/%s/name", entry->d_name); file.open(filename, ios::in); if (file) { file.getline(human_name, sizeof(human_name)); file.close(); } if (strcmp(human_name, "C0")==0) pt_strcpy(human_name, _("C0 polling")); snprintf(filename + len, sizeof(filename) - len, "/%s/usage", entry->d_name); file.open(filename, ios::in); if (file) { file >> usage; file.close(); } else continue; snprintf(filename + len, sizeof(filename) - len, "/%s/time", entry->d_name); file.open(filename, ios::in); if (file) { file >> duration; file.close(); } update_cstate(linux_name, human_name, usage, duration, 1); }
void abstract_cpu::measurement_end(void) { unsigned int i, j; total_stamp = 0; gettimeofday(&stamp_after, NULL); for (i = 0; i < children.size(); i++) if (children[i]) children[i]->wiggle(); time_factor = 1000000.0 * (stamp_after.tv_sec - stamp_before.tv_sec) + stamp_after.tv_usec - stamp_before.tv_usec; for (i = 0; i < children.size(); i++) if (children[i]) children[i]->measurement_end(); for (i = 0; i < children.size(); i++) if (children[i]) { for (j = 0; j < children[i]->cstates.size(); j++) { struct idle_state *state; state = children[i]->cstates[j]; if (!state) continue; update_cstate( state->linux_name, state->human_name, state->usage_before, state->duration_before, state->before_count); finalize_cstate(state->linux_name, state->usage_after, state->duration_after, state->after_count); } for (j = 0; j < children[i]->pstates.size(); j++) { struct frequency *state; state = children[i]->pstates[j]; if (!state) continue; update_pstate( state->freq, state->human_name, state->time_before, state->before_count); finalize_pstate(state->freq, state->time_after, state->after_count); } } for (i = 0; i < cstates.size(); i++) { struct idle_state *state = cstates[i]; if (state->after_count == 0) { cout << "after count is 0 " << state->linux_name << "\n"; continue; } if (state->after_count != state->before_count) { cout << "count mismatch " << state->after_count << " " << state->before_count << " on cpu " << number << "\n"; continue; } state->usage_delta = (state->usage_after - state->usage_before) / state->after_count; state->duration_delta = (state->duration_after - state->duration_before) / state->after_count; } }
void cpu_linux::measurement_start(void) { ifstream file; DIR *dir; struct dirent *entry; char filename[256]; int len; unsigned int i; abstract_cpu::measurement_start(); len = sprintf(filename, "/sys/devices/system/cpu/cpu%i/cpuidle", number); dir = opendir(filename); if (!dir) return; /* For each C-state, there is a stateX directory which * contains a 'usage' and a 'time' (duration) file */ while ((entry = readdir(dir))) { char linux_name[64]; char human_name[64]; uint64_t usage = 0; uint64_t duration = 0; if (strlen(entry->d_name) < 3) continue; strcpy(linux_name, entry->d_name); strcpy(human_name, linux_name); sprintf(filename + len, "/%s/name", entry->d_name); file.open(filename, ios::in); if (file) { file.getline(human_name, 64); file.close(); } if (strcmp(human_name, "C0")==0) strcpy(human_name, _("C0 polling")); sprintf(filename + len, "/%s/usage", entry->d_name); file.open(filename, ios::in); if (file) { file >> usage; file.close(); } sprintf(filename + len, "/%s/time", entry->d_name); file.open(filename, ios::in); if (file) { file >> duration; file.close(); } update_cstate(linux_name, human_name, usage, duration, 1); } closedir(dir); last_stamp = 0; for (i = 0; i < children.size(); i++) if (children[i]) children[i]->wiggle(); sprintf(filename, "/sys/devices/system/cpu/cpu%i/cpufreq/stats/time_in_state", first_cpu); file.open(filename, ios::in); if (file) { char line[1024]; while (file) { uint64_t f; file.getline(line, 1024); f = strtoull(line, NULL, 10); account_freq(f, 0); } file.close(); } account_freq(0, 0); }