Changes in uspace/app/top/top.c [172aad6:b3b7e14a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/top/top.c
r172aad6 rb3b7e14a 44 44 #include <arch/barrier.h> 45 45 #include <errno.h> 46 #include <sort.h>47 46 #include "screen.h" 48 47 #include "input.h" … … 58 57 59 58 op_mode_t op_mode = OP_TASKS; 60 sort_mode_t sort_mode = SORT_TASK_CYCLES;61 59 bool excs_all = false; 62 60 … … 69 67 target->tasks = NULL; 70 68 target->tasks_perc = NULL; 71 target->tasks_map = NULL;72 69 target->threads = NULL; 73 70 target->exceptions = NULL; 74 71 target->exceptions_perc = NULL; 75 72 target->physmem = NULL; 76 target->ucycles_diff = NULL;77 target->kcycles_diff = NULL;78 target->ecycles_diff = NULL;79 target->ecount_diff = NULL;80 73 81 74 /* Get current time */ … … 120 113 return "Not enough memory for task utilization"; 121 114 122 target->tasks_map =123 (size_t *) calloc(target->tasks_count, sizeof(size_t));124 if (target->tasks_map == NULL)125 return "Not enough memory for task map";126 127 115 /* Get threads */ 128 116 target->threads = stats_get_threads(&(target->threads_count)); … … 144 132 if (target->physmem == NULL) 145 133 return "Cannot get physical memory"; 146 147 target->ucycles_diff = calloc(target->tasks_count,148 sizeof(uint64_t));149 if (target->ucycles_diff == NULL)150 return "Not enough memory for user utilization";151 152 /* Allocate memory for computed values */153 target->kcycles_diff = calloc(target->tasks_count,154 sizeof(uint64_t));155 if (target->kcycles_diff == NULL)156 return "Not enough memory for kernel utilization";157 158 target->ecycles_diff = calloc(target->exceptions_count,159 sizeof(uint64_t));160 if (target->ecycles_diff == NULL)161 return "Not enough memory for exception cycles utilization";162 163 target->ecount_diff = calloc(target->exceptions_count,164 sizeof(uint64_t));165 if (target->ecount_diff == NULL)166 return "Not enough memory for exception count utilization";167 134 168 135 return NULL; … … 175 142 * 176 143 */ 177 static voidcompute_percentages(data_t *old_data, data_t *new_data)144 static const char *compute_percentages(data_t *old_data, data_t *new_data) 178 145 { 179 /* For each CPU: Compute total cycles and divide it between 146 /* Allocate memory */ 147 148 uint64_t *ucycles_diff = calloc(new_data->tasks_count, 149 sizeof(uint64_t)); 150 if (ucycles_diff == NULL) 151 return "Not enough memory for user utilization"; 152 153 uint64_t *kcycles_diff = calloc(new_data->tasks_count, 154 sizeof(uint64_t)); 155 if (kcycles_diff == NULL) { 156 free(ucycles_diff); 157 return "Not enough memory for kernel utilization"; 158 } 159 160 uint64_t *ecycles_diff = calloc(new_data->exceptions_count, 161 sizeof(uint64_t)); 162 if (ecycles_diff == NULL) { 163 free(ucycles_diff); 164 free(kcycles_diff); 165 return "Not enough memory for exception cycles utilization"; 166 } 167 168 uint64_t *ecount_diff = calloc(new_data->exceptions_count, 169 sizeof(uint64_t)); 170 if (ecount_diff == NULL) { 171 free(ucycles_diff); 172 free(kcycles_diff); 173 free(ecycles_diff); 174 return "Not enough memory for exception count utilization"; 175 } 176 177 /* For each CPU: Compute total ticks and divide it between 180 178 user and kernel */ 181 179 … … 183 181 for (i = 0; i < new_data->cpus_count; i++) { 184 182 uint64_t idle = 185 new_data->cpus[i].idle_ cycles - old_data->cpus[i].idle_cycles;183 new_data->cpus[i].idle_ticks - old_data->cpus[i].idle_ticks; 186 184 uint64_t busy = 187 new_data->cpus[i].busy_ cycles - old_data->cpus[i].busy_cycles;185 new_data->cpus[i].busy_ticks - old_data->cpus[i].busy_ticks; 188 186 uint64_t sum = idle + busy; 189 187 … … 212 210 if (!found) { 213 211 /* This is newly borned task, ignore it */ 214 new_data->ucycles_diff[i] = 0;215 new_data->kcycles_diff[i] = 0;212 ucycles_diff[i] = 0; 213 kcycles_diff[i] = 0; 216 214 continue; 217 215 } 218 216 219 new_data->ucycles_diff[i] =217 ucycles_diff[i] = 220 218 new_data->tasks[i].ucycles - old_data->tasks[j].ucycles; 221 new_data->kcycles_diff[i] =219 kcycles_diff[i] = 222 220 new_data->tasks[i].kcycles - old_data->tasks[j].kcycles; 223 221 224 222 virtmem_total += new_data->tasks[i].virtmem; 225 ucycles_total += new_data->ucycles_diff[i];226 kcycles_total += new_data->kcycles_diff[i];223 ucycles_total += ucycles_diff[i]; 224 kcycles_total += kcycles_diff[i]; 227 225 } 228 226 … … 233 231 new_data->tasks[i].virtmem * 100, virtmem_total); 234 232 FRACTION_TO_FLOAT(new_data->tasks_perc[i].ucycles, 235 new_data->ucycles_diff[i] * 100, ucycles_total);233 ucycles_diff[i] * 100, ucycles_total); 236 234 FRACTION_TO_FLOAT(new_data->tasks_perc[i].kcycles, 237 new_data->kcycles_diff[i] * 100, kcycles_total);235 kcycles_diff[i] * 100, kcycles_total); 238 236 } 239 237 … … 261 259 if (!found) { 262 260 /* This is a new exception, ignore it */ 263 new_data->ecycles_diff[i] = 0;264 new_data->ecount_diff[i] = 0;261 ecycles_diff[i] = 0; 262 ecount_diff[i] = 0; 265 263 continue; 266 264 } 267 265 268 new_data->ecycles_diff[i] =266 ecycles_diff[i] = 269 267 new_data->exceptions[i].cycles - old_data->exceptions[j].cycles; 270 new_data->ecount_diff[i] =268 ecount_diff[i] = 271 269 new_data->exceptions[i].count - old_data->exceptions[i].count; 272 270 273 ecycles_total += new_data->ecycles_diff[i];274 ecount_total += new_data->ecount_diff[i];271 ecycles_total += ecycles_diff[i]; 272 ecount_total += ecount_diff[i]; 275 273 } 276 274 … … 279 277 for (i = 0; i < new_data->exceptions_count; i++) { 280 278 FRACTION_TO_FLOAT(new_data->exceptions_perc[i].cycles, 281 new_data->ecycles_diff[i] * 100, ecycles_total);279 ecycles_diff[i] * 100, ecycles_total); 282 280 FRACTION_TO_FLOAT(new_data->exceptions_perc[i].count, 283 new_data->ecount_diff[i] * 100, ecount_total); 284 } 285 } 286 287 static int cmp_data(void *a, void *b, void *arg) 288 { 289 size_t ia = *((size_t *) a); 290 size_t ib = *((size_t *) b); 291 data_t *data = (data_t *) arg; 292 293 uint64_t acycles = data->ucycles_diff[ia] + data->kcycles_diff[ia]; 294 uint64_t bcycles = data->ucycles_diff[ib] + data->kcycles_diff[ib]; 295 296 if (acycles > bcycles) 297 return -1; 298 299 if (acycles < bcycles) 300 return 1; 301 302 return 0; 303 } 304 305 static void sort_data(data_t *data) 306 { 307 size_t i; 308 309 for (i = 0; i < data->tasks_count; i++) 310 data->tasks_map[i] = i; 311 312 qsort((void *) data->tasks_map, data->tasks_count, 313 sizeof(size_t), cmp_data, (void *) data); 281 ecount_diff[i] * 100, ecount_total); 282 } 283 284 /* Cleanup */ 285 286 free(ucycles_diff); 287 free(kcycles_diff); 288 free(ecycles_diff); 289 free(ecount_diff); 290 291 return NULL; 314 292 } 315 293 … … 342 320 if (target->physmem != NULL) 343 321 free(target->physmem); 344 345 if (target->ucycles_diff != NULL)346 free(target->ucycles_diff);347 348 if (target->kcycles_diff != NULL)349 free(target->kcycles_diff);350 351 if (target->ecycles_diff != NULL)352 free(target->ecycles_diff);353 354 if (target->ecount_diff != NULL)355 free(target->ecount_diff);356 322 } 357 323 … … 369 335 370 336 /* Compute some rubbish to have initialised values */ 371 compute_percentages(&data_prev, &data_prev); 337 if ((ret = compute_percentages(&data_prev, &data_prev)) != NULL) 338 goto out; 372 339 373 340 /* And paint screen until death */ … … 380 347 } 381 348 382 compute_percentages(&data_prev, &data); 383 sort_data(&data); 349 if ((ret = compute_percentages(&data_prev, &data)) != NULL) { 350 free_data(&data); 351 goto out; 352 } 353 384 354 print_data(&data); 385 355 free_data(&data_prev);
Note:
See TracChangeset
for help on using the changeset viewer.