From 7cf703ceb488aaefdbf43e496e44865ead748e54 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Wed, 20 Jul 2011 15:49:55 +0000 Subject: [PATCH] added support of cpu usage monitoring --- po/Makefile.in | 6 +-- src/Makefile.am | 4 ++ src/Makefile.in | 40 ++++++++++---------- src/graph.c | 5 +++ src/lib/Makefile.am | 12 +++++- src/lib/Makefile.in | 43 ++++++++++++++++------ src/lib/cpu.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib/cpu.h | 31 ++++++++++++++++ src/lib/psensor.c | 20 +++++++++- src/lib/psensor.h | 3 ++ src/main.c | 7 ++++ src/ui_sensorlist.c | 1 + 12 files changed, 239 insertions(+), 36 deletions(-) create mode 100644 src/lib/cpu.c create mode 100644 src/lib/cpu.h diff --git a/po/Makefile.in b/po/Makefile.in index 1d3f8f1..03604dc 100644 --- a/po/Makefile.in +++ b/po/Makefile.in @@ -34,12 +34,12 @@ INSTALL_DATA = ${INSTALL} -m 644 # We use $(mkdir_p). # In automake <= 1.9.x, $(mkdir_p) is defined either as "mkdir -p --" or as # "$(mkinstalldirs)" or as "$(install_sh) -d". For these automake versions, -# ${SHELL} /home/jporsini/work/wpitchoune/svnpub/psensor/trunk/install-sh does not start with $(SHELL), so we add it. +# ${SHELL} /home/jporsini/work.local/wpitchoune.net/svnpub/psensor/trunk/install-sh does not start with $(SHELL), so we add it. # In automake >= 1.10, /bin/mkdir -p is derived from ${MKDIR_P}, which is defined # either as "/path/to/mkdir -p" or ".../install-sh -c -d". For these automake # versions, $(mkinstalldirs) and $(install_sh) are unused. -mkinstalldirs = $(SHELL) ${SHELL} /home/jporsini/work/wpitchoune/svnpub/psensor/trunk/install-sh -d -install_sh = $(SHELL) ${SHELL} /home/jporsini/work/wpitchoune/svnpub/psensor/trunk/install-sh +mkinstalldirs = $(SHELL) ${SHELL} /home/jporsini/work.local/wpitchoune.net/svnpub/psensor/trunk/install-sh -d +install_sh = $(SHELL) ${SHELL} /home/jporsini/work.local/wpitchoune.net/svnpub/psensor/trunk/install-sh MKDIR_P = /bin/mkdir -p mkdir_p = /bin/mkdir -p diff --git a/src/Makefile.am b/src/Makefile.am index bde5a54..ccea9d5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -41,6 +41,10 @@ psensor_SOURCES = \ ui_sensorlist.h ui_sensorlist.c \ ui_sensorpref.h ui_sensorpref.c +if GTOP +LIBS += $(GTOP_LIBS) +endif + if LIBNOTIFY psensor_SOURCES += ui_notify.h ui_notify.c LIBS += $(LIBNOTIFY_LIBS) diff --git a/src/Makefile.in b/src/Makefile.in index c975416..0c04299 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -37,19 +37,20 @@ host_triplet = @host@ @JSON_TRUE@am__append_1 = libpsensor_json @JSON_TRUE@@LIBMICROHTTPD_TRUE@am__append_2 = server bin_PROGRAMS = psensor$(EXEEXT) -@LIBNOTIFY_TRUE@am__append_3 = ui_notify.h ui_notify.c -@LIBNOTIFY_TRUE@am__append_4 = $(LIBNOTIFY_LIBS) -@LIBNOTIFY_TRUE@am__append_5 = $(LIBNOTIFY_CFLAGS) -@APPINDICATOR_TRUE@am__append_6 = ui_appindicator.h ui_appindicator.c -@APPINDICATOR_TRUE@am__append_7 = $(APPINDICATOR_LIBS) -@APPINDICATOR_TRUE@am__append_8 = $(APPINDICATOR_CFLAGS) -@NVIDIA_TRUE@am__append_9 = $(NVIDIA_CFLAGS) -@NVIDIA_TRUE@am__append_10 = $(NVIDIA_LIBS) -@UNITY_TRUE@am__append_11 = $(UNITY_CFLAGS) -@UNITY_TRUE@am__append_12 = unity/libpsensor_unity.a $(UNITY_LIBS) -@CURL_TRUE@@JSON_TRUE@am__append_13 = rsensor.h rsensor.c plib/url.c plib/url.h -@CURL_TRUE@@JSON_TRUE@am__append_14 = $(CURL_LIBS) $(JSON_LIBS) -@CURL_TRUE@@JSON_TRUE@am__append_15 = $(CURL_CFLAGS) $(JSON_CFLAGS) +@GTOP_TRUE@am__append_3 = $(GTOP_LIBS) +@LIBNOTIFY_TRUE@am__append_4 = ui_notify.h ui_notify.c +@LIBNOTIFY_TRUE@am__append_5 = $(LIBNOTIFY_LIBS) +@LIBNOTIFY_TRUE@am__append_6 = $(LIBNOTIFY_CFLAGS) +@APPINDICATOR_TRUE@am__append_7 = ui_appindicator.h ui_appindicator.c +@APPINDICATOR_TRUE@am__append_8 = $(APPINDICATOR_LIBS) +@APPINDICATOR_TRUE@am__append_9 = $(APPINDICATOR_CFLAGS) +@NVIDIA_TRUE@am__append_10 = $(NVIDIA_CFLAGS) +@NVIDIA_TRUE@am__append_11 = $(NVIDIA_LIBS) +@UNITY_TRUE@am__append_12 = $(UNITY_CFLAGS) +@UNITY_TRUE@am__append_13 = unity/libpsensor_unity.a $(UNITY_LIBS) +@CURL_TRUE@@JSON_TRUE@am__append_14 = rsensor.h rsensor.c plib/url.c plib/url.h +@CURL_TRUE@@JSON_TRUE@am__append_15 = $(CURL_LIBS) $(JSON_LIBS) +@CURL_TRUE@@JSON_TRUE@am__append_16 = $(CURL_CFLAGS) $(JSON_CFLAGS) subdir = src DIST_COMMON = $(dist_man_MANS) $(srcdir)/Makefile.am \ $(srcdir)/Makefile.in @@ -208,8 +209,9 @@ LIBNOTIFY_CFLAGS = @LIBNOTIFY_CFLAGS@ LIBNOTIFY_LIBS = @LIBNOTIFY_LIBS@ LIBOBJS = @LIBOBJS@ LIBS = plib/libplib.a lib/libpsensor.a $(GTK_LIBS) $(GCONF_LIBS) \ - $(SENSORS_LIBS) $(am__append_4) $(am__append_7) \ - $(am__append_10) $(am__append_12) $(am__append_14) + $(SENSORS_LIBS) $(am__append_3) $(am__append_5) \ + $(am__append_8) $(am__append_11) $(am__append_13) \ + $(am__append_15) LTLIBICONV = @LTLIBICONV@ LTLIBINTL = @LTLIBINTL@ LTLIBOBJS = @LTLIBOBJS@ @@ -306,13 +308,13 @@ AM_CPPFLAGS = -Wall -pedantic -Werror \ -DDEFAULT_WWW_DIR=\""$(pkgdatadir)/www"\" \ -I$(top_srcdir)/src/lib -I$(top_srcdir)/src/unity \ $(GTK_CFLAGS) $(GCONF_CFLAGS) $(SENSORS_CFLAGS) \ - $(am__append_5) $(am__append_8) $(am__append_9) \ - $(am__append_11) $(am__append_15) + $(am__append_6) $(am__append_9) $(am__append_10) \ + $(am__append_12) $(am__append_16) psensor_SOURCES = compat.h cfg.h cfg.c graph.h graph.c main.c ui.h \ ui.c ui_color.h ui_color.c ui_graph.h ui_graph.c ui_pref.h \ ui_pref.c ui_sensorlist.h ui_sensorlist.c ui_sensorpref.h \ - ui_sensorpref.c $(am__append_3) $(am__append_6) \ - $(am__append_13) + ui_sensorpref.c $(am__append_4) $(am__append_7) \ + $(am__append_14) dist_man_MANS = psensor.1 EXTRA_DIST = description.txt all: all-recursive diff --git a/src/graph.c b/src/graph.c index db6f7a3..988ea4a 100644 --- a/src/graph.c +++ b/src/graph.c @@ -300,6 +300,11 @@ graph_update(struct psensor **sensors, if (is_fan_type(s->type)) { min = min_rpm; max = max_rpm; + } else if (s->type & SENSOR_TYPE_CPU_USAGE) { + min = 0; + max = get_max_value + (sensors, + SENSOR_TYPE_CPU_USAGE); } else { min = mint; max = maxt; diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 32ea765..a319b98 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -4,6 +4,7 @@ libpsensor_a_CFLAGS = -Werror libpsensor_a_SOURCES = \ amd.h \ + cpu.h \ measure.h measure.c \ color.h color.c \ psensor.h psensor.c\ @@ -15,14 +16,23 @@ if NVIDIA libpsensor_a_SOURCES += nvidia.c endif +AM_CPPFLAGS= + if LIBATIADL LIBS += $(LIBATIADL_LIBS) -AM_CPPFLAGS = $(LIBATIADL_CFLAGS) +AM_CPPFLAGS += $(LIBATIADL_CFLAGS) libpsensor_a_SOURCES += amd.c else libpsensor_a_CFLAGS += -pedantic endif +if GTOP +libpsensor_a_SOURCES += cpu.c +LIBS += $(GTOP_LIBS) +AM_CPPFLAGS += $(GTOP_CFLAGS) +endif + EXTRA_DIST=$(libpsensor_a_SOURCES) \ amd.c \ + cpu.c \ nvidia.c \ No newline at end of file diff --git a/src/lib/Makefile.in b/src/lib/Makefile.in index 59b1b8c..e5721d2 100644 --- a/src/lib/Makefile.in +++ b/src/lib/Makefile.in @@ -36,8 +36,12 @@ build_triplet = @build@ host_triplet = @host@ @NVIDIA_TRUE@am__append_1 = nvidia.c @LIBATIADL_TRUE@am__append_2 = $(LIBATIADL_LIBS) -@LIBATIADL_TRUE@am__append_3 = amd.c -@LIBATIADL_FALSE@am__append_4 = -pedantic +@LIBATIADL_TRUE@am__append_3 = $(LIBATIADL_CFLAGS) +@LIBATIADL_TRUE@am__append_4 = amd.c +@LIBATIADL_FALSE@am__append_5 = -pedantic +@GTOP_TRUE@am__append_6 = cpu.c +@GTOP_TRUE@am__append_7 = $(GTOP_LIBS) +@GTOP_TRUE@am__append_8 = $(GTOP_CFLAGS) subdir = src/lib DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -53,15 +57,16 @@ AR = ar ARFLAGS = cru libpsensor_a_AR = $(AR) $(ARFLAGS) libpsensor_a_LIBADD = -am__libpsensor_a_SOURCES_DIST = amd.h measure.h measure.c color.h \ - color.c psensor.h psensor.c hdd.h hdd.c nvidia.h lmsensor.h \ - lmsensor.c nvidia.c amd.c +am__libpsensor_a_SOURCES_DIST = amd.h cpu.h measure.h measure.c \ + color.h color.c psensor.h psensor.c hdd.h hdd.c nvidia.h \ + lmsensor.h lmsensor.c nvidia.c amd.c cpu.c @NVIDIA_TRUE@am__objects_1 = libpsensor_a-nvidia.$(OBJEXT) @LIBATIADL_TRUE@am__objects_2 = libpsensor_a-amd.$(OBJEXT) +@GTOP_TRUE@am__objects_3 = libpsensor_a-cpu.$(OBJEXT) am_libpsensor_a_OBJECTS = libpsensor_a-measure.$(OBJEXT) \ libpsensor_a-color.$(OBJEXT) libpsensor_a-psensor.$(OBJEXT) \ libpsensor_a-hdd.$(OBJEXT) libpsensor_a-lmsensor.$(OBJEXT) \ - $(am__objects_1) $(am__objects_2) + $(am__objects_1) $(am__objects_2) $(am__objects_3) libpsensor_a_OBJECTS = $(am_libpsensor_a_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -129,7 +134,7 @@ LIBMICROHTTPD_LIBS = @LIBMICROHTTPD_LIBS@ LIBNOTIFY_CFLAGS = @LIBNOTIFY_CFLAGS@ LIBNOTIFY_LIBS = @LIBNOTIFY_LIBS@ LIBOBJS = @LIBOBJS@ -LIBS = @LIBS@ $(am__append_2) +LIBS = @LIBS@ $(am__append_2) $(am__append_7) LTLIBICONV = @LTLIBICONV@ LTLIBINTL = @LTLIBINTL@ LTLIBOBJS = @LTLIBOBJS@ @@ -221,13 +226,14 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ noinst_LIBRARIES = libpsensor.a -libpsensor_a_CFLAGS = -Werror $(am__append_4) -libpsensor_a_SOURCES = amd.h measure.h measure.c color.h color.c \ +libpsensor_a_CFLAGS = -Werror $(am__append_5) +libpsensor_a_SOURCES = amd.h cpu.h measure.h measure.c color.h color.c \ psensor.h psensor.c hdd.h hdd.c nvidia.h lmsensor.h lmsensor.c \ - $(am__append_1) $(am__append_3) -@LIBATIADL_TRUE@AM_CPPFLAGS = $(LIBATIADL_CFLAGS) + $(am__append_1) $(am__append_4) $(am__append_6) +AM_CPPFLAGS = $(am__append_3) $(am__append_8) EXTRA_DIST = $(libpsensor_a_SOURCES) \ amd.c \ + cpu.c \ nvidia.c all: all-am @@ -280,6 +286,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpsensor_a-amd.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpsensor_a-color.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpsensor_a-cpu.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpsensor_a-hdd.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpsensor_a-lmsensor.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpsensor_a-measure.Po@am__quote@ @@ -398,6 +405,20 @@ libpsensor_a-amd.obj: amd.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpsensor_a_CFLAGS) $(CFLAGS) -c -o libpsensor_a-amd.obj `if test -f 'amd.c'; then $(CYGPATH_W) 'amd.c'; else $(CYGPATH_W) '$(srcdir)/amd.c'; fi` +libpsensor_a-cpu.o: cpu.c +@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpsensor_a_CFLAGS) $(CFLAGS) -MT libpsensor_a-cpu.o -MD -MP -MF $(DEPDIR)/libpsensor_a-cpu.Tpo -c -o libpsensor_a-cpu.o `test -f 'cpu.c' || echo '$(srcdir)/'`cpu.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpsensor_a-cpu.Tpo $(DEPDIR)/libpsensor_a-cpu.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='cpu.c' object='libpsensor_a-cpu.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpsensor_a_CFLAGS) $(CFLAGS) -c -o libpsensor_a-cpu.o `test -f 'cpu.c' || echo '$(srcdir)/'`cpu.c + +libpsensor_a-cpu.obj: cpu.c +@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpsensor_a_CFLAGS) $(CFLAGS) -MT libpsensor_a-cpu.obj -MD -MP -MF $(DEPDIR)/libpsensor_a-cpu.Tpo -c -o libpsensor_a-cpu.obj `if test -f 'cpu.c'; then $(CYGPATH_W) 'cpu.c'; else $(CYGPATH_W) '$(srcdir)/cpu.c'; fi` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpsensor_a-cpu.Tpo $(DEPDIR)/libpsensor_a-cpu.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='cpu.c' object='libpsensor_a-cpu.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpsensor_a_CFLAGS) $(CFLAGS) -c -o libpsensor_a-cpu.obj `if test -f 'cpu.c'; then $(CYGPATH_W) 'cpu.c'; else $(CYGPATH_W) '$(srcdir)/cpu.c'; fi` + ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ diff --git a/src/lib/cpu.c b/src/lib/cpu.c new file mode 100644 index 0000000..e6ed3f3 --- /dev/null +++ b/src/lib/cpu.c @@ -0,0 +1,103 @@ +/* + Copyright (C) 2010-2011 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 published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA +*/ + +#include +#include +#define _(str) gettext(str) + +#include + +#include + +#include "cpu.h" + +static glibtop_cpu *cpu; +static float last_used; +static float last_total; + +static struct psensor *create_sensor(int measures_len) +{ + char *label; + int type; + char *id; + struct psensor *psensor; + + id = strdup("cpu usage"); + label = strdup("cpu usage"); + type = SENSOR_TYPE_CPU_USAGE; + + psensor = psensor_create(id, label, type, measures_len); + + return psensor; +} + +struct psensor * * +cpu_psensor_list_add(struct psensor **sensors, int measures_len) +{ + struct psensor *s; + + s = create_sensor(measures_len); + + return psensor_list_add(sensors, s); +} + +static double get_usage() +{ + 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); + + used = cpu->user + cpu->nice + cpu->sys; + + dt = cpu->total - last_total; + + if (dt) + cpu_rate = 100 * (used - last_used) / dt; + + last_used = used; + last_total = cpu->total; + + return cpu_rate; +} + +void cpu_psensor_list_update(struct psensor **sensors) +{ + struct psensor **ss, *s; + + ss = sensors; + while (*ss) { + s = *ss; + + if (s->type == SENSOR_TYPE_CPU_USAGE) + psensor_set_current_value(s, get_usage()); + + ss++; + } +} + +void cpu_cleanup() +{ + if (cpu) + free(cpu); +} diff --git a/src/lib/cpu.h b/src/lib/cpu.h new file mode 100644 index 0000000..3381b0e --- /dev/null +++ b/src/lib/cpu.h @@ -0,0 +1,31 @@ +/* + Copyright (C) 2010-2011 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 published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA +*/ + +#ifndef _PSENSOR_CPU_H_ +#define _PSENSOR_CPU_H_ + +#include "psensor.h" + +void cpu_psensor_list_update(struct psensor **sensors); +struct psensor **cpu_psensor_list_add(struct psensor **sensors, + int values_max_len); + +void cpu_cleanup(); + +#endif diff --git a/src/lib/psensor.c b/src/lib/psensor.c index da57f09..8d7b37e 100644 --- a/src/lib/psensor.c +++ b/src/lib/psensor.c @@ -28,6 +28,11 @@ #include "psensor.h" #include "lmsensor.h" +#ifdef HAVE_GTOP +#include "cpu.h" +#endif + + struct psensor *psensor_create(char *id, char *name, unsigned int type, int values_max_length) { @@ -204,6 +209,8 @@ char *psensor_value_to_string(unsigned int type, double value) if (is_temp_type(type)) unit = "C"; + else if (type & SENSOR_TYPE_CPU_USAGE) + unit = "%"; else unit = ""; @@ -298,7 +305,7 @@ double get_min_value(struct psensor **sensors, int type) Returns the maximal value of a given 'type' (SENSOR_TYPE_TEMP or SENSOR_TYPE_FAN) */ -static double get_max_value(struct psensor **sensors, int type) +double get_max_value(struct psensor **sensors, int type) { double m = UNKNOWN_DBL_VALUE; struct psensor **s = sensors; @@ -375,7 +382,6 @@ struct psensor **get_all_sensors(int values_max_length) psensors = lmsensor_psensor_list_add(NULL, values_max_length); tmp_psensors = hdd_psensor_list_add(psensors, values_max_length); - if (tmp_psensors != psensors) { free(psensors); psensors = tmp_psensors; @@ -412,6 +418,9 @@ const char *psensor_type_to_str(unsigned int type) if (type & SENSOR_TYPE_HDD_TEMP) return "HDD Temperature"; + if (type & SENSOR_TYPE_CPU_USAGE) + return "CPU Usage"; + return "N/A"; /* should not be possible */ } @@ -424,6 +433,9 @@ const char *psensor_type_to_unit_str(unsigned int type) if (type & SENSOR_TYPE_FAN) return _("RPM"); + if (type & SENSOR_TYPE_CPU_USAGE) + return _("%"); + return "N/A"; } @@ -431,6 +443,10 @@ void psensor_list_update_measures(struct psensor **sensors) { lmsensor_psensor_list_update(sensors); +#ifdef HAVE_GTOP + cpu_psensor_list_update(sensors); +#endif + if (psensor_list_contains_type(sensors, SENSOR_TYPE_HDD_TEMP)) hdd_psensor_list_update(sensors); } diff --git a/src/lib/psensor.h b/src/lib/psensor.h index 49e86d5..099556f 100644 --- a/src/lib/psensor.h +++ b/src/lib/psensor.h @@ -34,6 +34,7 @@ enum psensor_type { SENSOR_TYPE_LMSENSOR = 0x0100, SENSOR_TYPE_NVIDIA_TEMP = 0x0200 | SENSOR_TYPE_TEMP, SENSOR_TYPE_HDD_TEMP = 0x0400 | SENSOR_TYPE_TEMP, + SENSOR_TYPE_CPU_USAGE = 0x0800, SENSOR_TYPE_AMD = 0x1000, SENSOR_TYPE_AMD_TEMP = SENSOR_TYPE_AMD | SENSOR_TYPE_TEMP, @@ -173,4 +174,6 @@ void psensor_init(); void psensor_cleanup(); +double get_max_value(struct psensor **sensors, int type); + #endif diff --git a/src/main.c b/src/main.c index 3a55482..5ee6c96 100644 --- a/src/main.c +++ b/src/main.c @@ -63,6 +63,10 @@ #include "ui_notify.h" #endif +#ifdef HAVE_GTOP +#include "cpu.h" +#endif + #include "compat.h" static const char *program_name; @@ -363,6 +367,9 @@ int main(int argc, char **argv) #ifdef HAVE_LIBATIADL ui.sensors = amd_psensor_list_add(ui.sensors, 600); #endif +#ifdef HAVE_GTOP + ui.sensors = cpu_psensor_list_add(ui.sensors, 600); +#endif } associate_preferences(ui.sensors); diff --git a/src/ui_sensorlist.c b/src/ui_sensorlist.c index ad49b22..a29a1b6 100644 --- a/src/ui_sensorlist.c +++ b/src/ui_sensorlist.c @@ -73,6 +73,7 @@ void ui_sensorlist_update(struct ui_psensor *ui) str = psensor_value_to_string(s->type, s->measures[s->values_max_length - 1].value.d_num); + gtk_list_store_set(GTK_LIST_STORE(model), &iter, COL_TEMP, str, -1); free(str); -- 2.7.4