コード例 #1
0
ファイル: cpuinfo.c プロジェクト: serghei/kde3-kdebase
void initCpuInfo(struct SensorModul *sm)
{
    CpuInfoSM = sm;

    if(updateCpuInfo() < 0)
        return;

    processCpuInfo();
}
コード例 #2
0
ファイル: cpu.c プロジェクト: serghei/kde3-kdebase
void initCpuInfo(struct SensorModul *sm)
{
    /* Total CPU load */
    registerMonitor("cpu/user", "integer", printCPUUser, printCPUUserInfo, sm);
    registerMonitor("cpu/nice", "integer", printCPUNice, printCPUNiceInfo, sm);
    registerMonitor("cpu/sys", "integer", printCPUSys, printCPUSysInfo, sm);
    registerMonitor("cpu/idle", "integer", printCPUIdle, printCPUIdleInfo, sm);
    registerMonitor("cpu/interrupt", "integer", printCPUInterrupt, printCPUInterruptInfo, sm);

    updateCpuInfo();
}
コード例 #3
0
ファイル: CPU.c プロジェクト: serghei/kde3-kdebase
void initCpuInfo(struct SensorModul *sm)
{
    /* Total CPU load */
    registerMonitor("cpu/user", "integer", printCPUUser, printCPUUserInfo, sm);
    registerMonitor("cpu/nice", "integer", printCPUNice, printCPUNiceInfo, sm);
    registerMonitor("cpu/sys", "integer", printCPUSys, printCPUSysInfo, sm);
    registerMonitor("cpu/idle", "integer", printCPUIdle, printCPUIdleInfo, sm);
    kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open");
    kvm_nlist(kd, my_nlist);
    cp_time_offset = my_nlist[0].n_value;

    updateCpuInfo();
}
コード例 #4
0
ファイル: cpuinfo.c プロジェクト: KDE/kde-workspace
void
initCpuInfo(struct SensorModul* sm)
{
    size_t len;
    int id;
    char name[SYSCTL_ID_LEN];
    int minfreq, maxfreq;

    len = sizeof(cpus);
    /* XXX: this is a guess */
    sysctlbyname("kern.smp.active", &cpus, &len, NULL, 0);
    /* NOTE: cpus may be 0, which implies 1 */
    cpus = cpus ? cpus : 1;

    len = sizeof(cores);
    sysctlbyname("kern.smp.cpus", &cores, &len, NULL, 0);

    len = sizeof(maxcpus);
    sysctlbyname("kern.smp.maxcpus", &maxcpus, &len, NULL, 0);

    /* Core/process count */
    registerMonitor("system/processors", "integer", printNumCpus, printNumCpusInfo, sm);
    registerMonitor("system/cores", "integer", printNumCores, printNumCoresInfo, sm);

    /*
     * CPU Loads
     */
    if ((cp_time = malloc(sizeof(long) * CPUSTATES * (cores * 4 + 1))) == NULL) {
        log_error("out of memory for cp_time");
        return;
    }
    cp_old = &cp_time[cores];
    cp_diff = &cp_old[cores];
    cpu_states = &cp_diff[cores];

    /* Total CPU load */
    registerMonitor("cpu/system/user", "float", printCPUUser, printCPUUserInfo, sm);
    registerMonitor("cpu/system/nice", "float", printCPUNice, printCPUNiceInfo, sm);
    registerMonitor("cpu/system/sys", "float", printCPUSys, printCPUSysInfo, sm);
    registerMonitor("cpu/system/TotalLoad", "float", printCPUTotalLoad, printCPUTotalLoadInfo, sm);
    registerMonitor("cpu/system/intr", "float", printCPUIntr, printCPUIntrInfo, sm);
    registerMonitor("cpu/system/idle", "float", printCPUIdle, printCPUIdleInfo, sm);

    /* Monitor names changed from kde3 => kde4. Remain compatible with legacy requests when possible. */
    registerLegacyMonitor("cpu/user", "float", printCPUUser, printCPUUserInfo, sm);
    registerLegacyMonitor("cpu/nice", "float", printCPUNice, printCPUNiceInfo, sm);
    registerLegacyMonitor("cpu/sys", "float", printCPUSys, printCPUSysInfo, sm);
    registerLegacyMonitor("cpu/idle", "float", printCPUIdle, printCPUIdleInfo, sm);

    for (id = 0; id < cores; ++id) {
        snprintf(name, SYSCTL_ID_LEN, "cpu/cpu%d/user", id);
        registerMonitor(name, "float", printCPUxUser, printCPUxUserInfo, sm);
        snprintf(name, SYSCTL_ID_LEN, "cpu/cpu%d/nice", id);
        registerMonitor(name, "float", printCPUxNice, printCPUxNiceInfo, sm);
        snprintf(name, SYSCTL_ID_LEN, "cpu/cpu%d/sys", id);
        registerMonitor(name, "float", printCPUxSys, printCPUxSysInfo, sm);
        snprintf(name, SYSCTL_ID_LEN, "cpu/cpu%d/TotalLoad", id);
        registerMonitor(name, "float", printCPUxTotalLoad, printCPUxTotalLoadInfo, sm);
        snprintf(name, SYSCTL_ID_LEN, "cpu/cpu%d/intr", id);
        registerMonitor(name, "float", printCPUxIntr, printCPUxIntrInfo, sm);
        snprintf(name, SYSCTL_ID_LEN, "cpu/cpu%d/idle", id);
        registerMonitor(name, "float", printCPUxIdle, printCPUxIdleInfo, sm);
    }

    /*
     * CPU frequencies
     */
    if ((freq = malloc(sizeof(int) * 3 * (cores + 1))) == NULL) {
        log_error("out of memory for freq");
        return;
    }

    registerMonitor("cpu/system/AverageClock", "float", printCPUClock, printCPUClockInfo, sm);
    for (id = 0; id < cores; ++id) {
        len = sizeof(int);
        snprintf(name, SYSCTL_ID_LEN, "dev.cpu.%d.freq", id);
        if (!sysctlbyname(name, &freq[id][0], &len, NULL, 0)) {
            get_mmfreq(id, &freq[id][1], &freq[id][2]);
            snprintf(name, SYSCTL_ID_LEN, "cpu/cpu%d/clock", id);
            registerMonitor(name, "integer", printCPUxClock, printCPUxClockInfo, sm);
        } else {
            freq[id][0] = -1;
            freq[id][1] = 0;
            freq[id][2] = 0;
        }
    }

    minfreq = freq[0][1];
    maxfreq = freq[0][2];
    for (id = 1; id < cores; ++id)
        if (freq[id][0] != -1) {
            minfreq = minfreq > freq[id][1] ? freq[id][1] : minfreq;
            maxfreq = maxfreq < freq[id][2] ? freq[id][2] : maxfreq;
        }
    freq[cores][1] = minfreq;
    freq[cores][2] = maxfreq;

    /*
     * CPU temperature
     */
    if ((temp = malloc(sizeof(int) * (cores + 1))) == NULL) {
        log_error("out of memory for temp");
        return;
    }
    registerMonitor("cpu/system/AverageTemperature", "float", printCPUTemperature, printCPUTemperatureInfo, sm);
    for (id = 0; id < cores; ++id) {
        len = sizeof(int);
        snprintf(name, SYSCTL_ID_LEN, "dev.cpu.%d.temperature", id);
        if (!sysctlbyname(name, &temp[id], &len, NULL, 0)) {
            snprintf(name, SYSCTL_ID_LEN, "cpu/cpu%d/temperature", id);
            registerMonitor(name, "float", printCPUxTemperature, printCPUxTemperatureInfo, sm);
        } else
            temp[id] = -1;
    }

    updateCpuInfo();
}