mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-28 09:38:38 +00:00
Replaces commit 44e3708cdb204782d728ddd6a40dec230bb9299c
Thanks to ichelm610x for the patch. I just added memoization to reduce the impact of the many system calls. (cherry picked from commit 1eedf2633bfe822d80f6215d53730de473207f25)
This commit is contained in:
parent
80c56d099e
commit
b1b91c80fa
50
src/linux.cc
50
src/linux.cc
@ -2272,6 +2272,49 @@ void print_disk_protect_queue(struct text_object *obj, char *p, int p_max_size)
|
|||||||
snprintf(p, p_max_size, (state > 0) ? "frozen" : "free ");
|
snprintf(p, p_max_size, (state > 0) ? "frozen" : "free ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct DEV_LIST_TYPE
|
||||||
|
{
|
||||||
|
char *dev_name;
|
||||||
|
int memoized;
|
||||||
|
struct DEV_LIST_TYPE *next;
|
||||||
|
|
||||||
|
} DEV_LIST, *DEV_LIST_PTR;
|
||||||
|
|
||||||
|
/* Same as sf #2942117 but memoized using a linked list */
|
||||||
|
int is_disk(char *dev)
|
||||||
|
{
|
||||||
|
char syspath[PATH_MAX];
|
||||||
|
char *slash;
|
||||||
|
static DEV_LIST_PTR dev_head = NULL;
|
||||||
|
DEV_LIST_PTR dev_cur, dev_last;
|
||||||
|
|
||||||
|
dev_cur = dev_head;
|
||||||
|
|
||||||
|
while (dev_cur) {
|
||||||
|
if (strcmp(dev_cur->dev_name, dev) == 0)
|
||||||
|
return dev_cur->memoized;
|
||||||
|
dev_last = dev_cur;
|
||||||
|
dev_cur = dev_cur->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
dev_cur = (DEV_LIST_PTR)malloc(sizeof(DEV_LIST));
|
||||||
|
dev_cur->dev_name = (char *)malloc((strlen(dev)+1)*sizeof(char));
|
||||||
|
strcpy(dev_cur->dev_name,dev);
|
||||||
|
dev_cur->next = NULL;
|
||||||
|
|
||||||
|
while ((slash = strchr(dev, '/')))
|
||||||
|
*slash = '!';
|
||||||
|
snprintf(syspath, sizeof(syspath), "/sys/block/%s", dev);
|
||||||
|
dev_cur->memoized = !(access(syspath, F_OK));
|
||||||
|
|
||||||
|
if (dev_head)
|
||||||
|
dev_last->next = dev_cur;
|
||||||
|
else
|
||||||
|
dev_head = dev_cur;
|
||||||
|
|
||||||
|
return dev_cur->memoized;
|
||||||
|
}
|
||||||
|
|
||||||
void update_diskio(void)
|
void update_diskio(void)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
@ -2282,7 +2325,6 @@ void update_diskio(void)
|
|||||||
struct diskio_stat *cur;
|
struct diskio_stat *cur;
|
||||||
unsigned int reads, writes;
|
unsigned int reads, writes;
|
||||||
unsigned int total_reads = 0, total_writes = 0;
|
unsigned int total_reads = 0, total_writes = 0;
|
||||||
size_t len_devbuf;
|
|
||||||
|
|
||||||
stats.current = 0;
|
stats.current = 0;
|
||||||
stats.current_read = 0;
|
stats.current_read = 0;
|
||||||
@ -2303,10 +2345,8 @@ void update_diskio(void)
|
|||||||
* XXX: ignore devices which are part of a SW RAID (MD_MAJOR) */
|
* XXX: ignore devices which are part of a SW RAID (MD_MAJOR) */
|
||||||
if (col_count == 5 && major != LVM_BLK_MAJOR && major != NBD_MAJOR
|
if (col_count == 5 && major != LVM_BLK_MAJOR && major != NBD_MAJOR
|
||||||
&& major != RAMDISK_MAJOR && major != LOOP_MAJOR) {
|
&& major != RAMDISK_MAJOR && major != LOOP_MAJOR) {
|
||||||
/* If the last character of the device is a digit we assume
|
/* check needed for kernel >= 2.6.31, see sf #2942117 */
|
||||||
* it is a subdevice (needed for kernel > 2.6.31) */
|
if (is_disk(devbuf)) {
|
||||||
len_devbuf = strlen(devbuf);
|
|
||||||
if ((len_devbuf > 0) && !isdigit(devbuf[len_devbuf-1])) {
|
|
||||||
total_reads += reads;
|
total_reads += reads;
|
||||||
total_writes += writes;
|
total_writes += writes;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user