]> granicus.if.org Git - sysstat/commitdiff
Don't link sysstat's commands with sensors library if not needed.
authorSebastien Godard <sysstat@orange.fr>
Sun, 6 Mar 2011 19:19:51 +0000 (20:19 +0100)
committerSebastien Godard <sysstat@orange.fr>
Sun, 6 Mar 2011 19:19:51 +0000 (20:19 +0100)
Sebastien,

I'm forwarding a bug report I've got today. The submitter is right. The
only binary that actually needs sensors is sadc. but all the remaining
binaries are linked with the  library, and it's not easy to change it.

I was trying to find some way to fix the issue e.g. by using the
--as-needed linker option, but this doesn't worked well (even after
changing ordering of linking). Finally I've came up with an idea of
splitting rd_stats.c into two parts - one that requires sensors and the
other one that doesn't.

I'm attaching some proof of concept patch just to show the idea. It uses
preprocessor macro to compile a tiny version of rd_stats.c that is than
linked with all binaries except for sadc. I don't think the patch is
ready to be applied b you as is. It would be much better to manually
split the rd_stats.c file into two parts, and than make configure not to
add -lsensors to CFLAGS, but put -lsensors in some autoconf variable
that would be added to sadc's LFLAGS. Could you please look at it and
possbly make an appropriate changes for the next version of sysstat?

Thanks,
robert

------ Wiadomosc oryginalna ------
Temat: Bug#612571: sysstat: iostat links libsensors4 with no need
Odeslano-Data: Wed, 09 Feb 2011 09:18:01 +0000, Wed, 09 Feb 2011
09:18:04 +0000
Odeslano-Od: Mario 'BitKoenig' Holbe <Mario.Holbe@TU-Ilmenau.DE>
Odeslano-Do: debian-bugs-dist@lists.debian.org
Odeslano-Kopia: Robert Luberda <robert@debian.org>
Data: Wed, 9 Feb 2011 10:15:31 +0100
Nadawca: Mario 'BitKoenig' Holbe <Mario.Holbe@TU-Ilmenau.DE>
Odpowiedz-Do: Mario 'BitKoenig' Holbe <Mario.Holbe@TU-Ilmenau.DE>,
612571@bugs.debian.org
Adresat: submit@bugs.debian.org

Package: sysstat
Version: 9.1.7-2

Hello,

iostat from sysstat 9.1.7-2 links /usr/lib/libsensors.so.4.
The manual page doesn't reveal any new functions that could explain this
and according to ldd libsensors isn't used:

$ ldd -u /usr/bin/iostat
Unused direct dependencies:

        /usr/lib/libsensors.so.4

regards
   Mario

CHANGES
Makefile.in
activity.c
configure
configure.in
rd_sensors.c [new file with mode: 0644]
rd_sensors.h [new file with mode: 0644]
rd_stats.c
rd_stats.h
sa.h
sa_wrap.c

diff --git a/CHANGES b/CHANGES
index ce33abf7bf485e481b02ef6daf872d8291241dc9..0bf21ba1b1aa37ddfc0b85e110e5c17bbbf30bf4 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -10,6 +10,8 @@ xxxx/xx/xx: Version 10.0.0 - Sebastien Godard (sysstat <at> orange.fr)
        * [Jan Kaluza]: Added --debuginfo option to cifsiostat and
          nfsiostat.
        * cifsiostat and nfsiostat manual pages updated.
