mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-26 00:28:25 +00:00
review load* code
This commit is contained in:
parent
42dfb7ac69
commit
0bed05997b
@ -1,3 +1,7 @@
|
|||||||
|
2009-10-25
|
||||||
|
* Fixed loadavg and loadgraph argument parsing and corrected it's
|
||||||
|
documentation.
|
||||||
|
|
||||||
2009-09-11
|
2009-09-11
|
||||||
* Fixed configure test failure. Tolua test program couldn't find lua
|
* Fixed configure test failure. Tolua test program couldn't find lua
|
||||||
libraries (even though they existed) and failed to compile.
|
libraries (even though they existed) and failed to compile.
|
||||||
|
@ -1787,7 +1787,8 @@
|
|||||||
<option>(1|2|3)</option>
|
<option>(1|2|3)</option>
|
||||||
</term>
|
</term>
|
||||||
<listitem>System load average, 1 is for past 1 minute, 2
|
<listitem>System load average, 1 is for past 1 minute, 2
|
||||||
for past 5 minutes and 3 for past 15 minutes.
|
for past 5 minutes and 3 for past 15 minutes. Without argument, prints
|
||||||
|
all three values separated by whitespace.
|
||||||
<para /></listitem>
|
<para /></listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
@ -1795,7 +1796,7 @@
|
|||||||
<command>
|
<command>
|
||||||
<option>loadgraph</option>
|
<option>loadgraph</option>
|
||||||
</command>
|
</command>
|
||||||
<option>(1|2|3) (height),(width) (gradient colour 1)
|
<option>(height),(width) (gradient colour 1)
|
||||||
(gradient colour 2) (scale) (-t) (-l)</option>
|
(gradient colour 2) (scale) (-t) (-l)</option>
|
||||||
</term>
|
</term>
|
||||||
<listitem>Load1 average graph, similar to xload, with
|
<listitem>Load1 average graph, similar to xload, with
|
||||||
|
48
src/common.c
48
src/common.c
@ -420,41 +420,26 @@ unsigned int round_to_int(float f)
|
|||||||
|
|
||||||
void scan_loadavg_arg(struct text_object *obj, const char *arg)
|
void scan_loadavg_arg(struct text_object *obj, const char *arg)
|
||||||
{
|
{
|
||||||
int a = 1, b = 2, c = 3, r = 3;
|
obj->data.i = 0;
|
||||||
|
if (arg && !arg[1] && isdigit(arg[0])) {
|
||||||
if (arg) {
|
obj->data.i = atoi(arg);
|
||||||
r = sscanf(arg, "%d %d %d", &a, &b, &c);
|
if (obj->data.i > 3 || obj->data.i < 1) {
|
||||||
if (r >= 3 && (c < 1 || c > 3)) {
|
NORM_ERR("loadavg arg needs to be in range (1,3)");
|
||||||
r--;
|
obj->data.i = 0;
|
||||||
}
|
|
||||||
if (r >= 2 && (b < 1 || b > 3)) {
|
|
||||||
r--, b = c;
|
|
||||||
}
|
|
||||||
if (r >= 1 && (a < 1 || a > 3)) {
|
|
||||||
r--, a = b, b = c;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
|
/* convert to array index (or the default (-1)) */
|
||||||
obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
|
obj->data.i--;
|
||||||
obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_loadavg(struct text_object *obj, char *p, int p_max_size)
|
void print_loadavg(struct text_object *obj, char *p, int p_max_size)
|
||||||
{
|
{
|
||||||
float *v = info.loadavg;
|
float *v = info.loadavg;
|
||||||
|
|
||||||
if (obj->data.loadavg[2]) {
|
if (obj->data.i < 0) {
|
||||||
snprintf(p, p_max_size, "%.2f %.2f %.2f",
|
snprintf(p, p_max_size, "%.2f %.2f %.2f", v[0], v[1], v[2]);
|
||||||
v[obj->data.loadavg[0] - 1],
|
} else {
|
||||||
v[obj->data.loadavg[1] - 1],
|
snprintf(p, p_max_size, "%.2f", v[obj->data.i]);
|
||||||
v[obj->data.loadavg[2] - 1]);
|
|
||||||
} else if (obj->data.loadavg[1]) {
|
|
||||||
snprintf(p, p_max_size, "%.2f %.2f",
|
|
||||||
v[obj->data.loadavg[0] - 1],
|
|
||||||
v[obj->data.loadavg[1] - 1]);
|
|
||||||
} else if (obj->data.loadavg[0]) {
|
|
||||||
snprintf(p, p_max_size, "%.2f",
|
|
||||||
v[obj->data.loadavg[0] - 1]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -462,17 +447,12 @@ void print_loadavg(struct text_object *obj, char *p, int p_max_size)
|
|||||||
void scan_loadgraph_arg(struct text_object *obj, const char *arg)
|
void scan_loadgraph_arg(struct text_object *obj, const char *arg)
|
||||||
{
|
{
|
||||||
char *buf = 0;
|
char *buf = 0;
|
||||||
|
|
||||||
SIZE_DEFAULTS(graph);
|
SIZE_DEFAULTS(graph);
|
||||||
buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
|
buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
|
||||||
&obj->e, &obj->char_a, &obj->char_b);
|
&obj->e, &obj->char_a, &obj->char_b);
|
||||||
if (buf) {
|
if (buf)
|
||||||
int a = 1, r = 3;
|
|
||||||
if (arg) {
|
|
||||||
r = sscanf(arg, "%d", &a);
|
|
||||||
}
|
|
||||||
obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
|
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_loadgraph(struct text_object *obj, char *p)
|
void print_loadgraph(struct text_object *obj, char *p)
|
||||||
|
@ -434,7 +434,6 @@ struct text_object {
|
|||||||
char *s; /* some string */
|
char *s; /* some string */
|
||||||
int i; /* some integer */
|
int i; /* some integer */
|
||||||
long l; /* some other integer */
|
long l; /* some other integer */
|
||||||
unsigned char loadavg[3];
|
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
void *opaque; /* temporary workaround to not blow stuff */
|
void *opaque; /* temporary workaround to not blow stuff */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user