Changeset 79edc36 in mainline for uspace/app/top/top.c
- Timestamp:
- 2010-04-01T15:21:03Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 62550dce
- Parents:
- 83a957a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/top/top.c
r83a957a r79edc36 37 37 #include <stdio.h> 38 38 #include <stdlib.h> 39 #include <async.h>40 39 #include <unistd.h> 41 40 #include <io/console.h> 42 #include <vfs/vfs.h> 41 #include <uptime.h> 42 #include <task.h> 43 #include <thread.h> 44 #include <sys/time.h> 45 #include <load.h> 43 46 #include "screen.h" 44 47 #include "input.h" 48 #include "top.h" 49 50 #define UPDATE_INTERVAL 1 51 52 #define DAY 86400 53 #define HOUR 3600 54 #define MINUTE 60 55 56 static void read_vars(data_t *target) 57 { 58 /* Read current time */ 59 struct timeval time; 60 if (gettimeofday(&time, NULL) != 0) { 61 printf("Cannot get time of day!\n"); 62 exit(1); 63 } 64 target->hours = (time.tv_sec % DAY) / HOUR; 65 target->minutes = (time.tv_sec % HOUR) / MINUTE; 66 target->seconds = time.tv_sec % MINUTE; 67 68 /* Read uptime */ 69 uint64_t uptime; 70 get_uptime(&uptime); 71 target->uptime_d = uptime / DAY; 72 target->uptime_h = (uptime % DAY) / HOUR; 73 target->uptime_m = (uptime % HOUR) / MINUTE; 74 target->uptime_s = uptime % MINUTE; 75 76 /* Read load */ 77 get_load(target->load); 78 } 45 79 46 80 int main(int argc, char *argv[]) 47 81 { 82 data_t old_data; 83 data_t new_data; 84 85 /* Read initial stats */ 86 printf("Reading initial data...\n"); 87 read_vars(&old_data); 88 sleep(UPDATE_INTERVAL); 89 read_vars(&new_data); 90 48 91 screen_init(); 49 92 50 93 /* And paint screen until death... */ 51 int i = 0;52 94 while (true) { 53 char c = tgetchar( );95 char c = tgetchar(UPDATE_INTERVAL); 54 96 if (c < 0) { 55 clear_screen(); 56 moveto(0,0); 57 printf("Still running;-) for %d...", i++); 58 fflush(stdout); 97 read_vars(&new_data); 98 print_data(&new_data); 59 99 continue; 60 100 } … … 68 108 break; 69 109 } 110 70 111 } 71 112 113 puts("\n\n"); 72 114 fflush(stdout); 73 115 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.