+       * Don't link sysstat's commands with sensors library if not
+         needed [DEBIAN Bug#612571].
        * [Adam Heath]: iostat incorrectly mapped device-mapper IDs
          greater than 256. This is now fixed [DEBIAN Bug#614397].
        * Sysstat's commands option -V now displays the version number
index 0a767d1d5831f2236a55f5c30c9ee2590e048d80..24e6e66a812396c5837314ffe6da6501e2a342dc 100644 (file)
@@ -23,6 +23,14 @@ INSTALL = @INSTALL@
 INSTALL_DATA = @INSTALL_DATA@
 INSTALL_BIN = @INSTALL_BIN@
 
+HAVE_SENSORS = @HAVE_SENSORS@
+LFSENSORS =
+DFSENSORS =
+ifeq ($(HAVE_SENSORS),y)
+LFSENSORS = @LFSENSORS@
+DFSENSORS = @DFSENSORS@
+endif
+
 # Directories
 ifndef PREFIX
 PREFIX = @prefix@
@@ -65,6 +73,7 @@ CFLAGS = @CFLAGS@ -Wall -Wstrict-prototypes -pipe -O2
 DFLAGS = @DFLAGS@
 LFLAGS =  -s
 DFLAGS += -DSA_DIR=\"$(SA_DIR)\" -DSADC_PATH=\"$(SADC_PATH)\"
+DFLAGS += $(DFSENSORS)
 
 # Commands
 ifndef MSGFMT
@@ -155,7 +164,7 @@ sa_common.o: sa_common.c sa.h common.h ioconf.h sysconfig.h rd_stats.h
 
 ioconf.o: ioconf.c ioconf.h common.h sysconfig.h
 
-act_sadc.o: activity.c sa.h rd_stats.h
+act_sadc.o: activity.c sa.h rd_stats.h rd_sensors.h
        $(CC) -o $@ -c $(CFLAGS) -DSOURCE_SADC $(DFLAGS) $<
 
 act_sar.o: activity.c sa.h pr_stats.h
@@ -166,13 +175,15 @@ act_sadf.o: activity.c sa.h rndr_stats.h xml_stats.h
 
 rd_stats.o: rd_stats.c common.h rd_stats.h ioconf.h sysconfig.h
 
+rd_sensors.o: rd_sensors.c common.h rd_sensors.h sysconfig.h
+
 pr_stats.o: pr_stats.c sa.h ioconf.h sysconfig.h pr_stats.h
 
 rndr_stats.o: rndr_stats.c sa.h ioconf.h sysconfig.h rndr_stats.h
 
 xml_stats.o: xml_stats.c sa.h ioconf.h sysconfig.h xml_stats.h
 
-sa_wrap.o: sa_wrap.c sa.h rd_stats.h
+sa_wrap.o: sa_wrap.c sa.h rd_stats.h rd_sensors.h
 
 # Explicit rules needed to prevent possible file corruption
 # when using parallel execution.
@@ -181,9 +192,12 @@ libsyscom.a: common.o ioconf.o
 
 librdstats.a: librdstats.a(rd_stats.o)
 
-sadc.o: sadc.c sa.h version.h common.h ioconf.h sysconfig.h rd_stats.h
+librdsensors.a: librdsensors.a(rd_sensors.o)
+
+sadc.o: sadc.c sa.h version.h common.h ioconf.h sysconfig.h rd_stats.h rd_sensors.h
 
-sadc: sadc.o act_sadc.o sa_wrap.o sa_common.o librdstats.a libsyscom.a
+sadc: LFLAGS += $(LFSENSORS)
+sadc: sadc.o act_sadc.o sa_wrap.o sa_common.o librdstats.a librdsensors.a libsyscom.a
 
 sar.o: sar.c sa.h version.h common.h ioconf.h pr_stats.h sysconfig.h
 
index 64fcc97ce5ea3376b94297b420a7e38b9ab9bf18..7f276c47b7c60a598caad38d8e7817f234f5031a 100644 (file)
@@ -23,6 +23,7 @@
 
 #ifdef SOURCE_SADC
 #include "rd_stats.h"
+#include "rd_sensors.h"
 #endif
 
 #ifdef SOURCE_SAR
index 97cca303a7a651cc2cacbedea29c4fc7a767fd14..35050ec632cc09c9a80a4b426a975a697e312da5 100755 (executable)
--- a/configure
+++ b/configure
@@ -672,6 +672,8 @@ INITD_DIR
 INIT_DIR
 RC_DIR
 rcdir
+DFSENSORS
+LFSENSORS
 HAVE_SENSORS
 PATH_CHKCONFIG
 PATH_CP
@@ -3677,6 +3679,8 @@ $as_echo "no, using $LN_S" >&6; }
 fi
 
 
+DFLAGS=""
+
 # Extract the first word of "chmod", so it can be a program name with args.
 set dummy chmod; ac_word=$2
 { $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
@@ -6812,18 +6816,17 @@ else
 fi
 
 if test $SENSORS != "yes"; then
-   CFSENSORS=""
-   DFSENSORS=""
+   HAVE_SENSORS="n"
 else
-   CFSENSORS="-lsensors"
-   DFSENSORS="-DHAVE_SENSORS"
+   HAVE_SENSORS="y"
 fi
 { $as_echo "$as_me:$LINENO: result: $SENSORS" >&5
 $as_echo "$SENSORS" >&6; }
 
 # Check for lm_sensors
-HAVE_SENSORS=no
-DFLAGS=""
+SENSORS=no
+LFSENSORS=""
+DFSENSORS=""
 { $as_echo "$as_me:$LINENO: checking for sensors_get_detected_chips in -lsensors" >&5
 $as_echo_n "checking for sensors_get_detected_chips in -lsensors... " >&6; }
 if test "${ac_cv_lib_sensors_sensors_get_detected_chips+set}" = set; then
@@ -6890,7 +6893,9 @@ fi
 { $as_echo "$as_me:$LINENO: result: $ac_cv_lib_sensors_sensors_get_detected_chips" >&5
 $as_echo "$ac_cv_lib_sensors_sensors_get_detected_chips" >&6; }
 if test "x$ac_cv_lib_sensors_sensors_get_detected_chips" = x""yes; then
-  CFLAGS="${CFLAGS} ${CFSENSORS}"
+  LFSENSORS="-lsensors"
+else
+  HAVE_SENSORS="n"
 fi
 
 { $as_echo "$as_me:$LINENO: checking for sensors lib" >&5
@@ -6930,17 +6935,19 @@ $as_echo "$ac_try_echo") >&5
         test -z "$ac_c_werror_flag" ||
         test ! -s conftest.err
        } && test -s conftest.$ac_objext; then
-  HAVE_SENSORS=yes; DFLAGS="${DFLAGS} ${DFSENSORS}"
+  SENSORS=yes; DFSENSORS="-DHAVE_SENSORS"
 else
   $as_echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-       HAVE_SENSORS=no
+       HAVE_SENSORS="n"; SENSORS=no
 fi
 
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ $as_echo "$as_me:$LINENO: result: $HAVE_SENSORS" >&5
-$as_echo "$HAVE_SENSORS" >&6; }
+{ $as_echo "$as_me:$LINENO: result: $SENSORS" >&5
+$as_echo "$SENSORS" >&6; }
+
+
 
 
 echo .
