Changeset 9f1362d4 in mainline for uspace/app/top/screen.c
- Timestamp:
- 2010-04-19T19:58:18Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 369a5f8
- Parents:
- caad59a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/top/screen.c
rcaad59a r9f1362d4 37 37 38 38 #include <stdio.h> 39 #include <ipc/ipc.h> 39 40 #include <io/console.h> 41 #include <io/style.h> 40 42 #include <vfs/vfs.h> 41 43 #include <stdarg.h> … … 45 47 #include "top.h" 46 48 47 #define WHITE 0xf0f0f0 48 #define BLACK 0x000000 49 50 static int rows; 51 static int colls; 52 static int up_rows; 49 static ipcarg_t warn_col = 0; 50 static ipcarg_t warn_row = 0; 51 52 static void screen_style_normal(void) 53 { 54 fflush(stdout); 55 console_set_style(fphone(stdout), STYLE_NORMAL); 56 } 57 58 static void screen_style_inverted(void) 59 { 60 fflush(stdout); 61 console_set_style(fphone(stdout), STYLE_INVERTED); 62 } 63 64 static void screen_moveto(ipcarg_t col, ipcarg_t row) 65 { 66 fflush(stdout); 67 console_set_pos(fphone(stdout), col, row); 68 } 69 70 static void screen_get_pos(ipcarg_t *col, ipcarg_t *row) 71 { 72 fflush(stdout); 73 console_get_pos(fphone(stdout), col, row); 74 } 75 76 static void screen_get_size(ipcarg_t *col, ipcarg_t *row) 77 { 78 fflush(stdout); 79 console_get_size(fphone(stdout), col, row); 80 } 81 82 static void screen_restart(bool clear) 83 { 84 screen_style_normal(); 85 86 if (clear) { 87 fflush(stdout); 88 console_clear(fphone(stdout)); 89 } 90 91 screen_moveto(0, 0); 92 } 93 94 static void screen_newline(void) 95 { 96 ipcarg_t cols; 97 ipcarg_t rows; 98 screen_get_size(&cols, &rows); 99 100 ipcarg_t c; 101 ipcarg_t r; 102 screen_get_pos(&c, &r); 103 104 ipcarg_t i; 105 for (i = c + 1; i < cols; i++) 106 puts(" "); 107 108 if (r + 1 < rows) 109 puts("\n"); 110 } 111 112 void screen_init(void) 113 { 114 fflush(stdout); 115 console_cursor_visibility(fphone(stdout), false); 116 117 screen_restart(true); 118 } 119 120 void screen_done(void) 121 { 122 screen_restart(true); 123 124 fflush(stdout); 125 console_cursor_visibility(fphone(stdout), true); 126 } 53 127 54 128 static void print_float(fixed_float ffloat, unsigned int precision) … … 64 138 } 65 139 66 static void screen_resume_normal(void) 67 { 68 fflush(stdout); 69 console_set_rgb_color(fphone(stdout), 0, WHITE); 70 } 71 72 static void screen_moveto(int r, int c) 73 { 74 fflush(stdout); 75 console_goto(fphone(stdout), c, r); 76 } 77 78 static void screen_clear(void) 79 { 80 console_clear(fphone(stdout)); 81 screen_moveto(0, 0); 82 up_rows = 0; 83 fflush(stdout); 84 } 85 86 void screen_init(void) 87 { 88 console_cursor_visibility(fphone(stdout), 0); 89 screen_resume_normal(); 90 screen_clear(); 91 92 console_get_size(fphone(stdout), &colls, &rows); 93 } 94 95 void screen_done(void) 96 { 97 screen_resume_normal(); 98 screen_clear(); 99 console_cursor_visibility(fphone(stdout), 1); 100 } 101 102 static inline void print_time(data_t *data) 103 { 104 printf("%02lu:%02lu:%02lu ", data->hours, data->minutes, data->seconds); 105 } 106 107 static inline void print_uptime(data_t *data) 108 { 109 printf("up %u days, %02u:%02u:%02u, ", data->udays, data->uhours, 110 data->uminutes, data->useconds); 111 } 112 113 static inline void print_load(data_t *data) 114 { 115 printf("load avarage: "); 140 static inline void print_global_head(data_t *data) 141 { 142 printf("top - %02lu:%02lu:%02lu up %u days, %02u:%02u:%02u, load avarage:", 143 data->hours, data->minutes, data->seconds, 144 data->udays, data->uhours, data->uminutes, data->useconds); 116 145 117 146 size_t i; 118 147 for (i = 0; i < data->load_count; i++) { 148 puts(" "); 119 149 stats_print_load_fragment(data->load[i], 2); 120 printf(" "); 121 } 150 } 151 152 screen_newline(); 122 153 } 123 154 … … 125 156 { 126 157 printf("tasks: %u total", data->tasks_count); 158 screen_newline(); 127 159 } 128 160 … … 137 169 size_t invalid = 0; 138 170 139 140 171 size_t i; 141 172 for (i = 0; i < data->threads_count; i++) { … … 167 198 "%u other, %u invalid", 168 199 total, running, ready, sleeping, lingering, other, invalid); 200 screen_newline(); 169 201 } 170 202 … … 178 210 data->cpus[i].id, data->cpus[i].frequency_mhz, 179 211 data->cpus[i].busy_ticks, data->cpus[i].idle_ticks); 180 p rintf(", idle: ");212 puts(", idle: "); 181 213 print_float(data->cpus_perc[i].idle, 2); 182 p rintf("%%, busy: ");214 puts("%, busy: "); 183 215 print_float(data->cpus_perc[i].busy, 2); 184 p rintf("%%\n");216 puts("%"); 185 217 } else 186 printf("cpu%u inactive \n", data->cpus[i].id);187 188 up_rows++;218 printf("cpu%u inactive", data->cpus[i].id); 219 220 screen_newline(); 189 221 } 190 222 } … … 209 241 PRIu64 "%c used, %" PRIu64 "%c free", total, total_suffix, 210 242 unavail, unavail_suffix, used, used_suffix, free, free_suffix); 211 } 212 213 static inline void print_tasks(data_t *data, int row) 214 { 215 size_t i; 216 for (i = 0; i < data->tasks_count; i++, row++) { 217 if (row > rows) 218 break; 219 243 screen_newline(); 244 } 245 246 static inline void print_task_head(void) 247 { 248 screen_style_inverted(); 249 printf(" ID Threads Mem %%Mem %%uCycles %%kCycles Name"); 250 screen_newline(); 251 screen_style_normal(); 252 } 253 254 static inline void print_tasks(data_t *data) 255 { 256 ipcarg_t cols; 257 ipcarg_t rows; 258 screen_get_size(&cols, &rows); 259 260 ipcarg_t col; 261 ipcarg_t row; 262 screen_get_pos(&col, &row); 263 264 size_t i; 265 for (i = 0; (i < data->tasks_count) && (row < rows); i++, row++) { 220 266 uint64_t virtmem; 221 267 char virtmem_suffix; … … 224 270 printf("%8" PRIu64 " %8u %8" PRIu64 "%c ", data->tasks[i].task_id, 225 271 data->tasks[i].threads, virtmem, virtmem_suffix); 226 p rintf(" ");272 puts(" "); 227 273 print_float(data->tasks_perc[i].virtmem, 2); 228 p rintf("%% ");274 puts("% "); 229 275 print_float(data->tasks_perc[i].ucycles, 2); 230 p rintf("%% ");276 puts("% "); 231 277 print_float(data->tasks_perc[i].kcycles, 2); 232 printf("%% %s\n", data->tasks[i].name); 233 } 234 } 235 236 static inline void print_task_head(void) 237 { 238 fflush(stdout); 239 console_set_rgb_color(fphone(stdout), WHITE, BLACK); 240 241 printf(" ID Threads Mem %%Mem %%uCycles %%kCycles Name"); 242 243 int i; 244 for (i = 61; i < colls; ++i) 245 printf(" "); 246 247 fflush(stdout); 248 console_set_rgb_color(fphone(stdout), BLACK, WHITE); 278 printf("%% %s", data->tasks[i].name); 279 280 screen_newline(); 281 } 249 282 } 250 283 251 284 static inline void print_ipc_head(void) 252 285 { 253 fflush(stdout); 254 console_set_rgb_color(fphone(stdout), WHITE, BLACK); 255 286 screen_style_inverted(); 256 287 printf(" ID Calls sent Calls recv Answs sent Answs recv IRQn recv Forw Name"); 257 258 int i;259 for (i = 80; i < colls; ++i) 260 printf(" "); 261 262 fflush(stdout); 263 console_set_rgb_color(fphone(stdout), BLACK, WHITE);264 } 265 266 static inline void print_ipc(data_t *data, int row) 267 { 268 size_t i;269 for (i = 0; i < data->tasks_count; i++, row++) {270 if (row > rows)271 break;272 288 screen_newline(); 289 screen_style_normal(); 290 } 291 292 static inline void print_ipc(data_t *data) 293 { 294 ipcarg_t cols; 295 ipcarg_t rows; 296 screen_get_size(&cols, &rows); 297 298 ipcarg_t col; 299 ipcarg_t row; 300 screen_get_pos(&col, &row); 301 302 size_t i; 303 for (i = 0; (i < data->tasks_count) && (row < rows); i++, row++) { 273 304 printf("%8" PRIu64 " %10" PRIu64 " %10" PRIu64 " %10" PRIu64 274 " %10" PRIu64 " %10" PRIu64 " %10" PRIu64 " %s \n",305 " %10" PRIu64 " %10" PRIu64 " %10" PRIu64 " %s", 275 306 data->tasks[i].task_id, data->tasks[i].ipc_info.call_sent, 276 307 data->tasks[i].ipc_info.call_recieved, … … 279 310 data->tasks[i].ipc_info.irq_notif_recieved, 280 311 data->tasks[i].ipc_info.forwarded, data->tasks[i].name); 312 313 screen_newline(); 281 314 } 282 315 } … … 284 317 void print_data(data_t *data) 285 318 { 286 screen_clear(); 287 fflush(stdout); 288 289 printf("top - "); 290 print_time(data); 291 print_uptime(data); 292 print_load(data); 293 294 printf("\n"); 295 up_rows++; 296 319 screen_restart(false); 320 print_global_head(data); 297 321 print_task_summary(data); 298 299 printf("\n");300 up_rows++;301 302 322 print_thread_summary(data); 303 304 printf("\n");305 up_rows++;306 307 323 print_cpu_info(data); 308 324 print_physmem_info(data); 309 325 310 printf("\n");311 up_rows++;312 313 326 /* Empty row for warnings */ 314 printf("\n"); 327 screen_get_pos(&warn_col, &warn_row); 328 screen_newline(); 315 329 316 330 if (operation_type == OP_IPC) { 317 331 print_ipc_head(); 318 printf("\n"); 319 print_ipc(data, up_rows); 332 print_ipc(data); 320 333 } else { 321 334 print_task_head(); 322 printf("\n"); 323 print_tasks(data, up_rows); 335 print_tasks(data); 324 336 } 325 337 … … 329 341 void print_warning(const char *fmt, ...) 330 342 { 331 screen_moveto( up_rows, 0);343 screen_moveto(warn_col, warn_row); 332 344 333 345 va_list args; … … 336 348 va_end(args); 337 349 350 screen_newline(); 338 351 fflush(stdout); 339 352 }
Note:
See TracChangeset
for help on using the changeset viewer.