Пример #1
0
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);

    }
Пример #2
0
interrupt::interrupt(const char *_handler, int _number) : power_consumer()
{
	char buf[128];
	running_since = 0;
	number = _number;
	pt_strcpy(handler, _handler);
	raw_count = 0;
	snprintf(desc, sizeof(desc), "[%i] %s", number, pretty_print(handler, buf, 128));
}
Пример #3
0
class interrupt * find_create_interrupt(const char *_handler, int nr, int cpu)
{
	char handler[64];
	unsigned int i;
	class interrupt *new_irq;

	pt_strcpy(handler, _handler);
	if (strcmp(handler, "timer")==0)
		sprintf(handler, "timer/%i", cpu);


	for (i = 0; i < all_interrupts.size(); i++) {
		if (all_interrupts[i] && all_interrupts[i]->number == nr && strcmp(handler, all_interrupts[i]->handler) == 0)
			return all_interrupts[i];
	}

	new_irq = new class interrupt(handler, nr);
	all_interrupts.push_back(new_irq);
	return new_irq;
}
Пример #4
0
sysfs_power_meter::sysfs_power_meter(const char *power_supply_name)
{
	rate = 0.0;
	capacity = 0.0;
	pt_strcpy(name, power_supply_name);
}