index d8f52cb15446151aff0c0681f5cdb1ddb4188aa6..72bb9546638ecd2186bfe269d64bb074f1f55692 100644 (file)
@@ -21,6 +21,8 @@ AC_PROG_CC
 AC_GNU_SOURCE
 AC_PROG_LN_S
 
+DFLAGS=""
+
 AC_CHECK_PROG(CHMOD, chmod, chmod)
 AC_CHECK_PROG(CHOWN, chown, chown)
 AC_CHECK_PROG(AR, ar, ar)
@@ -81,24 +83,25 @@ AC_ARG_ENABLE(sensors,
                             [disable sensors support]),
                             SENSORS=$enableval,SENSORS=yes)
 if test $SENSORS != "yes"; then
-   CFSENSORS=""
-   DFSENSORS=""
+   HAVE_SENSORS="n"
 else
-   CFSENSORS="-lsensors"
-   DFSENSORS="-DHAVE_SENSORS"
+   HAVE_SENSORS="y"
 fi
 AC_MSG_RESULT($SENSORS)
 
 # Check for lm_sensors
-HAVE_SENSORS=no
-DFLAGS=""
-AC_CHECK_LIB(sensors, sensors_get_detected_chips, CFLAGS="${CFLAGS} ${CFSENSORS}")
+SENSORS=no
+LFSENSORS=""
+DFSENSORS=""
+AC_CHECK_LIB(sensors, sensors_get_detected_chips, LFSENSORS="-lsensors", HAVE_SENSORS="n")
 AC_MSG_CHECKING(for sensors lib)
 AC_TRY_COMPILE(#include <sensors/sensors.h>
 #include <sensors/error.h>
-               , sensors_cleanup();,HAVE_SENSORS=yes; DFLAGS="${DFLAGS} ${DFSENSORS}", HAVE_SENSORS=no)
-AC_MSG_RESULT($HAVE_SENSORS)
+               , sensors_cleanup();,SENSORS=yes; DFSENSORS="-DHAVE_SENSORS", HAVE_SENSORS="n"; SENSORS=no)
+AC_MSG_RESULT($SENSORS)
 AC_SUBST(HAVE_SENSORS)
+AC_SUBST(LFSENSORS)
+AC_SUBST(DFSENSORS)
 
 echo .
 echo Check system services:
