Changeset 172aad6 in mainline for uspace/app/top/top.c
- Timestamp:
- 2010-06-24T11:31:03Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e821e49
- Parents:
- 549012c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/top/top.c
r549012c r172aad6 44 44 #include <arch/barrier.h> 45 45 #include <errno.h> 46 #include <sort.h> 46 47 #include "screen.h" 47 48 #include "input.h" … … 57 58 58 59 op_mode_t op_mode = OP_TASKS; 60 sort_mode_t sort_mode = SORT_TASK_CYCLES; 59 61 bool excs_all = false; 60 62 … … 67 69 target->tasks = NULL; 68 70 target->tasks_perc = NULL; 71 target->tasks_map = NULL; 69 72 target->threads = NULL; 70 73 target->exceptions = NULL; 71 74 target->exceptions_perc = NULL; 72 75 target->physmem = NULL; 76 target->ucycles_diff = NULL; 77 target->kcycles_diff = NULL; 78 target->ecycles_diff = NULL; 79 target->ecount_diff = NULL; 73 80 74 81 /* Get current time */ … … 113 120 return "Not enough memory for task utilization"; 114 121 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 115 127 /* Get threads */ 116 128 target->threads = stats_get_threads(&(target->threads_count)); … … 132 144 if (target->physmem == NULL) 133 145 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"; 134 167 135 168 return NULL; … … 142 175 * 143 176 */ 144 static const char *compute_percentages(data_t *old_data, data_t *new_data) 145 { 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 static void compute_percentages(data_t *old_data, data_t *new_data) 178 { 177 179 /* For each CPU: Compute total cycles and divide it between 178 180 user and kernel */ … … 210 212 if (!found) { 211 213 /* This is newly borned task, ignore it */ 212 ucycles_diff[i] = 0;213 kcycles_diff[i] = 0;214 new_data->ucycles_diff[i] = 0; 215 new_data->kcycles_diff[i] = 0; 214 216 continue; 215 217 } 216 218 217 ucycles_diff[i] =219 new_data->ucycles_diff[i] = 218 220 new_data->tasks[i].ucycles - old_data->tasks[j].ucycles; 219 kcycles_diff[i] =221 new_data->kcycles_diff[i] = 220 222 new_data->tasks[i].kcycles - old_data->tasks[j].kcycles; 221 223 222 224 virtmem_total += new_data->tasks[i].virtmem; 223 ucycles_total += ucycles_diff[i];224 kcycles_total += kcycles_diff[i];225 ucycles_total += new_data->ucycles_diff[i]; 226 kcycles_total += new_data->kcycles_diff[i]; 225 227 } 226 228 … … 231 233 new_data->tasks[i].virtmem * 100, virtmem_total); 232 234 FRACTION_TO_FLOAT(new_data->tasks_perc[i].ucycles, 233 ucycles_diff[i] * 100, ucycles_total);235 new_data->ucycles_diff[i] * 100, ucycles_total); 234 236 FRACTION_TO_FLOAT(new_data->tasks_perc[i].kcycles, 235 kcycles_diff[i] * 100, kcycles_total);237 new_data->kcycles_diff[i] * 100, kcycles_total); 236 238 } 237 239 … … 259 261 if (!found) { 260 262 /* This is a new exception, ignore it */ 261 ecycles_diff[i] = 0;262 ecount_diff[i] = 0;263 new_data->ecycles_diff[i] = 0; 264 new_data->ecount_diff[i] = 0; 263 265 continue; 264 266 } 265 267 266 ecycles_diff[i] =268 new_data->ecycles_diff[i] = 267 269 new_data->exceptions[i].cycles - old_data->exceptions[j].cycles; 268 ecount_diff[i] =270 new_data->ecount_diff[i] = 269 271 new_data->exceptions[i].count - old_data->exceptions[i].count; 270 272 271 ecycles_total += ecycles_diff[i];272 ecount_total += ecount_diff[i];273 ecycles_total += new_data->ecycles_diff[i]; 274 ecount_total += new_data->ecount_diff[i]; 273 275 } 274 276 … … 277 279 for (i = 0; i < new_data->exceptions_count; i++) { 278 280 FRACTION_TO_FLOAT(new_data->exceptions_perc[i].cycles, 279 ecycles_diff[i] * 100, ecycles_total);281 new_data->ecycles_diff[i] * 100, ecycles_total); 280 282 FRACTION_TO_FLOAT(new_data->exceptions_perc[i].count, 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; 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); 292 314 } 293 315 … … 320 342 if (target->physmem != NULL) 321 343 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); 322 356 } 323 357 … … 335 369 336 370 /* Compute some rubbish to have initialised values */ 337 if ((ret = compute_percentages(&data_prev, &data_prev)) != NULL) 338 goto out; 371 compute_percentages(&data_prev, &data_prev); 339 372 340 373 /* And paint screen until death */ … … 347 380 } 348 381 349 if ((ret = compute_percentages(&data_prev, &data)) != NULL) { 350 free_data(&data); 351 goto out; 352 } 353 382 compute_percentages(&data_prev, &data); 383 sort_data(&data); 354 384 print_data(&data); 355 385 free_data(&data_prev);
Note:
See TracChangeset
for help on using the changeset viewer.