Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 407325
Collapse All | Expand All

(-)wmmon.c (-14 / +60 lines)
Lines 106-111 int minus_buffers = 1; /* do we want to Link Here
106
FILE	*fp_meminfo;
106
FILE	*fp_meminfo;
107
FILE	*fp_stat;
107
FILE	*fp_stat;
108
FILE	*fp_loadavg;
108
FILE	*fp_loadavg;
109
FILE  *fp_diskstats;  /* wbk new io stats API */
109
110
110
/* functions */
111
/* functions */
111
void usage(void);
112
void usage(void);
Lines 231-236 void wmmon_routine(int argc, char **argv Link Here
231
	fp_meminfo = fopen("/proc/meminfo", "r");
232
	fp_meminfo = fopen("/proc/meminfo", "r");
232
	fp_loadavg = fopen("/proc/loadavg", "r");
233
	fp_loadavg = fopen("/proc/loadavg", "r");
233
	fp_stat = fopen("/proc/stat", "r");
234
	fp_stat = fopen("/proc/stat", "r");
235
  fp_diskstats = fopen("/proc/diskstats", "r");
234
236
235
	if (fp) {
237
	if (fp) {
236
		fscanf(fp, "%ld", &online_time);
238
		fscanf(fp, "%ld", &online_time);
Lines 447-453 void wmmon_routine(int argc, char **argv Link Here
447
			}
449
			}
448
		}
450
		}
449
451
450
		usleep(250000L);
452
		usleep(250000L); /* wbk - may need tweaking */
451
	}
453
	}
452
}
454
}
453
455
Lines 527-533 void update_stat_mem(stat_dev *st, stat_ Link Here
527
void get_statistics(char *devname, long *is, long *ds, long *idle) {
529
void get_statistics(char *devname, long *is, long *ds, long *idle) {
528
530
529
	int	i;
531
	int	i;
530
	char	temp[128];
532
	/*char	temp[128];*/
533
534
  static char *line = NULL;
535
  static size_t line_size = 0;
536
531
	char	*p;
537
	char	*p;
532
	char	*tokens = " \t\n";
538
	char	*tokens = " \t\n";
533
	float	f;
539
	float	f;
Lines 539-547 void get_statistics(char *devname, long Link Here
539
545
540
	if (!strncmp(devname, "cpu", 3)) {
546
	if (!strncmp(devname, "cpu", 3)) {
541
		fseek(fp_stat, 0, SEEK_SET);
547
		fseek(fp_stat, 0, SEEK_SET);
542
		while (fgets(temp, 128, fp_stat)) {
548
		while ((getline(&line, &line_size, fp_stat)) > 0) {
543
			if (strstr(temp, "cpu")) {
549
			if (strstr(line, "cpu")) {
544
				p = strtok(temp, tokens);
550
				p = strtok(line, tokens);
545
				/* 1..3, 4 == idle, we don't want idle! */
551
				/* 1..3, 4 == idle, we don't want idle! */
546
				for (i=0; i<3; i++) {
552
				for (i=0; i<3; i++) {
547
					p = strtok(NULL, tokens);
553
					p = strtok(NULL, tokens);
Lines 551-572 void get_statistics(char *devname, long Link Here
551
				*idle = atol(p);
557
				*idle = atol(p);
552
			}
558
			}
553
		}
559
		}
554
		fp_loadavg = freopen("/proc/loadavg", "r", fp_loadavg);
560
    /* wbk - fopen() might be more appropriate. */
561
		if ((fp_loadavg = freopen("/proc/loadavg", "r", fp_loadavg)) == NULL)
562
        perror("ger_statistics(): freopen(proc/loadavg) failed!\n");
555
		fscanf(fp_loadavg, "%f", &f);
563
		fscanf(fp_loadavg, "%f", &f);
556
		*is = (long) (100 * f);
564
		*is = (long) (100 * f);
557
	}
565
	}
558
566
559
	if (!strncmp(devname, "i/o", 3)) {
567
	if (!strncmp(devname, "i/o", 3)) {
568
    /* TODO: Do we need an freopen() call here? Seem to be losing
569
     * our open file, breaking graph after hibernation            */
560
570
561
		fseek(fp_stat, 0, SEEK_SET);
571
		if (fseek(fp_diskstats, 0, SEEK_SET) == -1)
562
		while (fgets(temp, 128, fp_stat)) {
572
      perror("get_statistics() seek failed\n");
563
			if (strstr(temp, "disk_rio") || strstr(temp, "disk_wio")) {
573
564
				p = strtok(temp, tokens);
574
		/*while (fgets(temp, 128, fp_diskstats)) {*/
565
				/* 1..4 */
575
		while ((getline(&line, &line_size, fp_diskstats)) > 0 ) {
566
				for (i=0; i<4; i++) {
576
      /* wbk 20120308 WORK IN PROGRESS: This is a band-aid fix to     *
577
       * restore original functionality. I think there are some       *
578
       * fundamental performance/stability issues in this whole       *
579
       * function, partly due to reliance on /procfs string parsing   *
580
       * in what I suspect is a critical loop, partly due to lack of  *
581
       * error handling. Might benefit from a rewrite, but I can't    *
582
       * invest the time needed to test such a change at the moment.  *
583
       *                                                              * 
584
      /* These are no longer in /proc/stat. /proc/diskstats seems to  *
585
       * be the closest replacement. Under modern BSD's, /proc is now *
586
       * deprecated, so iostat() might be the answer.                 */
587
      /*    http://www.gossamer-threads.com/lists/linux/kernel/314618 *
588
       * has good info on this being removed from kernel. Also see    *
589
       * kernel sources Documentation/iostats.txt                     */
590
      /*                                                              */
591
      /* do we need an freopen()? Why didn't /proc/stat/ have one?    */
592
      /* TODO: We will end up with doubled values. We are adding the  *
593
       * aggregate to the individual partition, due to device         *
594
       * selection logic. Either grab devices' stats with numbers, or *
595
       * without (sda OR sda[1..10]. Could use strstr() return plus   *
596
       * offset, but would have to be careful with bounds checking    *
597
       * since we're in a limited buffer. Or just divide by 2.        *
598
       * (inefficient). Shouldn't matter for graphing (we care about  *
599
       * proportions, not numbers.)                                   */
600
601
      /* NOTE: It seems this strstr() would occasionally fail to      *
602
       * detect its target due to buffer boundary overlap.            */
603
			if (strstr(line, "sd") || strstr(line, "sr")) {
604
				p = strtok(line, tokens);
605
				for (i=1; i<=6; i++)    /* skip 3 tokens, then use fields from*/
567
					p = strtok(NULL, tokens);
606
					p = strtok(NULL, tokens);
568
					*ds += atol(p);
607
        *ds += atol(p);
569
				}
608
        for (i=7; i<=10; i++)   /* linux/Documentation/iostats.txt    */
609
          p = strtok(NULL, tokens); 
610
        *ds += atol(p);
611
        /* field 11 looks tailor made for a simple load monitor. In
612
         * practice, it doesn't show much unless the system is hammered. */
613
        /*for (i=1; i<14; i++)
614
          p = strtok(NULL, tokens);
615
        *ds += atol(p);*/
570
			}
616
			}
571
		}
617
		}
572
		if (*ds > maxdiskio) maxdiskio = *ds;
618
		if (*ds > maxdiskio) maxdiskio = *ds;

Return to bug 407325