Changeset ee35ba0b in mainline for uspace/app/top/top.c
- Timestamp:
- 2010-04-03T15:26:34Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 452268a
- Parents:
- 8b2aba5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/top/top.c
r8b2aba5 ree35ba0b 54 54 #define MINUTE 60 55 55 56 int number = 0; 57 int number2 = 0; 56 58 static void read_data(data_t *target) 57 59 { … … 84 86 } 85 87 88 /** Computes percentage differencies from old_data to new_data 89 * 90 * @param old_data Pointer to old data strucutre. 91 * @param new_data Pointer to actual data where percetages are stored. 92 * 93 */ 94 static void compute_percentages(data_t *old_data, data_t *new_data) 95 { 96 /* Foreach cpu, compute total ticks and divide it between user and 97 * system */ 98 unsigned int i; 99 new_data->cpu_perc = malloc(new_data->cpu_count * sizeof(cpu_perc_t)); 100 for (i = 0; i < new_data->cpu_count; ++i) { 101 uint64_t idle = new_data->cpus[i].idle_ticks - old_data->cpus[i].idle_ticks; 102 uint64_t busy = new_data->cpus[i].busy_ticks - old_data->cpus[i].busy_ticks; 103 uint64_t sum = idle + busy; 104 new_data->cpu_perc[i].idle = ((float)(idle * 100) / sum); 105 new_data->cpu_perc[i].busy = ((float)(busy * 100) / sum); 106 } 107 } 108 86 109 static void free_data(data_t *target) 87 110 { 88 111 free(target->tasks); 112 free(target->cpus); 113 free(target->cpu_perc); 89 114 } 90 115 91 static inline void swap(data_t * first, data_t*second)116 static inline void swap(data_t **first, data_t **second) 92 117 { 93 118 data_t *temp; 94 temp = first;95 first =second;96 second = temp;119 temp = *first; 120 *first = *second; 121 *second = temp; 97 122 } 98 123 … … 103 128 data_t *data1 = &data[0]; 104 129 data_t *data2 = &data[1]; 130 screen_init(); 105 131 106 132 /* Read initial stats */ 107 133 printf("Reading initial data...\n"); 108 134 read_data(data1); 109 sleep(UPDATE_INTERVAL); 110 read_data(data2); 111 112 screen_init(); 113 print_data(data2); 135 /* Compute some rubbish to have initialised values */ 136 compute_percentages(data1, data1); 114 137 115 138 /* And paint screen until death... */ … … 117 140 char c = tgetchar(UPDATE_INTERVAL); 118 141 if (c < 0) { 142 read_data(data2); 143 compute_percentages(data1, data2); 119 144 free_data(data1); 120 swap(data1, data2);121 read_data(data2);122 145 print_data(data2); 146 swap(&data1, &data2); 123 147 continue; 124 148 }
Note:
See TracChangeset
for help on using the changeset viewer.