~ubuntu-branches/ubuntu/wily/wmsysmon/wily-proposed

« back to all changes in this revision

Viewing changes to .pc/break.patch/src/wmsysmon.c

  • Committer: Package Import Robot
  • Author(s): Doug Torrance
  • Date: 2015-07-12 10:43:06 UTC
  • Revision ID: package-import@ubuntu.com-20150712104306-350lv0jwoyecd67d
Tags: 0.7.7-8
* New maintainer (Closes: #792213).
* debian/compat
  - Bump to 9.
* debian/control
  - Tidy using wrap-and-sort.
  - Bump versioned dependency on debhelper to >= 9.
  - Remove dpatch from Build-Depends.
  - Bump Standards-Version to 3.9.6.
  - Add Homepage and Vcs-*.
  - Lengthen Description.
* debian/copyright
  - Convert to DEP5 format.
* debian/manpages
  - New file.
* debian/patches/{break,output,src_makefile,makefile-strip}.patch
  - Rename from 01-break.dpatch, 02-output.dpatch, 03-src_makefile.dpatch,
    and 04-makefile.dpatch.
  - Convert patches from dpatch to quilt
  - Add DEP3 headers.
* debian/patches/makefile-strip.patch
  - Patch src/Makefile and not Makefile; the latter does not exist in the
    .orig tarball.
* debian/patches/unused-{but-set-variable,result}.patch
  - New patches; fix compiler warnings.
* debian/rules
  - Update to use dh.
* debian/source/format
  - New file; use 3.0 (quilt).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        wmsysmon -- system monitoring dockapp
 
3
 
 
4
        Copyright (C) 1998-1999 Dave Clark - clarkd@skynet.ca
 
5
        Copyright (C) 2000 Vito Caputo - swivel@gnugeneration.com
 
6
 
 
7
        wmsysmon is free software; you can redistribute it and/or modify
 
8
        it under the terms of the GNU General Public License as published by
 
9
        the Free Software Foundation; either version 2 of the License, or
 
10
        (at your option) any later version.
 
11
 
 
12
        wmsysmon is distributed in the hope that it will be useful,
 
13
        but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
        GNU General Public License for more details.
 
16
 
 
17
        You should have received a copy of the GNU General Public License
 
18
        along with this program; if not, write to the Free Software
 
19
        Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
20
*/
 
21
 
 
22
#include <stdlib.h>
 
23
#include <stdio.h>
 
24
#include <time.h>
 
25
#include <string.h>
 
26
#include <fcntl.h>
 
27
#include <unistd.h>
 
28
#include <ctype.h>
 
29
#include <math.h>
 
30
#include <sys/poll.h>
 
31
#include <sys/wait.h>
 
32
#include <sys/stat.h>
 
33
#include <sys/param.h>
 
34
#include <sys/types.h>
 
35
#include <sys/ioctl.h>
 
36
#include <sys/time.h>
 
37
#include <X11/Xlib.h>
 
38
#include <X11/xpm.h>
 
39
#include <X11/extensions/shape.h>
 
40
 
 
41
 
 
42
#include "wmgeneral.h"
 
43
 
 
44
#ifdef HI_INTS
 
45
#include "wmsysmon-master-alpha.xpm"
 
46
#else
 
47
#include "wmsysmon-master-i386.xpm"
 
48
#endif
 
49
 
 
50
#define WMSYSMON_VERSION "0.7.7"
 
51
 
 
52
#define CHAR_WIDTH 5
 
53
#define CHAR_HEIGHT 7
 
54
 
 
55
#define BCHAR_WIDTH 6
 
56
#define BCHAR_HEIGHT 9
 
57
 
 
58
#define BOFFX   (93)
 
59
#define BOFFY   (66)
 
60
#define BREDX   (81)
 
61
#define BREDY   (66)
 
62
#define BGREENX (87)
 
63
#define BGREENY (66)
 
64
 
 
65
#define LITEW   (4)
 
66
#define LITEH   (4)
 
67
 
 
68
#define B_OFF   (0)
 
69
#define B_RED   (1)
 
70
#define B_GREEN (2)
 
71
 
 
72
/* meter definitions */
 
73
#define VBAR_W  (4)
 
74
#define VBAR_H  (4)
 
75
 
 
76
#define INT_LITES       (1)
 
77
#define INT_METERS      (2)
 
78
 
 
79
char    wmsysmon_mask_bits[64*64];
 
80
int     wmsysmon_mask_width = 64;
 
81
int     wmsysmon_mask_height = 64;
 
82
 
 
83
long    start_time = 0;
 
84
long    start_uptime = 0;
 
85
int     counter = 0;
 
86
int     Mem_l; /* line in /proc/meminfo "Mem:" is on */
 
87
int     Swap_l; /* line in /proc/meminfo "Swap:" is on */
 
88
int     intr_l; /* line in /proc/stat "intr" is on */
 
89
int     rio_l; /* line in /proc/stat "disk_rio" is on */
 
90
int     wio_l; /* line in /proc/stat "disk_wio" is on */
 
91
int     page_l; /* line in /proc/stat "page" is on */
 
92
int     swap_l; /* line in /proc/stat "swap" is on */
 
93
 
 
94
long    io_max;
 
95
long    io_max_diff;
 
96
 
 
97
int     meter[4][2];
 
98
 
 
99
#ifdef HI_INTS
 
100
long    _last_ints[24];
 
101
long    _ints[24];
 
102
int     int_peaks[24];
 
103
#else
 
104
long    _last_ints[16];
 
105
long    _ints[16];
 
106
int     int_peaks[16];
 
107
#endif
 
108
long    *last_ints;
 
109
long    *ints;
 
110
long    int_mode = INT_METERS;
 
111
 
 
112
long    last_pageins=0;
 
113
long    last_pageouts=0;
 
114
 
 
115
long    last_swapins=0;
 
116
long    last_swapouts=0;
 
117
 
 
118
char    buf[1024];
 
119
FILE    *statfp;
 
120
FILE    *memfp;
 
121
 
 
122
int     update_rate = 50;
 
123
 
 
124
char    *ProgName;
 
125
 
 
126
time_t  curtime;
 
127
time_t  prevtime;
 
128
 
 
129
 
 
130
void usage(void);
 
131
void printversion(void);
 
132
void BlitString(char *name, int x, int y);
 
133
void BlitNum(int num, int x, int y);
 
134
void wmsysmon_routine(int, char **);
 
135
void DrawBar(int sx, int sy, int w, int h, float percent, int dx, int dy);
 
136
void DrawLite(int state, int dx, int dy);
 
137
void DrawUptime(void);
 
138
void DrawStuff( void );
 
139
void DrawMem( void );
 
140
void DrawMeter(unsigned int, unsigned int, int, int);
 
141
 
 
142
int main(int argc, char *argv[]) {
 
143
        int     i;
 
144
 
 
145
        /* set meter x,y pairs */
 
146
        meter[3][0] = 108;
 
147
        meter[3][1] = 66;
 
148
        meter[2][0] = 116;
 
149
        meter[2][1] = 66;
 
150
        meter[1][0] = 124;
 
151
        meter[1][1] = 66;
 
152
        meter[0][0] = 132;
 
153
        meter[0][1] = 66;
 
154
 
 
155
        last_ints = _last_ints;
 
156
        ints = _ints;
 
157
    
 
158
        /* Parse Command Line */
 
159
 
 
160
        ProgName = argv[0];
 
161
        if (strlen(ProgName) >= 5)
 
162
                ProgName += (strlen(ProgName) - 5);
 
163
 
 
164
        for (i = 1; i < argc; i++) {
 
165
                char *arg = argv[i];
 
166
 
 
167
                if (*arg == '-') {
 
168
                        switch (arg[1]) {
 
169
                        case 'd':
 
170
                                if (strcmp(arg + 1, "display")) {
 
171
                                        usage();
 
172
                                        exit(1);
 
173
                                }
 
174
                                break;
 
175
                        case 'g':
 
176
                                if (strcmp(arg+1, "geometry")) {
 
177
                                        usage();
 
178
                                        exit(1);
 
179
                                }
 
180
                                break;
 
181
                        case 'v':
 
182
                                printversion();
 
183
                                exit(0);
 
184
                                break;
 
185
                        case 'r':
 
186
                                if (argc > (i + 1)) {
 
187
                                        update_rate = (atoi(argv[i + 1]));
 
188
                                        i++;
 
189
                                }
 
190
                                break;
 
191
                        case 'l':
 
192
                                int_mode = INT_LITES;
 
193
                                break;
 
194
 
 
195
                        default:
 
196
                                usage();
 
197
                                exit(0);
 
198
                                break;
 
199
                        }
 
200
                }
 
201
        }
 
202
 
 
203
        wmsysmon_routine(argc, argv);
 
204
 
 
205
 
 
206
        return 0;
 
207
}
 
208
 
 
209
 
 
210
void wmsysmon_routine(int argc, char **argv)
 
211
{
 
212
        int             i;
 
213
        XEvent          Event;
 
214
        FILE            *fp;
 
215
        int             xfd;
 
216
        struct pollfd   pfd;
 
217
    
 
218
 
 
219
        createXBMfromXPM(wmsysmon_mask_bits, wmsysmon_master_xpm, wmsysmon_mask_width, wmsysmon_mask_height);
 
220
    
 
221
        xfd = openXwindow(argc, argv, wmsysmon_master_xpm, wmsysmon_mask_bits, wmsysmon_mask_width, wmsysmon_mask_height);
 
222
        if(xfd < 0) exit(1);
 
223
 
 
224
        pfd.fd = xfd;
 
225
        pfd.events = (POLLIN);
 
226
 
 
227
    /* init ints */
 
228
        bzero(&_last_ints, sizeof(_last_ints));
 
229
        bzero(&_ints, sizeof(_ints));
 
230
        bzero(&int_peaks, sizeof(int_peaks));
 
231
 
 
232
    
 
233
    /* init uptime */
 
234
        fp = fopen("/proc/uptime", "r");
 
235
        if (fp) {
 
236
                fscanf(fp, "%ld", &start_time);
 
237
                fclose(fp);
 
238
                start_uptime = time(NULL);
 
239
        }
 
240
 
 
241
        statfp = fopen("/proc/stat", "r");
 
242
        memfp = fopen("/proc/meminfo", "r");
 
243
 
 
244
        /* here we find tags in /proc/stat & /proc/meminfo and note their
 
245
         * lines, for faster lookup throughout execution.
 
246
         */
 
247
        /* /proc/meminfo */
 
248
        for(i = 0; fgets(buf, 1024, memfp); i++) {
 
249
                if(strstr(buf, "Mem:")) Mem_l = i;
 
250
                else if(strstr(buf, "Swap:")) Swap_l = i;
 
251
        }
 
252
 
 
253
        /* /proc/stat */
 
254
        for(i = 0; fgets(buf, 1024, statfp); i++) {
 
255
                if(strstr(buf, "disk_wio")) wio_l = i;
 
256
                else if(strstr(buf, "disk_rio")) rio_l = i;
 
257
                else if(strstr(buf, "page")) page_l = i;
 
258
                else if(strstr(buf, "swap")) swap_l = i;
 
259
                else if(strstr(buf, "intr")) intr_l = i;
 
260
        }
 
261
 
 
262
        while(1) {
 
263
        
 
264
                curtime = time(0);
 
265
 
 
266
                DrawUptime();
 
267
                DrawStuff();
 
268
                DrawMem();
 
269
                RedrawWindow();
 
270
        
 
271
                /* X Events */
 
272
                poll(&pfd, 1, update_rate);
 
273
                while (XPending(display)) {
 
274
                        XNextEvent(display, &Event);
 
275
                        switch (Event.type) {
 
276
                        case Expose:
 
277
                                DirtyWindow(Event.xexpose.x,
 
278
                                            Event.xexpose.y,
 
279
                                            Event.xexpose.width,
 
280
                                            Event.xexpose.height);
 
281
                                break;
 
282
                        case DestroyNotify:
 
283
                                XCloseDisplay(display);
 
284
                                exit(0);
 
285
                                break;
 
286
 
 
287
                        default:
 
288
#ifdef MONDEBUG
 
289
                                printf("got: %i\n", Event.type);
 
290
#endif
 
291
                        }
 
292
                }
 
293
 
 
294
/*              usleep(update_rate); */
 
295
        }
 
296
}
 
297
 
 
298
 
 
299
void DrawMeter(unsigned int level, unsigned int peak, int dx, int dy)
 
300
{
 
301
        static unsigned int     a;
 
302
 
 
303
        /* meters are on a per interruptscale, dictated by the peak, maintain
 
304
         * this peak outside of here, you can use a fixed peak for all ints but
 
305
         * since we're using only 4 lines for our level, the timer interrupt
 
306
         * usually kills the peak for the others so they never move. */
 
307
 
 
308
        if(peak) {
 
309
                a = level * 3 / peak;
 
310
        } else a = 0;
 
311
 
 
312
#ifdef MONDEBUG
 
313
        printf("level: %u peak: %u selection: %u\n", level, peak, a);
 
314
        fflush(stdout);
 
315
#endif
 
316
 
 
317
        if(a > 3) a = 3;
 
318
 
 
319
        copyXPMArea(meter[a][0],
 
320
                    meter[a][1],
 
321
                    VBAR_W,
 
322
                    VBAR_H,
 
323
                    dx,
 
324
                    dy);
 
325
}
 
326
 
 
327
 
 
328
 
 
329
void DrawBar(int sx, int sy, int w, int h, float percent, int dx, int dy)
 
330
{
 
331
        static int      tx;
 
332
 
 
333
        tx = (float)((float)w * ((float)percent / (float)100.0));
 
334
 
 
335
        copyXPMArea(sx, sy, tx, h, dx, dy);
 
336
 
 
337
        copyXPMArea(sx, sy + h + 1, w - tx, h, dx + tx, dy);
 
338
 
 
339
}
 
340
 
 
341
 
 
342
void DrawLite(int state, int dx, int dy)
 
343
{
 
344
 
 
345
        switch(state) {
 
346
                case B_RED:
 
347
                        copyXPMArea(BREDX, BREDY, LITEW, LITEH, dx, dy);
 
348
                        break;
 
349
                case B_GREEN:
 
350
                        copyXPMArea(BGREENX, BGREENY, LITEW, LITEH, dx, dy);
 
351
                        break;
 
352
                default:
 
353
                case B_OFF:
 
354
                        copyXPMArea(BOFFX, BOFFY, LITEW, LITEH, dx, dy);
 
355
                        break;
 
356
        }
 
357
 
 
358
}
 
359
 
 
360
 
 
361
void DrawUptime(void)
 
362
{
 
363
        static int      first = 1;
 
364
        static int      old_days = 0, old_hours = 0, old_minutes = 0;
 
365
        static long     uptime;
 
366
        static int      i;
 
367
 
 
368
    
 
369
        uptime = curtime - start_uptime + start_time;
 
370
 
 
371
        /* blit minutes */
 
372
        uptime /=60;
 
373
        i = uptime % 60;
 
374
 
 
375
        if(old_minutes != i || first) {
 
376
                old_minutes = i;
 
377
                sprintf(buf, "%02i", i);
 
378
#ifdef HI_INTS
 
379
                BlitString(buf, 45, 29);
 
380
#else
 
381
                BlitString(buf, 45, 37);
 
382
#endif
 
383
        }
 
384
    
 
385
        /* blit hours */
 
386
        uptime /=60;
 
387
        i = uptime % 24;
 
388
 
 
389
        if(old_hours != i || first) {
 
390
                old_hours = i;
 
391
                sprintf(buf, "%02i", i);
 
392
#ifdef HI_INTS
 
393
                BlitString(buf, 29, 29);
 
394
#else
 
395
                BlitString(buf, 29, 37);
 
396
#endif
 
397
        }
 
398
 
 
399
    
 
400
        /* blit days */
 
401
        uptime /= 24;
 
402
        i = uptime;
 
403
        if(old_days != i || first) {
 
404
                old_days = i;
 
405
                sprintf(buf, "%03i", i);
 
406
#ifdef HI_INTS
 
407
                BlitString(buf, 6, 29);
 
408
#else
 
409
                BlitString(buf, 6, 37);
 
410
#endif
 
411
        }
 
412
 
 
413
        first = 0;
 
414
}
 
415
 
 
416
 
 
417
void DrawStuff( void )
 
418
{
 
419
        static int      io_last = 0, first = 1;
 
420
#ifdef HI_INTS
 
421
        static int      int_lites[24] =
 
422
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
 
423
                /* to keep track of on/off status */
 
424
#else
 
425
        static int      int_lites[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
 
426
#endif
 
427
        static int      pagein_lite = 0, pageout_lite = 0, swapin_lite = 0, swapout_lite = 0;
 
428
        static char     *tok;
 
429
        static char     seps[] = {" "};
 
430
        static int      i, ents;
 
431
 
 
432
        static long     io;
 
433
        static long     iodiff;
 
434
        static int      iopercent;
 
435
 
 
436
        static long     pageins;
 
437
        static long     pageouts;
 
438
        static long     swapins;
 
439
        static long     swapouts;
 
440
        static long     intdiff;
 
441
        static long     stage;
 
442
        static long     *tints;
 
443
 
 
444
        stage = io = iodiff = iopercent = pageins = pageouts = swapins = swapouts = 0;
 
445
 
 
446
        statfp = freopen("/proc/stat", "r", statfp);
 
447
 
 
448
 
 
449
        for(i = 0, ents = 0; ents < 5 && fgets(buf, 1024, statfp); i++) {
 
450
                if(i == rio_l) {
 
451
                        tok = strtok(buf, seps);
 
452
 
 
453
                        io += atoi(tok);
 
454
                        tok = strtok(NULL, seps);
 
455
 
 
456
                        io += atoi(tok);
 
457
                        tok = strtok(NULL, seps);
 
458
 
 
459
                        io += atoi(tok);
 
460
                        tok = strtok(NULL, seps);
 
461
 
 
462
                        io += atoi(tok);
 
463
                        tok = strtok(NULL, seps);
 
464
                        ents++;
 
465
                } else if(i == wio_l) {
 
466
                        tok = strtok(buf, seps);
 
467
 
 
468
                        io += atoi(tok);
 
469
                        tok = strtok(NULL, seps);
 
470
 
 
471
                        io += atoi(tok);
 
472
                        tok = strtok(NULL, seps);
 
473
 
 
474
                        io += atoi(tok);
 
475
                        tok = strtok(NULL, seps);
 
476
 
 
477
                        io += atoi(tok);
 
478
                        tok = strtok(NULL, seps);
 
479
                        ents++;
 
480
                } else if(i == page_l) {
 
481
                        sscanf(buf, "%*s %ld %ld", &pageins, &pageouts);
 
482
                        ents++;
 
483
                } else if(i == swap_l) {
 
484
                        sscanf(buf, "%*s %ld %ld",
 
485
                                &swapins, &swapouts);
 
486
                        ents++;
 
487
                } else if(i == intr_l) {
 
488
                        sscanf( buf,
 
489
        #ifdef HI_INTS
 
490
                                "%*s %*d %ld %ld %ld %ld %ld"
 
491
                                "%ld %ld %ld %ld %ld %ld %ld"
 
492
                                "%ld %ld %ld %ld %ld %ld %ld"
 
493
                                "%ld %ld %ld %ld %ld",
 
494
                                &ints[0], &ints[1], &ints[2],
 
495
                                &ints[3], &ints[4], &ints[5],
 
496
                                &ints[6], &ints[7], &ints[8],
 
497
                                &ints[9], &ints[10], &ints[11],
 
498
                                &ints[12], &ints[13], &ints[14],
 
499
                                &ints[15], &ints[16], &ints[17],
 
500
                                &ints[18], &ints[19], &ints[20],
 
501
                                &ints[21], &ints[22], &ints[23]);
 
502
        #else
 
503
                                "%*s %*d %ld %ld %ld %ld %ld"
 
504
                                "%ld %ld %ld %ld %ld %ld %ld"
 
505
                                "%ld %ld %ld %ld",
 
506
                                &ints[0], &ints[1], &ints[2],
 
507
                                &ints[3], &ints[4], &ints[5],
 
508
                                &ints[6], &ints[7], &ints[8],
 
509
                                &ints[9], &ints[10], &ints[11],
 
510
                                &ints[12], &ints[13], &ints[14],
 
511
                                &ints[15]);
 
512
        #endif
 
513
                        ents++;
 
514
                }
 
515
        }
 
516
 
 
517
 
 
518
        /* ------------------ IO bar ------------------ */
 
519
        if(io_max == 0) io_max = io;
 
520
    
 
521
        if(io > io_max) iodiff = abs(io_max - io);
 
522
        else iodiff = 0;
 
523
 
 
524
        io_max = io;
 
525
 
 
526
    
 
527
        if(io_max_diff !=0) iopercent = ((float) iodiff / (float) io_max_diff) * 100.0;
 
528
        else iopercent = 0;
 
529
 
 
530
        if(iodiff > io_max_diff) io_max_diff = iodiff;
 
531
 
 
532
        if (iopercent > 100) iopercent = 100;
 
533
    
 
534
 
 
535
        if(iopercent != io_last || first) {
 
536
                io_last = iopercent;
 
537
#ifdef HI_INTS
 
538
                DrawBar(67, 36, 58, 4, iopercent, 3, 20);
 
539
#else
 
540
                DrawBar(67, 36, 58, 6, iopercent, 3, 26);
 
541
#endif
 
542
        }
 
543
 
 
544
 
 
545
        if(int_mode == INT_LITES) {
 
546
                /* top 8 ints */
 
547
                for (i = 0; i < 8; i++) {
 
548
                        if ( ints[i] > last_ints[i] && !int_lites[i]) {
 
549
                                int_lites[i] = 1;
 
550
#ifdef HI_INTS
 
551
                                DrawLite(B_GREEN, 4 + (i * LITEW) + i, 43);
 
552
#else
 
553
                                DrawLite(B_GREEN, 4 + (i * LITEW) + i, 51);
 
554
#endif
 
555
                        } else if(ints[i] == last_ints[i] && int_lites[i]) {
 
556
                                int_lites[i] = 0;
 
557
#ifdef HI_INTS
 
558
                                DrawLite(B_OFF, 4 + (i * LITEW) + i, 43);
 
559
#else
 
560
                                DrawLite(B_OFF, 4 + (i * LITEW) + i, 51);
 
561
#endif
 
562
                        }
 
563
                }
 
564
                /* middle/bottom 8 */
 
565
                for (i = 8; i < 16; i++) {
 
566
                        if ( ints[i] > last_ints[i] && !int_lites[i]) {
 
567
                                int_lites[i] = 1;
 
568
#ifdef HI_INTS
 
569
                                DrawLite(B_GREEN, 4 + ((i - 8) *LITEW) + (i - 8), 48);
 
570
#else
 
571
                                DrawLite(B_GREEN, 4 + ((i - 8) *LITEW) + (i - 8), 56);
 
572
#endif
 
573
                        } else if(ints[i] == last_ints[i] && int_lites[i]) {
 
574
                                int_lites[i] = 0;
 
575
#ifdef HI_INTS
 
576
                                DrawLite(B_OFF, 4 + ((i - 8) * LITEW) + (i - 8), 48);
 
577
#else
 
578
                                DrawLite(B_OFF, 4 + ((i - 8) * LITEW) + (i - 8), 56);
 
579
#endif
 
580
                        }
 
581
                }
 
582
 
 
583
#ifdef HI_INTS
 
584
                /* bottom 8 on alpha/smp x86 */
 
585
                for (i = 16; i < 24; i++) {
 
586
                        if (ints[i] > last_ints[i] && !int_lites[i] ) {
 
587
                                int_lites[i] = 1;
 
588
                                DrawLite(B_GREEN, 4 + ((i - 16) * LITEW) + (i - 16), 53);
 
589
                        } else if(ints[i] == last_ints[i] && int_lites[i]) {
 
590
                                int_lites[i] = 0;
 
591
                                DrawLite(B_OFF, 4 + ((i -16) * LITEW) + (i - 16), 53);
 
592
                        }
 
593
                }
 
594
#endif
 
595
        } else if(int_mode == INT_METERS) {
 
596
                for (i = 0; i < 8; i++) {
 
597
                        if(last_ints[i]) {
 
598
                                intdiff = ints[i] - last_ints[i];
 
599
                                int_peaks[i] = (int_peaks[i] + intdiff) >> 1;
 
600
#ifdef HI_INTS
 
601
                                DrawMeter(intdiff,
 
602
                                          int_peaks[i],
 
603
                                          VBAR_H + (i * VBAR_W) + i,
 
604
                                          43);
 
605
#else
 
606
                                DrawMeter(intdiff,
 
607
                                          int_peaks[i],
 
608
                                          VBAR_H + (i * VBAR_W) + i,
 
609
                                          51);
 
610
#endif
 
611
                        }
 
612
                }
 
613
 
 
614
                for (i = 8; i < 16; i++) {
 
615
                        if(last_ints[i]) {
 
616
                                intdiff = ints[i] - last_ints[i];
 
617
                                int_peaks[i] = (int_peaks[i] + intdiff) >> 1;
 
618
#ifdef HI_INTS
 
619
                                DrawMeter(intdiff,
 
620
                                          int_peaks[i],
 
621
                                          VBAR_H + ((i - 8) * VBAR_W) + (i - 8),
 
622
                                          48);
 
623
#else
 
624
                                DrawMeter(intdiff,
 
625
                                          int_peaks[i],
 
626
                                          VBAR_H + ((i - 8) * VBAR_W) + (i - 8),
 
627
                                          56);
 
628
#endif
 
629
                        }
 
630
                }
 
631
 
 
632
#ifdef HI_INTS
 
633
                for (i = 16; i < 24; i++) {
 
634
                        if(last_ints[i]) {
 
635
                                intdiff = ints[i] - last_ints[i];
 
636
                                int_peaks[i] = (int_peaks[i] + intdiff) >> 1;
 
637
 
 
638
                                DrawMeter(intdiff,
 
639
                                          int_peaks[i],
 
640
                                          VBAR_H + ((i - 16) * VBAR_W) + (i - 16),
 
641
                                          53);
 
642
                        }
 
643
                }
 
644
#endif
 
645
        }
 
646
 
 
647
        tints = last_ints;
 
648
        last_ints = ints;
 
649
        ints = tints;
 
650
 
 
651
        /* page in / out */
 
652
 
 
653
        if (pageins > last_pageins && !pagein_lite) {
 
654
                pagein_lite = 1;
 
655
#ifdef HI_INTS
 
656
                DrawLite(B_RED, 51, 43);
 
657
#else
 
658
                DrawLite(B_RED, 51, 51);
 
659
#endif
 
660
        } else if(pagein_lite) {
 
661
                pagein_lite = 0;
 
662
#ifdef HI_INTS
 
663
                DrawLite(B_OFF, 51, 43);
 
664
#else
 
665
                DrawLite(B_OFF, 51, 51);
 
666
#endif
 
667
        }
 
668
 
 
669
        if (pageouts > last_pageouts && !pageout_lite) {
 
670
                pageout_lite = 1;
 
671
#ifdef HI_INTS
 
672
                DrawLite(B_RED, 56, 43);
 
673
#else
 
674
                DrawLite(B_RED, 56, 51);
 
675
#endif
 
676
        } else if(pageout_lite) {
 
677
                pageout_lite = 0;
 
678
#ifdef HI_INTS
 
679
                DrawLite(B_OFF, 56, 43);
 
680
#else
 
681
                DrawLite(B_OFF, 56, 51);
 
682
#endif
 
683
        }
 
684
 
 
685
        last_pageins = pageins;
 
686
        last_pageouts = pageouts;
 
687
 
 
688
        /* swap in/out */
 
689
 
 
690
        if(swapins > last_swapins && !swapin_lite) {
 
691
                swapin_lite = 1;
 
692
#ifdef HI_INTS
 
693
                DrawLite(B_RED, 51, 48);
 
694
#else
 
695
                DrawLite(B_RED, 51, 56);
 
696
#endif
 
697
        } else if(swapin_lite) {
 
698
                swapin_lite = 0;
 
699
#ifdef HI_INTS
 
700
                DrawLite(B_OFF, 51, 48);
 
701
#else
 
702
                DrawLite(B_OFF, 51, 56);
 
703
#endif
 
704
        }
 
705
 
 
706
        if (swapouts > last_swapouts && !swapout_lite) {
 
707
                swapout_lite = 1;
 
708
#ifdef HI_INTS
 
709
                DrawLite(B_RED, 56, 48);
 
710
#else
 
711
                DrawLite(B_RED, 56, 56);
 
712
#endif
 
713
        } else if(swapout_lite) {
 
714
                swapout_lite = 0;
 
715
#ifdef HI_INTS
 
716
                DrawLite(B_OFF, 56, 48);
 
717
#else
 
718
                DrawLite(B_OFF, 56, 56);
 
719
#endif
 
720
        }
 
721
 
 
722
        last_swapins = swapins;
 
723
        last_swapouts = swapouts;
 
724
 
 
725
        first = 0;
 
726
 
 
727
}
 
728
 
 
729
 
 
730
void DrawMem(void)
 
731
{
 
732
        static int      last_mem = 0, last_swap = 0, first = 1;
 
733
        static long     mem_total = 0;
 
734
        static long     mem_used = 0;
 
735
        static long     mem_buffers = 0;
 
736
        static long     mem_cache = 0;
 
737
        static long     swap_total = 0;
 
738
        static long     swap_used = 0;
 
739
        static long     swap_free = 0;
 
740
 
 
741
        static int      mempercent = 0;
 
742
        static int      swappercent = 0;
 
743
        static int      i, ents;
 
744
 
 
745
 
 
746
        counter--;
 
747
 
 
748
        if(counter >= 0) return; /* polling /proc/meminfo is EXPENSIVE */
 
749
        counter = 3000000 / update_rate;
 
750
 
 
751
        memfp = freopen("/proc/meminfo", "r", memfp);
 
752
 
 
753
        for(i = 0, ents = 0; ents < 2 && fgets(buf, 1024, memfp); i++) {
 
754
                if(i == Mem_l) {
 
755
                        sscanf(buf, "%*s %ld %ld %*d %*d %ld %ld",
 
756
                                &mem_total,
 
757
                                &mem_used,
 
758
                                &mem_buffers,
 
759
                                &mem_cache);
 
760
                        ents++;
 
761
                } else if(i == Swap_l) {
 
762
                        sscanf(buf, "%*s %ld %ld %ld",
 
763
                                &swap_total,
 
764
                                &swap_used,
 
765
                                &swap_free);
 
766
                        ents++;
 
767
                }
 
768
        }
 
769
 
 
770
        /* could speed this up but we'd lose precision, look more into it to see
 
771
         * if precision change would be noticable, and if speed diff is significant
 
772
         */
 
773
        mempercent = ((float)(mem_used - mem_buffers - mem_cache)
 
774
                     /
 
775
                     (float)mem_total) * 100;
 
776
 
 
777
        swappercent = ((float)(swap_used)
 
778
                      /
 
779
                      (float)swap_total) * 100;
 
780
 
 
781
        if(mempercent != last_mem || first) {
 
782
                last_mem = mempercent;
 
783
#ifdef HI_INTS
 
784
                DrawBar(67, 36, 58,4 , mempercent, 3, 4);
 
785
#else
 
786
                DrawBar(67, 36, 58, 6, mempercent, 3, 4);
 
787
#endif
 
788
        }
 
789
            
 
790
        if(swappercent != last_swap || first) {
 
791
                last_swap = swappercent;
 
792
#ifdef HI_INTS
 
793
                DrawBar(67, 36, 58, 4, swappercent, 3, 12);
 
794
#else
 
795
                DrawBar(67, 36, 58, 6, swappercent, 3, 15);
 
796
#endif
 
797
        }
 
798
 
 
799
        first = 0;
 
800
 
 
801
}
 
802
 
 
803
 
 
804
/* Blits a string at given co-ordinates */
 
805
void BlitString(char *name, int x, int y)
 
806
{
 
807
        static int      i, c, k;
 
808
 
 
809
        k = x;
 
810
        for (i=0; name[i]; i++) {
 
811
 
 
812
                c = toupper(name[i]); 
 
813
                if (c >= 'A' && c <= 'Z') {
 
814
                        c -= 'A';
 
815
                        copyXPMArea(c * 6, 74, 6, 8, k, y);
 
816
                        k += 6;
 
817
                } else {
 
818
                        c -= '0';
 
819
                        copyXPMArea(c * 6, 64, 6, 8, k, y);
 
820
                        k += 6;
 
821
                }
 
822
        }
 
823
 
 
824
}
 
825
 
 
826
 
 
827
void BlitNum(int num, int x, int y)
 
828
{
 
829
        static int      newx;
 
830
 
 
831
 
 
832
        newx = x;
 
833
 
 
834
        sprintf(buf, "%03i", num);
 
835
 
 
836
        BlitString(buf, newx, y);
 
837
 
 
838
}
 
839
    
 
840
 
 
841
void usage(void)
 
842
{
 
843
        fprintf(stderr, "\nwmsysmon - http://www.gnugeneration.com\n");
 
844
        fprintf(stderr, "\n-------------------\n"
 
845
                        "|[---------------]|  <--- Memory Use %%\n"
 
846
                        "|[---------------]|  <--- Swap Use %%\n"
 
847
                        "|[---------------]|  <--- I/O %%\n"
 
848
                        "|                 |\n"
 
849
                        "|   000:00:00     |  <--- Uptime days:hours:minutes\n"
 
850
                        "|                 |\n"
 
851
#ifdef HI_INTS
 
852
                        "| 01234567   UV   |  <--- 0-N are hardware interrupts 0-23\n"
 
853
                        "| 89ABCDEF   WX   |  <--- U,V are Page IN/OUT, W,X are Swap IN/OUT\n"
 
854
                        "| GHIJKLMN   YZ   |\n"
 
855
#else
 
856
                        "| 01234567   WX   |  <--- 0-F are hardware interrupts 0-15\n"
 
857
                        "| 89ABCDEF   YZ   |  <--- W,X are Page IN/OUT, W,X are Swap IN/OUT\n"
 
858
#endif
 
859
                        "-------------------\n");
 
860
 
 
861
        fprintf(stderr, "usage:\n");
 
862
        fprintf(stderr, "\t-display <display name>\n");
 
863
        fprintf(stderr, "\t-geometry +XPOS+YPOS\tinitial window position\n");
 
864
        fprintf(stderr, "\t-r\t\t\tupdate rate in milliseconds (default:300)\n");
 
865
        fprintf(stderr, "\t-l\t\t\tblinky lights for interrupts vs. meters(default)\n");
 
866
        fprintf(stderr, "\t-h\t\t\tthis help screen\n");
 
867
        fprintf(stderr, "\t-v\t\t\tprint the version number\n");
 
868
        fprintf(stderr, "\n");
 
869
}
 
870
 
 
871
 
 
872
void printversion(void)
 
873
{
 
874
        fprintf(stderr, "wmsysmon v%s\n", WMSYSMON_VERSION);
 
875
}