Changeset a35b458 in mainline for uspace/app/top
- 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)
- Location:
- uspace/app/top
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/top/screen.c
r3061bc1 ra35b458 99 99 { 100 100 screen_style_normal(); 101 101 102 102 if (clear) { 103 103 console_flush(console); 104 104 console_clear(console); 105 105 } 106 106 107 107 screen_moveto(0, 0); 108 108 } … … 113 113 sysarg_t rows; 114 114 screen_get_size(&cols, &rows); 115 115 116 116 sysarg_t c; 117 117 sysarg_t r; 118 118 screen_get_pos(&c, &r); 119 119 120 120 sysarg_t i; 121 121 for (i = c + 1; i < cols; i++) 122 122 puts(" "); 123 123 124 124 if (r + 1 < rows) 125 125 puts("\n"); … … 129 129 { 130 130 console = console_init(stdin, stdout); 131 131 132 132 console_flush(console); 133 133 console_cursor_visibility(console, false); 134 134 135 135 screen_restart(true); 136 136 } … … 142 142 143 143 screen_restart(true); 144 144 145 145 console_flush(console); 146 146 console_cursor_visibility(console, true); … … 150 150 { 151 151 printf("%3" PRIu64 ".", ffloat.upper / ffloat.lower); 152 152 153 153 unsigned int i; 154 154 uint64_t rest = (ffloat.upper % ffloat.lower) * 10; … … 157 157 rest = (rest % ffloat.lower) * 10; 158 158 } 159 159 160 160 printf("%%"); 161 161 } … … 166 166 sysarg_t rows; 167 167 screen_get_size(&cols, &rows); 168 168 169 169 sysarg_t c; 170 170 sysarg_t r; 171 171 screen_get_pos(&c, &r); 172 172 173 173 if (c < cols) { 174 174 int pos = cols - c - 1; … … 184 184 data->hours, data->minutes, data->seconds, 185 185 data->udays, data->uhours, data->uminutes, data->useconds); 186 186 187 187 size_t i; 188 188 for (i = 0; i < data->load_count; i++) { … … 190 190 stats_print_load_fragment(data->load[i], 2); 191 191 } 192 192 193 193 screen_newline(); 194 194 } … … 209 209 size_t other = 0; 210 210 size_t invalid = 0; 211 211 212 212 size_t i; 213 213 for (i = 0; i < data->threads_count; i++) { 214 214 total++; 215 215 216 216 switch (data->threads[i].state) { 217 217 case Running: … … 235 235 } 236 236 } 237 237 238 238 printf("threads: %zu total, %zu running, %zu ready, " 239 239 "%zu sleeping, %zu lingering, %zu other, %zu invalid", … … 251 251 char busy_suffix; 252 252 char idle_suffix; 253 253 254 254 order_suffix(data->cpus[i].busy_cycles, &busy, &busy_suffix); 255 255 order_suffix(data->cpus[i].idle_cycles, &idle, &idle_suffix); 256 256 257 257 printf("cpu%u (%4" PRIu16 " MHz): busy cycles: " 258 258 "%" PRIu64 "%c, idle cycles: %" PRIu64 "%c", … … 265 265 } else 266 266 printf("cpu%u inactive", data->cpus[i].id); 267 267 268 268 screen_newline(); 269 269 } … … 280 280 const char *used_suffix; 281 281 const char *free_suffix; 282 282 283 283 bin_order_suffix(data->physmem->total, &total, &total_suffix, false); 284 284 bin_order_suffix(data->physmem->unavail, &unavail, &unavail_suffix, false); 285 285 bin_order_suffix(data->physmem->used, &used, &used_suffix, false); 286 286 bin_order_suffix(data->physmem->free, &free, &free_suffix, false); 287 287 288 288 printf("memory: %" PRIu64 "%s total, %" PRIu64 "%s unavail, %" 289 289 PRIu64 "%s used, %" PRIu64 "%s free", total, total_suffix, … … 305 305 sysarg_t rows; 306 306 screen_get_size(&cols, &rows); 307 308 screen_newline(); 309 307 308 screen_newline(); 309 310 310 printf("Operation modes:"); 311 311 screen_newline(); 312 312 313 313 printf(" t .. tasks statistics"); 314 314 screen_newline(); 315 315 316 316 printf(" i .. IPC statistics"); 317 317 screen_newline(); 318 318 319 319 printf(" e .. exceptions statistics"); 320 320 screen_newline(); 321 321 322 322 printf(" a .. toggle display of all/hot exceptions"); 323 323 screen_newline(); … … 330 330 printf("Other keys:"); 331 331 screen_newline(); 332 332 333 333 printf(" s .. choose column to sort by"); 334 334 screen_newline(); 335 335 336 336 printf(" r .. toggle reversed sorting"); 337 337 screen_newline(); 338 338 339 339 printf(" q .. quit"); 340 340 screen_newline(); 341 341 342 342 sysarg_t col; 343 343 sysarg_t row; 344 344 screen_get_pos(&col, &row); 345 345 346 346 while (row < rows) { 347 347 screen_newline(); … … 380 380 sysarg_t rows; 381 381 screen_get_size(&cols, &rows); 382 382 383 383 sysarg_t col; 384 384 sysarg_t row; 385 385 screen_get_pos(&col, &row); 386 386 387 387 size_t i; 388 388 for (i = 0; (i < table->num_fields) && (row < rows); i++) { … … 441 441 } 442 442 } 443 443 444 444 while (row < rows) { 445 445 screen_newline(); … … 453 453 sysarg_t rows; 454 454 screen_get_size(&cols, &rows); 455 455 456 456 sysarg_t col; 457 457 sysarg_t row; … … 464 464 row++; 465 465 } 466 466 467 467 while (row < rows) { 468 468 screen_newline(); … … 494 494 print_physmem_info(data); 495 495 print_warning(); 496 496 497 497 switch (screen_mode) { 498 498 case SCREEN_TABLE: … … 507 507 print_help(); 508 508 } 509 509 510 510 console_flush(console); 511 511 } … … 527 527 vsnprintf(warning_text, warning_text_size, fmt, args); 528 528 va_end(args); 529 529 530 530 warning_timeleft = 2 * USEC_COUNT; 531 531 … … 543 543 * Reset timeleft whenever it is not positive. 544 544 */ 545 545 546 546 if (timeleft <= 0) 547 547 timeleft = sec * USEC_COUNT; 548 548 549 549 /* 550 550 * Wait to see if there is any input. If so, take it and … … 553 553 * make timeleft zero and return -1. 554 554 */ 555 555 556 556 wchar_t c = 0; 557 557 558 558 while (c == 0) { 559 559 cons_event_t event; 560 560 561 561 warning_timeleft -= timeleft; 562 562 if (!console_get_event_timeout(console, &event, &timeleft)) { … … 565 565 } 566 566 warning_timeleft += timeleft; 567 567 568 568 if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS) 569 569 c = event.ev.key.c; 570 570 } 571 571 572 572 return (int) c; 573 573 } -
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 } -
uspace/app/top/top.h
r3061bc1 ra35b458 112 112 time_t minutes; 113 113 time_t seconds; 114 114 115 115 sysarg_t udays; 116 116 sysarg_t uhours; 117 117 sysarg_t uminutes; 118 118 sysarg_t useconds; 119 119 120 120 size_t load_count; 121 121 load_t *load; 122 122 123 123 size_t cpus_count; 124 124 stats_cpu_t *cpus; 125 125 perc_cpu_t *cpus_perc; 126 126 127 127 size_t tasks_count; 128 128 stats_task_t *tasks; 129 129 perc_task_t *tasks_perc; 130 130 131 131 size_t threads_count; 132 132 stats_thread_t *threads; 133 133 134 134 size_t exceptions_count; 135 135 stats_exc_t *exceptions; 136 136 perc_exc_t *exceptions_perc; 137 137 138 138 stats_physmem_t *physmem; 139 139 140 140 uint64_t *ucycles_diff; 141 141 uint64_t *kcycles_diff;
Note:
See TracChangeset
for help on using the changeset viewer.
