ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/saidar/saidar.c
(Generate patch)

Comparing projects/libstatgrab/src/saidar/saidar.c (file contents):
Revision 1.11 by ats, Mon Oct 20 22:35:14 2003 UTC vs.
Revision 1.17 by ats, Fri Nov 7 18:38:48 2003 UTC

# Line 295 | Line 295 | void display_data(){
295                  printw("%8s", size_conv(stats.swap_stats->free));
296          }
297  
298 <        if (stats.mem_stats != NULL && stats.swap_stats != NULL) {      
299 <                /* VM */
298 >        /* VM */
299 >        if (stats.mem_stats != NULL && stats.mem_stats->total != 0) {  
300                  move(6, 54);
301                  printw("%5.2f%%", (100.00 * (float)(stats.mem_stats->used)/stats.mem_stats->total));
302 +        }
303 +        if (stats.swap_stats != NULL && stats.swap_stats->total != 0) {
304                  move(7, 54);
305                  printw("%5.2f%%", (100.00 * (float)(stats.swap_stats->used)/stats.swap_stats->total));
306 +        }
307 +        if (stats.mem_stats != NULL && stats.swap_stats != NULL &&
308 +            stats.mem_stats->total != 0 && stats.swap_stats->total != 0) {      
309                  move(8, 54);
310                  printw("%5.2f%%", (100.00 * (float)(stats.mem_stats->used+stats.swap_stats->used)/(stats.mem_stats->total+stats.swap_stats->total)));
311          }
# Line 423 | Line 428 | int main(int argc, char **argv){
428          extern int optind;
429          int c;
430  
431 +        time_t last_update = 0;
432 +
433          WINDOW *window;
434  
428        int stdin_fileno;
429        fd_set infds;
430        struct timeval timeout;
431
435          extern int errno;
433        char ch;
436  
437          int delay=2;
438   #ifdef ALLBSD
# Line 444 | Line 446 | int main(int argc, char **argv){
446          }
447   #endif
448                  
449 <        while ((c = getopt(argc, argv, "vhd:")) != EOF){
449 >        while ((c = getopt(argc, argv, "vhd:")) != -1){
450                  switch (c){
451                          case 'd':
452                                  delay = atoi(optarg);
# Line 471 | Line 473 | int main(int argc, char **argv){
473          nonl();
474          cbreak();
475          noecho();
476 +        timeout(delay * 1000);
477          window=newwin(0, 0, 0, 0);
478          clear();
479  
# Line 481 | Line 484 | int main(int argc, char **argv){
484          }
485  
486          display_headings();
484        stdin_fileno=fileno(stdin);
487  
488          for(;;){
489 +                time_t now;
490 +                int ch = getch();
491  
492 <                FD_ZERO(&infds);
493 <                FD_SET(stdin_fileno, &infds);
494 <                timeout.tv_sec = delay;
491 <                timeout.tv_usec = 0;
492 <                
493 <                if((select((stdin_fileno+1), &infds, NULL, NULL, &timeout)) == -1){
494 <                        if(errno!=EINTR){
495 <                                perror("select failed");
496 <                                exit(1);
497 <                        }
492 >                if (ch == 'q'){
493 >                        endwin();
494 >                        return 0;
495                  }
496  
497 <                if(FD_ISSET(stdin_fileno, &infds)){
498 <                        ch=getch();
499 <                        if (ch == 'q'){
500 <                                endwin();
501 <                                return 0;
502 <                        }
497 >                /* To keep the numbers slightly accurate we do not want them
498 >                 * updating more frequently than once a second.
499 >                 */
500 >                now = time(NULL);
501 >                if ((now - last_update) >= 1) {
502 >                        get_stats();
503                  }
504 +                last_update = now;
505  
508                get_stats();
509
506                  display_data();
511
512                /* To keep the numbers slightly accurate we do not want them updating more
513                 * frequently than once a second.
514                 */
515                sleep(1);
507          }      
508  
509          endwin();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines