1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-23 19:39:06 +00:00

diskio: convert to generic object payload

This commit is contained in:
Phil Sutter 2009-10-07 22:44:17 +02:00
parent aa4d61d3d7
commit 0740e91911
5 changed files with 85 additions and 39 deletions

View File

@ -1145,32 +1145,24 @@ void generate_text_internal(char *p, int p_max_size,
need_to_load_fonts = 1;
}
#endif /* X11 */
/* TODO: move this correction from kB to kB/s elsewhere
* (or get rid of it??) */
OBJ(diskio) {
human_readable((obj->data.diskio->current / update_interval) * 1024LL,
p, p_max_size);
print_diskio(obj, 0, p, p_max_size);
}
OBJ(diskio_write) {
human_readable((obj->data.diskio->current_write / update_interval) * 1024LL,
p, p_max_size);
print_diskio(obj, 1, p, p_max_size);
}
OBJ(diskio_read) {
human_readable((obj->data.diskio->current_read / update_interval) * 1024LL,
p, p_max_size);
print_diskio(obj, -1, p, p_max_size);
}
#ifdef X11
OBJ(diskiograph) {
new_graph(p, obj->a, obj->b, obj->c, obj->d,
obj->data.diskio->current, obj->e, 1, obj->char_a, obj->char_b);
print_diskiograph(obj, 0, p);
}
OBJ(diskiograph_read) {
new_graph(p, obj->a, obj->b, obj->c, obj->d,
obj->data.diskio->current_read, obj->e, 1, obj->char_a, obj->char_b);
print_diskiograph(obj, -1, p);
}
OBJ(diskiograph_write) {
new_graph(p, obj->a, obj->b, obj->c, obj->d,
obj->data.diskio->current_write, obj->e, 1, obj->char_a, obj->char_b);
print_diskiograph(obj, 1, p);
}
#endif /* X11 */
OBJ(downspeed) {

View File

@ -396,36 +396,18 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
}
#endif /* X11 */
END OBJ(diskio, &update_diskio)
obj->data.diskio = prepare_diskio_stat(dev_name(arg));
parse_diskio_arg(obj, arg);
END OBJ(diskio_read, &update_diskio)
obj->data.diskio = prepare_diskio_stat(dev_name(arg));
parse_diskio_arg(obj, arg);
END OBJ(diskio_write, &update_diskio)
obj->data.diskio = prepare_diskio_stat(dev_name(arg));
parse_diskio_arg(obj, arg);
#ifdef X11
END OBJ(diskiograph, &update_diskio)
char *buf = 0;
SIZE_DEFAULTS(graph);
buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
&obj->e, &obj->char_a, &obj->char_b);
obj->data.diskio = prepare_diskio_stat(dev_name(buf));
if (buf) free(buf);
parse_diskiograph_arg(obj, arg);
END OBJ(diskiograph_read, &update_diskio)
char *buf = 0;
SIZE_DEFAULTS(graph);
buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
&obj->e, &obj->char_a, &obj->char_b);
obj->data.diskio = prepare_diskio_stat(dev_name(buf));
if (buf) free(buf);
parse_diskiograph_arg(obj, arg);
END OBJ(diskiograph_write, &update_diskio)
char *buf = 0;
SIZE_DEFAULTS(graph);
buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
&obj->e, &obj->char_a, &obj->char_b);
obj->data.diskio = prepare_diskio_stat(dev_name(buf));
if (buf) free(buf);
parse_diskiograph_arg(obj, arg);
#endif /* X11 */
END OBJ(color, 0)
#ifdef X11

View File

@ -30,9 +30,12 @@
#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>
@ -106,6 +109,69 @@ 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
*/
void print_diskio(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;
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);
}
#ifdef X11
void parse_diskiograph_arg(struct text_object *obj, const char *arg)
{
char *buf = 0;
SIZE_DEFAULTS(graph);
buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
&obj->e, &obj->char_a, &obj->char_b);
obj->data.opaque = prepare_diskio_stat(dev_name(buf));
if (buf)
free(buf);
}
void print_diskiograph(struct text_object *obj, int dir, char *p)
{
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;
new_graph(p, obj->a, obj->b, obj->c, obj->d,
val, obj->e, 1, obj->char_a, obj->char_b);
}
#endif /* X11 */
void update_diskio_values(struct diskio_stat *ds,
unsigned int reads, unsigned int writes)
{

View File

@ -51,4 +51,11 @@ void update_diskio(void);
void clear_diskio_stats(void);
void update_diskio_values(struct diskio_stat *, unsigned int, unsigned int);
void parse_diskio_arg(struct text_object *, const char *);
void print_diskio(struct text_object *, int, char *, int);
#ifdef X11
void parse_diskiograph_arg(struct text_object *, const char *);
void print_diskiograph(struct text_object *, int, char *);
#endif /* X11 */
#endif /* DISKIO_H_ */

View File

@ -444,7 +444,6 @@ struct text_object {
long l; /* some other integer */
unsigned int sensor;
struct net_stat *net;
struct diskio_stat *diskio;
unsigned char loadavg[3];
unsigned int cpu_index;
struct mail_s *mail;