/*
- * Copyright (C) 2010-2012 jeanfi@gmail.com
+ * Copyright (C) 2010-2014 jeanfi@gmail.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
#include "cpu.h"
-static glibtop_cpu *cpu;
static float last_used;
static float last_total;
id = strdup("cpu usage");
label = strdup("cpu usage");
- type = SENSOR_TYPE_CPU_USAGE;
+ type = SENSOR_TYPE_GTOP | SENSOR_TYPE_CPU_USAGE;
- psensor = psensor_create(id, label, strdup("CPU"), type, measures_len);
+ psensor = psensor_create(id,
+ label,
+ strdup(_("CPU")),
+ type,
+ measures_len);
return psensor;
}
static double get_usage()
{
+ glibtop_cpu cpu;
unsigned long int used = 0;
unsigned long int dt;
double cpu_rate = UNKNOWN_DBL_VALUE;
- if (!cpu)
- cpu = malloc(sizeof(glibtop_cpu));
+ glibtop_get_cpu(&cpu);
- glibtop_get_cpu(cpu);
+ used = cpu.user + cpu.nice + cpu.sys;
- used = cpu->user + cpu->nice + cpu->sys;
-
- dt = cpu->total - last_total;
+ dt = cpu.total - last_total;
if (dt)
cpu_rate = 100 * (used - last_used) / dt;
last_used = used;
- last_total = cpu->total;
+ last_total = cpu.total;
return cpu_rate;
}
void cpu_psensor_list_update(struct psensor **sensors)
{
- struct psensor **ss, *s;
+ struct psensor *s;
- ss = sensors;
- while (*ss) {
- s = *ss;
+ while (*sensors) {
+ s = *sensors;
- if (s->type == SENSOR_TYPE_CPU_USAGE)
+ if (s->type & SENSOR_TYPE_GTOP
+ && s->type & SENSOR_TYPE_CPU_USAGE)
cpu_usage_sensor_update(s);
- ss++;
+ sensors++;
}
}
-
-void cpu_cleanup()
-{
- if (cpu)
- free(cpu);
-}