enable displaying the used ioscheduler for a given disk
authorPhil <n0-1@users.sourceforge.net>
Sat, 22 Mar 2008 21:10:43 +0000 (21:10 +0000)
committerPhil <n0-1@users.sourceforge.net>
Sat, 22 Mar 2008 21:10:43 +0000 (21:10 +0000)
git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@1034 7f574dfc-610e-0410-a909-a81674777703

doc/conky.1
doc/variables.xml
src/conky.c
src/conky.h
src/linux.c

index 26e3c71..88db190 100644 (file)
@@ -894,12 +894,16 @@ Displays the number of messages in your global IMAP inbox by default. You can de
 Displays the number of unseen messages in your global IMAP inbox by default. You can define individual IMAP inboxes seperately by passing arguments to this object. Arguments are: "host user pass [-i interval] [-p port] [-e command]". Default port is 143, default interval is 5 minutes. If the password is supplied as '*', you will be prompted to enter the password when Conky starts.
 
 .TP 
+\fB\*(T<\fBioscheduler\fR\*(T>\fR \*(T<\fB(disk)\fR\*(T> 
+Prints the current ioscheduler used for the given disk name (i.e. e.g. "hda" or "sdb")
+
+.TP 
 \fB\*(T<\fBkernel\fR\*(T>\fR 
 Kernel version
 
 .TP 
 \fB\*(T<\fBlaptop_mode\fR\*(T>\fR 
-value of /proc/sys/vm/laptop_mode
+The value of /proc/sys/vm/laptop_mode
 
 .TP 
 \fB\*(T<\fBloadavg\fR\*(T>\fR 
index 56b5259..4f339c9 100644 (file)
 
 <varlistentry>
        <term>
+               <command><option>ioscheduler</option></command>
+       </term>
+       <option>(disk)</option>
+       <listitem>
+               Prints the current ioscheduler used for the given disk name (i.e. e.g. "hda" or "sdb")
+       <para></para></listitem>
+</varlistentry>
+
+<varlistentry>
+       <term>
                <command><option>kernel</option></command>
        </term>
        <listitem>
                <command><option>laptop_mode</option></command>
        </term>
        <listitem>
-               value of /proc/sys/vm/laptop_mode
+               The value of /proc/sys/vm/laptop_mode
        <para></para></listitem>
 </varlistentry>
 
index c4f0df9..e1c4b8f 100644 (file)
@@ -1145,6 +1145,7 @@ enum text_object_type {
        OBJ_ibm_brightness,
        OBJ_if_up,
        OBJ_if_gw,
+       OBJ_ioscheduler,
        OBJ_gw_iface,
        OBJ_gw_ip,
        OBJ_laptop_mode,
@@ -2065,6 +2066,10 @@ static void free_text_objects(unsigned int count, struct text_object *objs)
                                        info.gw_info.ip = 0;
                                }
                                break;
+                       case OBJ_ioscheduler:
+                               if(objs[i].data.s)
+                                       free(objs[i].data.s);
+                               break;
 #endif
 #ifdef XMMS2
                        case OBJ_xmms2_artist:
@@ -2477,6 +2482,12 @@ static struct text_object *construct_text_object(const char *s,
                blockstart[blockdepth] = object_count;
                obj->data.ifblock.pos = object_count + 2;
                blockdepth++;
+       END OBJ(ioscheduler, 0)
+               if (!arg) {
+                       CRIT_ERR("get_ioscheduler needs an argument (e.g. hda)");
+                       obj->data.s = 0;
+               } else
+                       obj->data.s = strdup(arg);
        END OBJ(laptop_mode, 0)
        END OBJ(pb_battery, 0)
                if (arg && strcmp(arg, "status") == 0) {
@@ -5309,6 +5320,9 @@ static void generate_text_internal(char *p, int p_max_size,
                                        if_jumped = 0;
                                }
                        }
+                       OBJ(ioscheduler) {
+                               snprintf(p, p_max_size, "%s", get_ioscheduler(obj->data.s));
+                       }
                        OBJ(kernel) {
                                snprintf(p, p_max_size, "%s", cur->uname_s.release);
                        }
index e9f0ef3..d93e7d2 100644 (file)
@@ -544,6 +544,7 @@ void get_freq_dynamic(char *, size_t, char *, int);
 char get_voltage(char *, size_t, char *, int, unsigned int);   /* ptarjan */
 void update_load_average();
 int interface_up(const char *dev);
+char *get_ioscheduler(char *);
 int get_laptop_mode(void);
 void update_gateway_info(void);
 
index 6922667..e498454 100644 (file)
@@ -178,6 +178,34 @@ int get_laptop_mode()
        return val;
 }
 
+/* my system says:
+ * # cat /sys/block/sda/queue/scheduler
+ * noop [anticipatory] cfq
+ */
+char *get_ioscheduler(char *disk)
+{
+       FILE *fp;
+       char buf[128];
+
+       if (!disk)
+               return "n/a";
+
+       snprintf(buf, 127, "/sys/block/%s/queue/scheduler", disk);
+       if ((fp = fopen(buf, "r")) == NULL) {
+               return strdup("n/a");
+       }
+       while (!feof(fp)) {
+               fscanf(fp, "%127s", buf);
+               if (buf[0] == '[') {
+                       buf[strlen(buf) - 1] = '\0';
+                       fclose(fp);
+                       return strdup(buf + 1);
+               }
+       }
+       fclose(fp);
+       return strdup("n/a");
+}
+
 int interface_up(const char *dev)
 {
        int fd;