Changeset a35b458 in mainline for uspace/app/top/top.c
- Timestamp:
- 2018-03-02T20:10:49Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
-
uspace/app/top/top.c (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/top/top.c
r3061bc1 ra35b458 153 153 target->table.num_fields = 0; 154 154 target->table.fields = NULL; 155 155 156 156 /* Get current time */ 157 157 struct timeval time; 158 158 gettimeofday(&time, NULL); 159 159 160 160 target->hours = (time.tv_sec % DAY) / HOUR; 161 161 target->minutes = (time.tv_sec % HOUR) / MINUTE; 162 162 target->seconds = time.tv_sec % MINUTE; 163 163 164 164 /* Get uptime */ 165 165 struct timeval uptime; 166 166 getuptime(&uptime); 167 167 168 168 target->udays = uptime.tv_sec / DAY; 169 169 target->uhours = (uptime.tv_sec % DAY) / HOUR; 170 170 target->uminutes = (uptime.tv_sec % HOUR) / MINUTE; 171 171 target->useconds = uptime.tv_sec % MINUTE; 172 172 173 173 /* Get load */ 174 174 target->load = stats_get_load(&(target->load_count)); 175 175 if (target->load == NULL) 176 176 return "Cannot get system load"; 177 177 178 178 /* Get CPUs */ 179 179 target->cpus = stats_get_cpus(&(target->cpus_count)); 180 180 if (target->cpus == NULL) 181 181 return "Cannot get CPUs"; 182 182 183 183 target->cpus_perc = 184 184 (perc_cpu_t *) calloc(target->cpus_count, sizeof(perc_cpu_t)); 185 185 if (target->cpus_perc == NULL) 186 186 return "Not enough memory for CPU utilization"; 187 187 188 188 /* Get tasks */ 189 189 target->tasks = stats_get_tasks(&(target->tasks_count)); 190 190 if (target->tasks == NULL) 191 191 return "Cannot get tasks"; 192 192 193 193 target->tasks_perc = 194 194 (perc_task_t *) calloc(target->tasks_count, sizeof(perc_task_t)); 195 195 if (target->tasks_perc == NULL) 196 196 return "Not enough memory for task utilization"; 197 197 198 198 /* Get threads */ 199 199 target->threads = stats_get_threads(&(target->threads_count)); 200 200 if (target->threads == NULL) 201 201 return "Cannot get threads"; 202 202 203 203 /* Get Exceptions */ 204 204 target->exceptions = stats_get_exceptions(&(target->exceptions_count)); 205 205 if (target->exceptions == NULL) 206 206 return "Cannot get exceptions"; 207 207 208 208 target->exceptions_perc = 209 209 (perc_exc_t *) calloc(target->exceptions_count, sizeof(perc_exc_t)); 210 210 if (target->exceptions_perc == NULL) 211 211 return "Not enough memory for exception utilization"; 212 212 213 213 /* Get physical memory */ 214 214 target->physmem = stats_get_physmem(); 215 215 if (target->physmem == NULL) 216 216 return "Cannot get physical memory"; 217 217 218 218 target->ucycles_diff = calloc(target->tasks_count, 219 219 sizeof(uint64_t)); 220 220 if (target->ucycles_diff == NULL) 221 221 return "Not enough memory for user utilization"; 222 222 223 223 /* Allocate memory for computed values */ 224 224 target->kcycles_diff = calloc(target->tasks_count, … … 226 226 if (target->kcycles_diff == NULL) 227 227 return "Not enough memory for kernel utilization"; 228 228 229 229 target->ecycles_diff = calloc(target->exceptions_count, 230 230 sizeof(uint64_t)); 231 231 if (target->ecycles_diff == NULL) 232 232 return "Not enough memory for exception cycles utilization"; 233 233 234 234 target->ecount_diff = calloc(target->exceptions_count, 235 235 sizeof(uint64_t)); 236 236 if (target->ecount_diff == NULL) 237 237 return "Not enough memory for exception count utilization"; 238 238 239 239 return NULL; 240 240 } … … 250 250 /* For each CPU: Compute total cycles and divide it between 251 251 user and kernel */ 252 252 253 253 size_t i; 254 254 for (i = 0; i < new_data->cpus_count; i++) { … … 258 258 new_data->cpus[i].busy_cycles - old_data->cpus[i].busy_cycles; 259 259 uint64_t sum = idle + busy; 260 260 261 261 FRACTION_TO_FLOAT(new_data->cpus_perc[i].idle, idle * 100, sum); 262 262 FRACTION_TO_FLOAT(new_data->cpus_perc[i].busy, busy * 100, sum); 263 263 } 264 264 265 265 /* For all tasks compute sum and differencies of all cycles */ 266 266 267 267 uint64_t virtmem_total = 0; 268 268 uint64_t resmem_total = 0; 269 269 uint64_t ucycles_total = 0; 270 270 uint64_t kcycles_total = 0; 271 271 272 272 for (i = 0; i < new_data->tasks_count; i++) { 273 273 /* Match task with the previous instance */ 274 274 275 275 bool found = false; 276 276 size_t j; … … 281 281 } 282 282 } 283 283 284 284 if (!found) { 285 285 /* This is newly borned task, ignore it */ … … 288 288 continue; 289 289 } 290 290 291 291 new_data->ucycles_diff[i] = 292 292 new_data->tasks[i].ucycles - old_data->tasks[j].ucycles; 293 293 new_data->kcycles_diff[i] = 294 294 new_data->tasks[i].kcycles - old_data->tasks[j].kcycles; 295 295 296 296 virtmem_total += new_data->tasks[i].virtmem; 297 297 resmem_total += new_data->tasks[i].resmem; … … 299 299 kcycles_total += new_data->kcycles_diff[i]; 300 300 } 301 301 302 302 /* For each task compute percential change */ 303 303 304 304 for (i = 0; i < new_data->tasks_count; i++) { 305 305 FRACTION_TO_FLOAT(new_data->tasks_perc[i].virtmem, … … 312 312 new_data->kcycles_diff[i] * 100, kcycles_total); 313 313 } 314 314 315 315 /* For all exceptions compute sum and differencies of cycles */ 316 316 317 317 uint64_t ecycles_total = 0; 318 318 uint64_t ecount_total = 0; 319 319 320 320 for (i = 0; i < new_data->exceptions_count; i++) { 321 321 /* … … 324 324 * usually disappear, but it does not hurt. 325 325 */ 326 326 327 327 bool found = false; 328 328 size_t j; … … 333 333 } 334 334 } 335 335 336 336 if (!found) { 337 337 /* This is a new exception, ignore it */ … … 340 340 continue; 341 341 } 342 342 343 343 new_data->ecycles_diff[i] = 344 344 new_data->exceptions[i].cycles - old_data->exceptions[j].cycles; 345 345 new_data->ecount_diff[i] = 346 346 new_data->exceptions[i].count - old_data->exceptions[i].count; 347 347 348 348 ecycles_total += new_data->ecycles_diff[i]; 349 349 ecount_total += new_data->ecount_diff[i]; 350 350 } 351 351 352 352 /* For each exception compute percential change */ 353 353 354 354 for (i = 0; i < new_data->exceptions_count; i++) { 355 355 FRACTION_TO_FLOAT(new_data->exceptions_perc[i].cycles, … … 364 364 field_t *fa = (field_t *)a + sort_column; 365 365 field_t *fb = (field_t *)b + sort_column; 366 366 367 367 if (fa->type > fb->type) 368 368 return 1 * sort_reverse; … … 536 536 if (target->load != NULL) 537 537 free(target->load); 538 538 539 539 if (target->cpus != NULL) 540 540 free(target->cpus); 541 541 542 542 if (target->cpus_perc != NULL) 543 543 free(target->cpus_perc); 544 544 545 545 if (target->tasks != NULL) 546 546 free(target->tasks); 547 547 548 548 if (target->tasks_perc != NULL) 549 549 free(target->tasks_perc); 550 550 551 551 if (target->threads != NULL) 552 552 free(target->threads); 553 553 554 554 if (target->exceptions != NULL) 555 555 free(target->exceptions); 556 556 557 557 if (target->exceptions_perc != NULL) 558 558 free(target->exceptions_perc); 559 559 560 560 if (target->physmem != NULL) 561 561 free(target->physmem); 562 562 563 563 if (target->ucycles_diff != NULL) 564 564 free(target->ucycles_diff); 565 565 566 566 if (target->kcycles_diff != NULL) 567 567 free(target->kcycles_diff); 568 568 569 569 if (target->ecycles_diff != NULL) 570 570 free(target->ecycles_diff); 571 571 572 572 if (target->ecount_diff != NULL) 573 573 free(target->ecount_diff); … … 582 582 data_t data_prev; 583 583 const char *ret = NULL; 584 584 585 585 screen_init(); 586 586 printf("Reading initial data...\n"); 587 587 588 588 if ((ret = read_data(&data)) != NULL) 589 589 goto out; 590 590 591 591 /* Compute some rubbish to have initialised values */ 592 592 compute_percentages(&data, &data); 593 593 594 594 /* And paint screen until death */ 595 595 while (true) { … … 602 602 goto out; 603 603 } 604 604 605 605 compute_percentages(&data_prev, &data); 606 606 free_data(&data_prev); … … 672 672 print_data(&data); 673 673 } 674 674 675 675 out: 676 676 screen_done(); 677 677 free_data(&data); 678 678 679 679 if (ret != NULL) { 680 680 fprintf(stderr, "%s: %s\n", NAME, ret); 681 681 return 1; 682 682 } 683 683 684 684 return 0; 685 685 }
Note:
See TracChangeset
for help on using the changeset viewer.