diff --git a/rd_sensors.c b/rd_sensors.c
new file mode 100644 (file)
index 0000000..3174ca2
--- /dev/null
@@ -0,0 +1,295 @@
+/*
+ * rd_sensors.c: Read sensors statistics
+ * (C) 1999-2011 by Sebastien GODARD (sysstat <at> orange.fr)
+ *
+ ***************************************************************************
+ * 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 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., *
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                   *
+ ***************************************************************************
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "common.h"
+#include "rd_sensors.h"
+
+#ifdef USE_NLS
+#include <locale.h>
+#include <libintl.h>
+#define _(string) gettext(string)
+#else
+#define _(string) (string)
+#endif
+
+#ifdef HAVE_SENSORS
+#include "sensors/sensors.h"
+#endif
+
+/*
+ ***************************************************************************
+ * Read fan statistics.
+ *
+ * IN:
+ * @st_pwr_fan Structure where stats will be saved.
+ * @nbr                Total number of fans.
+ *
+ * OUT:
+ * @st_pwr_fan Structure with statistics.
+ ***************************************************************************
+ */
+void read_fan(struct stats_pwr_fan *st_pwr_fan, int nbr)
+{
+#ifdef HAVE_SENSORS
+       int count = 0;
+       const sensors_chip_name *chip;
+       const sensors_feature *feature;
+       const sensors_subfeature *sub;
+       struct stats_pwr_fan *st_pwr_fan_i;
+       int chip_nr = 0;
+       int i, j;
+
+       memset(st_pwr_fan, 0, STATS_PWR_FAN_SIZE);
+       int err = 0;
+
+       while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
+               i = 0;
+               while ((feature = sensors_get_features(chip, &i))) {
+                       if ((feature->type == SENSORS_FEATURE_FAN) && (count < nbr)) {
+                               j = 0;
+                               st_pwr_fan_i = st_pwr_fan + count;
+                               sensors_snprintf_chip_name(st_pwr_fan_i->device, MAX_SENSORS_DEV_LEN, chip);
+                               
+                               while ((sub = sensors_get_all_subfeatures(chip, feature, &j))) {
+                                       if ((sub->type == SENSORS_SUBFEATURE_FAN_INPUT) &&
+                                           (sub->flags & SENSORS_MODE_R)) {
+                                               if ((err = sensors_get_value(chip, sub->number, &st_pwr_fan_i->rpm))) {
+                                                       st_pwr_fan_i->rpm = 0;
+                                               }
+                                       }
+                                       else if ((sub->type == SENSORS_SUBFEATURE_FAN_MIN)) {
+                                               if ((err = sensors_get_value(chip, sub->number, &st_pwr_fan_i->rpm_min))) {
+                                                       st_pwr_fan_i->rpm_min = 0;
+                                               }
+                                       }
+                               }
+                               count++;
+                       }
+               }
+       }
+#endif /* HAVE_SENSORS */
+}
+
+/*
+ ***************************************************************************
+ * Read device temperature statistics.
+ *
+ * IN:
+ * @st_pwr_temp        Structure where stats will be saved.
+ * @nbr                Total number of fans.
+ *
+ * OUT:
+ * @st_pwr_temp        Structure with statistics.
+ ***************************************************************************
+ */
+void read_temp(struct stats_pwr_temp *st_pwr_temp, int nbr)
+{
+#ifdef HAVE_SENSORS
+       int count = 0;
+       const sensors_chip_name *chip;
+       const sensors_feature *feature;
+       const sensors_subfeature *sub;
+       struct stats_pwr_temp *st_pwr_temp_i;
+       int chip_nr = 0;
+       int i, j;
+
+       memset(st_pwr_temp, 0, STATS_PWR_TEMP_SIZE);
+       int err = 0;
+
+       while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
+               i = 0;
+               while ((feature = sensors_get_features(chip, &i))) {
+                       if ((feature->type == SENSORS_FEATURE_TEMP) && (count < nbr)) {
+                               j = 0;
+                               st_pwr_temp_i = st_pwr_temp + count;
+                               sensors_snprintf_chip_name(st_pwr_temp_i->device, MAX_SENSORS_DEV_LEN, chip);
+                               
+                               while ((sub = sensors_get_all_subfeatures(chip, feature, &j))) {
+                                       if ((sub->type == SENSORS_SUBFEATURE_TEMP_INPUT) &&
+                                               (sub->flags & SENSORS_MODE_R)) {
+                                               if ((err = sensors_get_value(chip, sub->number, &st_pwr_temp_i->temp))) {
+                                                       st_pwr_temp_i->temp = 0;
+                                               }
+                                       }
+                                       else if ((sub->type == SENSORS_SUBFEATURE_TEMP_MIN)) {
+                                               if ((err = sensors_get_value(chip, sub->number, &st_pwr_temp_i->temp_min))) {
+                                                       st_pwr_temp_i->temp_min = 0;
+                                               }
+                                       }
+                                       else if ((sub->type == SENSORS_SUBFEATURE_TEMP_MAX)) {
+                                               if ((err = sensors_get_value(chip, sub->number, &st_pwr_temp_i->temp_max))) {
+                                                       st_pwr_temp_i->temp_max = 0;
+                                               }
+                                       }
+                               }
+                               count++;
+                       }
+               }
+       }
+#endif /* HAVE_SENSORS */
+}
+
+/*
+ ***************************************************************************
+ * Read voltage inputs statistics.
+ *
+ * IN:
+ * @st_pwr_in  Structure where stats will be saved.
+ * @nbr                Total number of voltage inputs.
+ *
+ * OUT:
+ * @st_pwr_in  Structure with statistics.
+ ***************************************************************************
+ */
+void read_in(struct stats_pwr_in *st_pwr_in, int nbr)
+{
+#ifdef HAVE_SENSORS
+       int count = 0;
+       const sensors_chip_name *chip;
+       const sensors_feature *feature;
+       const sensors_subfeature *sub;
+       struct stats_pwr_in *st_pwr_in_i;
+       int chip_nr = 0;
+       int i, j;
+
+       memset(st_pwr_in, 0, STATS_PWR_IN_SIZE);
+       int err = 0;
+
+       while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
+               i = 0;
+               while ((feature = sensors_get_features(chip, &i))) {
+                       if ((feature->type == SENSORS_FEATURE_IN) && (count < nbr)) {
+                               j = 0;
+                               st_pwr_in_i = st_pwr_in + count;
+                               sensors_snprintf_chip_name(st_pwr_in_i->device, MAX_SENSORS_DEV_LEN, chip);
+
+                               while ((sub = sensors_get_all_subfeatures(chip, feature, &j))) {
+                                       if ((sub->type == SENSORS_SUBFEATURE_IN_INPUT) &&
+                                               (sub->flags & SENSORS_MODE_R)) {
+                                               if ((err = sensors_get_value(chip, sub->number, &st_pwr_in_i->in))) {
+                                                       st_pwr_in_i->in = 0;
+                                               }
+                                       }
+                                       else if ((sub->type == SENSORS_SUBFEATURE_IN_MIN)) {
+                                               if ((err = sensors_get_value(chip, sub->number, &st_pwr_in_i->in_min))) {
+                                                       st_pwr_in_i->in_min = 0;
+                                               }
+                                       }
+                                       else if ((sub->type == SENSORS_SUBFEATURE_IN_MAX)) {
+                                               if ((err = sensors_get_value(chip, sub->number, &st_pwr_in_i->in_max))) {
+                                                       st_pwr_in_i->in_max = 0;
+                                               }
+                                       }
+                               }
+                               count++;
+                       }
+               }
+       }
+#endif /* HAVE_SENSORS */
+}
+
+#ifdef HAVE_SENSORS
+/*
+ ***************************************************************************
+ * Count the number of sensors of given type on the machine.
+ *
+ * IN:
+ * @type       Type of sensors.
+ *
+ * RETURNS:
+ * Number of sensors.
+ ***************************************************************************
+ */
+int get_sensors_nr(sensors_feature_type type) {
+       int count = 0;
+       const sensors_chip_name *chip;
+       const sensors_feature *feature;
+       int chip_nr = 0;
+       int i;
+
+       while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
+               i = 0;
+               while ((feature = sensors_get_features(chip, &i))) {
+                       if (feature->type == type) {
+                               count++;
+                       }
+               }
+       }
+
+       return count;
+}
+#endif /* HAVE_SENSORS */
+
+/*
+ ***************************************************************************
+ * Count the number of fans on the machine.
+ *
+ * RETURNS:
+ * Number of fans.
+ ***************************************************************************
+ */
+int get_fan_nr(void)
+{
+#ifdef HAVE_SENSORS
+       return get_sensors_nr(SENSORS_FEATURE_FAN);
+#else
+       return 0;
+#endif /* HAVE_SENSORS */
+}
+
+/*
+ ***************************************************************************
+ * Count the number of temperature sensors on the machine.
+ *
+ * RETURNS:
+ * Number of temperature sensors.
+ ***************************************************************************
+ */
+int get_temp_nr(void)
+{
+#ifdef HAVE_SENSORS
+       return get_sensors_nr(SENSORS_FEATURE_TEMP);
+#else
+       return 0;
+#endif /* HAVE_SENSORS */
+
+}
+
+/*
+ ***************************************************************************
+ * Count the number of voltage inputs on the machine.
+ *
+ * RETURNS:
+ * Number of voltage inputs.
+ ***************************************************************************
+ */
+int get_in_nr(void)
+{
+#ifdef HAVE_SENSORS
+       return get_sensors_nr(SENSORS_FEATURE_IN);
+#else
+       return 0;
+#endif /* HAVE_SENSORS */
+
+}
diff --git a/rd_sensors.h b/rd_sensors.h
new file mode 100644 (file)
index 0000000..814d088
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * rd_sensors.h: Include file used to read sensors statistics
+ * (C) 1999-2011 by Sebastien Godard (sysstat <at> orange.fr)
+ */
+
+#ifndef _RD_SENSORS_H
+#define _RD_SENSORS_H
+
+#include "common.h"
+
+/*
+ ***************************************************************************
+ * Definitions of structures for sensors statistics
+ ***************************************************************************
+ */
+
+/*
+ * Structure for fan statistics.
+ */
+struct stats_pwr_fan {
+       double  rpm                             __attribute__ ((aligned (8)));
+       double  rpm_min                         __attribute__ ((aligned (8)));
+       char    device[MAX_SENSORS_DEV_LEN]     __attribute__ ((aligned (8)));
+};
+
+#define STATS_PWR_FAN_SIZE     (sizeof(struct stats_pwr_fan))
+
+/*
+ * Structure for device temperature statistics.
+ */
+struct stats_pwr_temp {
+       double  temp                            __attribute__ ((aligned (8)));
+       double  temp_min                        __attribute__ ((aligned (8)));
+       double  temp_max                        __attribute__ ((aligned (8)));
+       char    device[MAX_SENSORS_DEV_LEN]     __attribute__ ((aligned (8)));
+};
+
+#define STATS_PWR_TEMP_SIZE    (sizeof(struct stats_pwr_temp))
+
+/*
+ * Structure for voltage inputs statistics.
+ */
+struct stats_pwr_in {
+       double  in                              __attribute__ ((aligned (8)));
+       double  in_min                          __attribute__ ((aligned (8)));
+       double  in_max                          __attribute__ ((aligned (8)));
+       char    device[MAX_SENSORS_DEV_LEN]     __attribute__ ((aligned (8)));
+};
+
+#define STATS_PWR_IN_SIZE      (sizeof(struct stats_pwr_in))
+
+/*
+ ***************************************************************************
+ * Prototypes for functions used to read sensors statistics
+ ***************************************************************************
+ */
+
+extern void
+       read_fan(struct stats_pwr_fan *, int);
+extern void
+       read_temp(struct stats_pwr_temp *, int);
+extern void
+       read_in(struct stats_pwr_in *, int);
+
+/*
+ ***************************************************************************
+ * Prototypes for functions used to count number of items
+ ***************************************************************************
+ */
+
+extern int
+       get_fan_nr(void);
+extern int
+       get_temp_nr(void);
+extern int
+       get_in_nr(void);
+
+#endif /* _RD_SENSORS_H */
index 772d1fbac092ff4b63edc18a568bb4c9ba136d77..cb3b46fb7feb82cf263ffa84bcde094e0025451a 100644 (file)
 #define _(string) (string)
 #endif
 
