~ubuntu-branches/debian/sid/conky/sid

« back to all changes in this revision

Viewing changes to src/diskio.c

  • Committer: Bazaar Package Importer
  • Author(s): Cesare Tirabassi
  • Date: 2010-03-28 21:19:51 UTC
  • mfrom: (1.3.1 upstream) (16.1.17 lucid)
  • Revision ID: james.westby@ubuntu.com-20100328211951-ejq536k2r858srli
Tags: 1.8.0-1
* New upstream release:
  - add AF_UNIX socket support
  - fix sigsegv if config file is deleted (LP: #525926)
  - the following debian bugs are closed by this upload:
    + change automake1.10 to automake1.11 (Closes: #550929)
    + hwmon made compatible with kernels >= 2.6.31 (Closes: #556926)
    + text_buffer_size change is well documented (Closes: #519401)
    + fix diskio for not existing devices (Closes: #536557)
    + fix wrong mixer values on some systems (Closes: #540282)
    + fix minor memory leak (Closes: #566524)
    + fix some documentation error re. graphs (Closes: #564518)
    + add -p/--pause startup option (Closes: #513440)
    + fix documentation about mixer values (Closes: #538760)
* This release is based on the Ubuntu package with the following changes
  necessary for Debian (Closes: #536320):
  - change control and rules to build correctly on non-Linux arches
    (Closes: #536326)
  - updated NEWS, descriptions in control and changelog
  - change archive area to contrib
* Change priority of metapackage to extra
* My utmost thanks go to Kapil Hari Paranjape for his packaging work and to
  Luca Falavigna for being so kind to review and sponsor this release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
 
1
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
 
2
 * vim: ts=4 sw=4 noet ai cindent syntax=c
 
3
 *
2
4
 * Conky, a system monitor, based on torsmo
3
5
 *
4
6
 * Any original torsmo code is licensed under the BSD license
8
10
 * Please see COPYING for details
9
11
 *
10
12
 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
11
 
 * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
 
13
 * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
12
14
 * (see AUTHORS)
13
15
 * All rights reserved.
14
16
 *
28
30
 
29
31
#include "config.h"
30
32
#include "conky.h"      /* text_buffer_size */
 
33
#include "core.h"
31
34
#include "logging.h"
32
35
#include "diskio.h"
33
36
#include "common.h"
 
37
#include "specials.h"
 
38
#include "text_object.h"
34
39
#include <stdlib.h>
35
40
#include <limits.h>
36
41
#include <sys/stat.h>
82
87
        snprintf(stat_name, text_buffer_size, "/dev/%s", device_name);
83
88
 
84
89
        if (stat(stat_name, &sb)) {
85
 
                ERR("diskio device '%s' does not exist", s);
86
 
                return 0;
 
90
                NORM_ERR("diskio device '%s' does not exist", s);
87
91
        }
88
92
 
89
93
        /* lookup existing */
105
109
        return cur;
106
110
}
107
111
 
 
112
void parse_diskio_arg(struct text_object *obj, const char *arg)
 
113
{
 
114
        obj->data.opaque = prepare_diskio_stat(arg);
 
115
}
 
116
 
 
117
/* dir indicates the direction:
 
118
 * -1: read
 
119
 *  0: read + write
 
120
 *  1: write
 
121
 */
 
122
static void print_diskio_dir(struct text_object *obj, int dir, char *p, int p_max_size)
 
123
{
 
124
        struct diskio_stat *diskio = obj->data.opaque;
 
125
        double val;
 
126
 
 
127
        if (!diskio)
 
128
                return;
 
129
 
 
130
        if (dir < 0)
 
131
                val = diskio->current_read;
 
132
        else if (dir == 0)
 
133
                val = diskio->current;
 
134
        else
 
135
                val = diskio->current_write;
 
136
 
 
137
        /* TODO: move this correction from kB to kB/s elsewhere
 
138
         * (or get rid of it??) */
 
139
        human_readable((val / update_interval) * 1024LL, p, p_max_size);
 
140
}
 
141
 
 
142
void print_diskio(struct text_object *obj, char *p, int p_max_size)
 
143
{
 
144
        print_diskio_dir(obj, 0, p, p_max_size);
 
145
}
 
146
 
 
147
void print_diskio_read(struct text_object *obj, char *p, int p_max_size)
 
148
{
 
149
        print_diskio_dir(obj, -1, p, p_max_size);
 
150
}
 
151
 
 
152
void print_diskio_write(struct text_object *obj, char *p, int p_max_size)
 
153
{
 
154
        print_diskio_dir(obj, 1, p, p_max_size);
 
155
}
 
156
 
 
157
#ifdef X11
 
158
void parse_diskiograph_arg(struct text_object *obj, const char *arg)
 
159
{
 
160
        char *buf = 0;
 
161
        buf = scan_graph(obj, arg, 0);
 
162
 
 
163
        obj->data.opaque = prepare_diskio_stat(dev_name(buf));
 
164
        if (buf)
 
165
                free(buf);
 
166
}
 
167
 
 
168
static void print_diskiograph_dir(struct text_object *obj, int dir, char *p, int p_max_size)
 
169
{
 
170
        struct diskio_stat *diskio = obj->data.opaque;
 
171
        double val;
 
172
 
 
173
        if (!diskio)
 
174
                return;
 
175
 
 
176
        if (!p_max_size)
 
177
                return;
 
178
 
 
179
        if (dir < 0)
 
180
                val = diskio->current_read;
 
181
        else if (dir == 0)
 
182
                val = diskio->current;
 
183
        else
 
184
                val = diskio->current_write;
 
185
 
 
186
        new_graph(obj, p, p_max_size, val);
 
187
}
 
188
 
 
189
void print_diskiograph(struct text_object *obj, char *p, int p_max_size)
 
190
{
 
191
        print_diskiograph_dir(obj, 0, p, p_max_size);
 
192
}
 
193
 
 
194
void print_diskiograph_read(struct text_object *obj, char *p, int p_max_size)
 
195
{
 
196
        print_diskiograph_dir(obj, -1, p, p_max_size);
 
197
}
 
198
 
 
199
void print_diskiograph_write(struct text_object *obj, char *p, int p_max_size)
 
200
{
 
201
        print_diskiograph_dir(obj, 1, p, p_max_size);
 
202
}
 
203
#endif /* X11 */
 
204
 
108
205
void update_diskio_values(struct diskio_stat *ds,
109
206
                unsigned int reads, unsigned int writes)
110
207
{
117
214
                ds->last_read = reads;
118
215
                ds->last_write = writes;
119
216
        }
120
 
        /* since the values in /proc/diskstats are absolute, we have to substract
 
217
        /* since the values in /proc/diskstats are absolute, we have to subtract
121
218
         * our last reading. The numbers stand for "sectors read", and we therefore
122
219
         * have to divide by two to get KB */
123
220
        ds->sample_read[0] = (reads - ds->last_read) / 2;