xdbe replaced with more generic pixmap based buffering but there are 3 major bugs:
[monky] / src / diskio.c
index 1e4a7a7..d9b2f3f 100644 (file)
@@ -10,7 +10,7 @@
  * Please see COPYING for details
  *
  * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
  * (see AUTHORS)
  * All rights reserved.
  *
 
 #include "config.h"
 #include "conky.h"     /* text_buffer_size */
+#include "core.h"
 #include "logging.h"
 #include "diskio.h"
 #include "common.h"
+#include "specials.h"
+#include "text_object.h"
 #include <stdlib.h>
 #include <limits.h>
 #include <sys/stat.h>
@@ -73,12 +76,6 @@ struct diskio_stat *prepare_diskio_stat(const char *s)
        if (!s)
                return &stats;
 
-#if defined(__FreeBSD__)
-       if (strncmp(s, "/dev/", 5) == 0) {
-               // supplied a /dev/device arg, so cut off the /dev part
-               strncpy(device_name, s + 5, text_buffer_size);
-       } else
-#endif
        strncpy(device_name, s, text_buffer_size);
 
        snprintf(stat_name, text_buffer_size, "/dev/%s", device_name);
@@ -106,6 +103,99 @@ struct diskio_stat *prepare_diskio_stat(const char *s)
        return cur;
 }
 
+void parse_diskio_arg(struct text_object *obj, const char *arg)
+{
+       obj->data.opaque = prepare_diskio_stat(arg);
+}
+
+/* dir indicates the direction:
+ * -1: read
+ *  0: read + write
+ *  1: write
+ */
+static void print_diskio_dir(struct text_object *obj, int dir, char *p, int p_max_size)
+{
+       struct diskio_stat *diskio = obj->data.opaque;
+       double val;
+
+       if (!diskio)
+               return;
+
+       if (dir < 0)
+               val = diskio->current_read;
+       else if (dir == 0)
+               val = diskio->current;
+       else
+               val = diskio->current_write;
+
+       /* TODO: move this correction from kB to kB/s elsewhere
+        * (or get rid of it??) */
+       human_readable((val / update_interval) * 1024LL, p, p_max_size);
+}
+
+void print_diskio(struct text_object *obj, char *p, int p_max_size)
+{
+       print_diskio_dir(obj, 0, p, p_max_size);
+}
+
+void print_diskio_read(struct text_object *obj, char *p, int p_max_size)
+{
+       print_diskio_dir(obj, -1, p, p_max_size);
+}
+
+void print_diskio_write(struct text_object *obj, char *p, int p_max_size)
+{
+       print_diskio_dir(obj, 1, p, p_max_size);
+}
+
+#ifdef X11
+void parse_diskiograph_arg(struct text_object *obj, const char *arg)
+{
+       char *buf = 0;
+       buf = scan_graph(obj, arg, 0);
+
+       obj->data.opaque = prepare_diskio_stat(dev_name(buf));
+       if (buf)
+               free(buf);
+}
+
+static void print_diskiograph_dir(struct text_object *obj, int dir, char *p, int p_max_size)
+{
+       struct diskio_stat *diskio = obj->data.opaque;
+       double val;
+
+       if (!diskio)
+               return;
+
+       if (!p_max_size)
+               return;
+
+       if (dir < 0)
+               val = diskio->current_read;
+       else if (dir == 0)
+               val = diskio->current;
+       else
+               val = diskio->current_write;
+
+       new_graph(obj, p, p_max_size, val);
+}
+
+void print_diskiograph(struct text_object *obj, char *p, int p_max_size)
+{
+       print_diskiograph_dir(obj, 0, p, p_max_size);
+}
+
+void print_diskiograph_read(struct text_object *obj, char *p, int p_max_size)
+{
+       print_diskiograph_dir(obj, -1, p, p_max_size);
+}
+
+void print_diskiograph_write(struct text_object *obj, char *p, int p_max_size)
+{
+       print_diskiograph_dir(obj, 1, p, p_max_size);
+}
+#endif /* X11 */
+
 void update_diskio_values(struct diskio_stat *ds,
                unsigned int reads, unsigned int writes)
 {
@@ -118,7 +208,7 @@ void update_diskio_values(struct diskio_stat *ds,
                ds->last_read = reads;
                ds->last_write = writes;
        }
-       /* since the values in /proc/diskstats are absolute, we have to substract
+       /* since the values in /proc/diskstats are absolute, we have to subtract
         * our last reading. The numbers stand for "sectors read", and we therefore
         * have to divide by two to get KB */
        ds->sample_read[0] = (reads - ds->last_read) / 2;