-#ifdef HAVE_SENSORS
-#include "sensors/sensors.h"
-#endif
-
 /*
  ***************************************************************************
  * Read CPU statistics and machine uptime.
@@ -1659,178 +1655,6 @@ void read_cpuinfo(struct stats_pwr_cpufreq *st_pwr_cpufreq, int nbr)
        }
 }
 
-/*
- ***************************************************************************
- * Read fan statistics.
- *
- * IN:
- * @st_pwr_fan Structure where stats will be saved.
- * @nbr                Total number of fans.
- *
- * OUT:
- * @st_pwr_fan Structure with statistics.
- ***************************************************************************
- */
-void read_fan(struct stats_pwr_fan *st_pwr_fan, int nbr)
-{
-#ifdef HAVE_SENSORS
-       int count = 0;
-       const sensors_chip_name *chip;
-       const sensors_feature *feature;
-       const sensors_subfeature *sub;
-       struct stats_pwr_fan *st_pwr_fan_i;
-       int chip_nr = 0;
-       int i, j;
-
-       memset(st_pwr_fan, 0, STATS_PWR_FAN_SIZE);
-       int err = 0;
-
-       while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
-               i = 0;
-               while ((feature = sensors_get_features(chip, &i))) {
-                       if ((feature->type == SENSORS_FEATURE_FAN) && (count < nbr)) {
-                               j = 0;
-                               st_pwr_fan_i = st_pwr_fan + count;
-                               sensors_snprintf_chip_name(st_pwr_fan_i->device, MAX_SENSORS_DEV_LEN, chip);
-                               
-                               while ((sub = sensors_get_all_subfeatures(chip, feature, &j))) {
-                                       if ((sub->type == SENSORS_SUBFEATURE_FAN_INPUT) &&
-                                           (sub->flags & SENSORS_MODE_R)) {
-                                               if ((err = sensors_get_value(chip, sub->number, &st_pwr_fan_i->rpm))) {
-                                                       st_pwr_fan_i->rpm = 0;
-                                               }
-                                       }
-                                       else if ((sub->type == SENSORS_SUBFEATURE_FAN_MIN)) {
-                                               if ((err = sensors_get_value(chip, sub->number, &st_pwr_fan_i->rpm_min))) {
-                                                       st_pwr_fan_i->rpm_min = 0;
-                                               }
-                                       }
-                               }
-                               count++;
-                       }
-               }
-       }
-#endif /* HAVE_SENSORS */
-}
-
-/*
- ***************************************************************************
- * Read device temperature statistics.
- *
- * IN:
- * @st_pwr_temp        Structure where stats will be saved.
- * @nbr                Total number of fans.
- *
- * OUT:
- * @st_pwr_temp        Structure with statistics.
- ***************************************************************************
- */
-void read_temp(struct stats_pwr_temp *st_pwr_temp, int nbr)
-{
-#ifdef HAVE_SENSORS
-       int count = 0;
-       const sensors_chip_name *chip;
-       const sensors_feature *feature;
-       const sensors_subfeature *sub;
-       struct stats_pwr_temp *st_pwr_temp_i;
-       int chip_nr = 0;
-       int i, j;
-
-       memset(st_pwr_temp, 0, STATS_PWR_TEMP_SIZE);
-       int err = 0;
-
-       while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
-               i = 0;
-               while ((feature = sensors_get_features(chip, &i))) {
-                       if ((feature->type == SENSORS_FEATURE_TEMP) && (count < nbr)) {
-                               j = 0;
-                               st_pwr_temp_i = st_pwr_temp + count;
-                               sensors_snprintf_chip_name(st_pwr_temp_i->device, MAX_SENSORS_DEV_LEN, chip);
-                               
-                               while ((sub = sensors_get_all_subfeatures(chip, feature, &j))) {
-                                       if ((sub->type == SENSORS_SUBFEATURE_TEMP_INPUT) &&
-                                               (sub->flags & SENSORS_MODE_R)) {
-                                               if ((err = sensors_get_value(chip, sub->number, &st_pwr_temp_i->temp))) {
-                                                       st_pwr_temp_i->temp = 0;
-                                               }
-                                       }
-                                       else if ((sub->type == SENSORS_SUBFEATURE_TEMP_MIN)) {
-                                               if ((err = sensors_get_value(chip, sub->number, &st_pwr_temp_i->temp_min))) {
-                                                       st_pwr_temp_i->temp_min = 0;
-                                               }
-                                       }
-                                       else if ((sub->type == SENSORS_SUBFEATURE_TEMP_MAX)) {
-                                               if ((err = sensors_get_value(chip, sub->number, &st_pwr_temp_i->temp_max))) {
-                                                       st_pwr_temp_i->temp_max = 0;
-                                               }
-                                       }
-                               }
-                               count++;
-                       }
-               }
-       }
-#endif /* HAVE_SENSORS */
-}
-
-/*
- ***************************************************************************
- * Read voltage inputs statistics.
- *
- * IN:
- * @st_pwr_in  Structure where stats will be saved.
- * @nbr                Total number of voltage inputs.
- *
- * OUT:
- * @st_pwr_in  Structure with statistics.
- ***************************************************************************
- */
-void read_in(struct stats_pwr_in *st_pwr_in, int nbr)
-{
-#ifdef HAVE_SENSORS
-       int count = 0;
-       const sensors_chip_name *chip;
-       const sensors_feature *feature;
-       const sensors_subfeature *sub;
-       struct stats_pwr_in *st_pwr_in_i;
-       int chip_nr = 0;
-       int i, j;
-
-       memset(st_pwr_in, 0, STATS_PWR_IN_SIZE);
-       int err = 0;
-
-       while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
-               i = 0;
-               while ((feature = sensors_get_features(chip, &i))) {
-                       if ((feature->type == SENSORS_FEATURE_IN) && (count < nbr)) {
-                               j = 0;
-                               st_pwr_in_i = st_pwr_in + count;
-                               sensors_snprintf_chip_name(st_pwr_in_i->device, MAX_SENSORS_DEV_LEN, chip);
-
-                               while ((sub = sensors_get_all_subfeatures(chip, feature, &j))) {
-                                       if ((sub->type == SENSORS_SUBFEATURE_IN_INPUT) &&
-                                               (sub->flags & SENSORS_MODE_R)) {
-                                               if ((err = sensors_get_value(chip, sub->number, &st_pwr_in_i->in))) {
-                                                       st_pwr_in_i->in = 0;
-                                               }
-                                       }
-                                       else if ((sub->type == SENSORS_SUBFEATURE_IN_MIN)) {
-                                               if ((err = sensors_get_value(chip, sub->number, &st_pwr_in_i->in_min))) {
-                                                       st_pwr_in_i->in_min = 0;
-                                               }
-                                       }
-                                       else if ((sub->type == SENSORS_SUBFEATURE_IN_MAX)) {
-                                               if ((err = sensors_get_value(chip, sub->number, &st_pwr_in_i->in_max))) {
-                                                       st_pwr_in_i->in_max = 0;
-                                               }
-                                       }
-                               }
-                               count++;
-                       }
-               }
-       }
-#endif /* HAVE_SENSORS */
-}
-
 /*
  ***************************************************************************
  * Read hugepages statistics from /proc/meminfo.
@@ -2273,91 +2097,6 @@ int get_irqcpu_nr(char *file, int max_nr_irqcpu, int cpu_nr)
        return irq;
 }
 
-#ifdef HAVE_SENSORS
-/*
- ***************************************************************************
- * Count the number of sensors of given type on the machine.
- *
- * IN:
- * @type       Type of sensors.
- *
- * RETURNS:
- * Number of sensors.
- ***************************************************************************
- */
-int get_sensors_nr(sensors_feature_type type) {
-       int count = 0;
-       const sensors_chip_name *chip;
-       const sensors_feature *feature;
-       int chip_nr = 0;
-       int i;
-
-       while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
-               i = 0;
-               while ((feature = sensors_get_features(chip, &i))) {
-                       if (feature->type == type) {
-                               count++;
-                       }
-               }
-       }
-
-       return count;
-}
-#endif /* HAVE_SENSORS */
-
-/*
- ***************************************************************************
- * Count the number of fans on the machine.
- *
- * RETURNS:
- * Number of fans.
- ***************************************************************************
- */
-int get_fan_nr(void)
-{
-#ifdef HAVE_SENSORS
-       return get_sensors_nr(SENSORS_FEATURE_FAN);
-#else
-       return 0;
-#endif /* HAVE_SENSORS */
-}
-
-/*
- ***************************************************************************
- * Count the number of temperature sensors on the machine.
- *
- * RETURNS:
- * Number of temperature sensors.
- ***************************************************************************
- */
-int get_temp_nr(void)
-{
-#ifdef HAVE_SENSORS
-       return get_sensors_nr(SENSORS_FEATURE_TEMP);
-#else
-       return 0;
-#endif /* HAVE_SENSORS */
-
-}
-
-/*
- ***************************************************************************
- * Count the number of voltage inputs on the machine.
- *
- * RETURNS:
- * Number of voltage inputs.
- ***************************************************************************
- */
-int get_in_nr(void)
-{
-#ifdef HAVE_SENSORS
-       return get_sensors_nr(SENSORS_FEATURE_IN);
-#else
-       return 0;
-#endif /* HAVE_SENSORS */
-
-}
-
 /*
  ***************************************************************************
  * Count number of possible frequencies for CPU#0.
index dcbc48462c673fbaf63ec2ca6a6914d0de09755d..9b01ac12708e3b8051c4379107d737b034ddfe87 100644 (file)
@@ -484,41 +484,6 @@ struct stats_pwr_cpufreq {
 
 #define STATS_PWR_CPUFREQ_SIZE (sizeof(struct stats_pwr_cpufreq))
 
-/*
- * Structure for fan statistics.
- */
-struct stats_pwr_fan {
-       double  rpm                             __attribute__ ((aligned (8)));
-       double  rpm_min                         __attribute__ ((aligned (8)));
-       char    device[MAX_SENSORS_DEV_LEN]     __attribute__ ((aligned (8)));
-};
-
-#define STATS_PWR_FAN_SIZE     (sizeof(struct stats_pwr_fan))
-
-/*
- * Structure for device temperature statistics.
- */
-struct stats_pwr_temp {
-       double  temp                            __attribute__ ((aligned (8)));
-       double  temp_min                        __attribute__ ((aligned (8)));
-       double  temp_max                        __attribute__ ((aligned (8)));
-       char    device[MAX_SENSORS_DEV_LEN]     __attribute__ ((aligned (8)));
-};
-
-#define STATS_PWR_TEMP_SIZE    (sizeof(struct stats_pwr_temp))
-
-/*
- * Structure for voltage inputs statistics.
- */
-struct stats_pwr_in {
-       double  in                              __attribute__ ((aligned (8)));
-       double  in_min                          __attribute__ ((aligned (8)));
-       double  in_max                          __attribute__ ((aligned (8)));
-       char    device[MAX_SENSORS_DEV_LEN]     __attribute__ ((aligned (8)));
-};
-
-#define STATS_PWR_IN_SIZE      (sizeof(struct stats_pwr_in))
-
 /* Structure for hugepages statistics */
 struct stats_huge {
        unsigned long frhkb                     __attribute__ ((aligned (8)));
@@ -608,12 +573,6 @@ extern void
        read_net_udp6(struct stats_net_udp6 *);
 extern void
        read_cpuinfo(struct stats_pwr_cpufreq *, int);
-extern void
-       read_fan(struct stats_pwr_fan *, int);
-extern void
-       read_temp(struct stats_pwr_temp *, int);
-extern void
-       read_in(struct stats_pwr_in *, int);
 extern void
        read_meminfo_huge(struct stats_huge *);
 extern void
@@ -639,12 +598,6 @@ extern int
        get_cpu_nr(unsigned int);
 extern int
        get_irqcpu_nr(char *, int, int);
-extern int
-       get_fan_nr(void);
-extern int
-       get_temp_nr(void);
-extern int
-       get_in_nr(void);
 extern int
        get_freq_nr(void);
 
diff --git a/sa.h b/sa.h
index a210ebbd9a4a277ad951d278160043ef28099d1c..57021ddea49782d424d15684fe46ec6219fb5730 100644 (file)
--- a/sa.h
+++ b/sa.h
@@ -8,7 +8,7 @@
 
 #include "common.h"
 #include "rd_stats.h"
-
+#include "rd_sensors.h"
 
 /*
  ***************************************************************************
index 78da6378b3a148fb074e787528ee5d38aa88cbeb..3fd08ef06d9e11989c874b384ec375a77722ad72 100644 (file)
--- a/sa_wrap.c
+++ b/sa_wrap.c
@@ -21,6 +21,7 @@
 
 #include "sa.h"
 #include "rd_stats.h"
+#include "rd_sensors.h"
 
 extern unsigned int flags;
 extern struct record_header record_hdr;