Changeset 8b2aba5 in mainline
- Timestamp:
- 2010-04-02T20:22:14Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ee35ba0b
- Parents:
- 8f56d93
- Location:
- uspace/app
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/ps/ps.c
r8f56d93 r8b2aba5 150 150 size_t i; 151 151 for (i = 0; i < cpu_count; ++i) { 152 printf("%2u (%4u Mhz): Busy ticks: % 8llu, Idle ticks: %8llu\n", cpus[i].id,152 printf("%2u (%4u Mhz): Busy ticks: %6llu, Idle ticks: %6llu\n", cpus[i].id, 153 153 (size_t)cpus[i].frequency_mhz, cpus[i].busy_ticks, cpus[i].idle_ticks); 154 154 } -
uspace/app/top/ps.c
r8f56d93 r8b2aba5 41 41 #include <malloc.h> 42 42 #include <ps.h> 43 #include <sysinfo.h> 43 44 #include "ps.h" 44 45 … … 94 95 } 95 96 97 unsigned int get_cpu_infos(uspace_cpu_info_t **out_infos) 98 { 99 unsigned int cpu_count = sysinfo_value("cpu.count"); 100 uspace_cpu_info_t *cpus = malloc(cpu_count * sizeof(uspace_cpu_info_t)); 101 get_cpu_info(cpus); 102 103 *out_infos = cpus; 104 return cpu_count; 105 } 106 96 107 /** @} 97 108 */ -
uspace/app/top/ps.h
r8f56d93 r8b2aba5 36 36 #include <task.h> 37 37 #include <kernel/ps/taskinfo.h> 38 #include <kernel/ps/cpuinfo.h> 38 39 39 40 extern const char *thread_states[]; 40 41 extern unsigned int get_tasks(task_id_t **out_tasks); 41 42 extern thread_info_t *get_threads(task_id_t taskid); 43 extern unsigned int get_cpu_infos(uspace_cpu_info_t **out_infos); 42 44 43 45 #endif -
uspace/app/top/screen.c
r8f56d93 r8b2aba5 46 46 int rows; 47 47 int colls; 48 int up_rows; 48 49 49 50 #define WHITE 0xf0f0f0 … … 59 60 { 60 61 console_get_size(fphone(stdout), &colls, &rows); 62 up_rows = 0; 61 63 console_cursor_visibility(fphone(stdout), 0); 62 64 resume_normal(); … … 68 70 console_clear(fphone(stdout)); 69 71 moveto(0, 0); 72 up_rows = 0; 73 fflush(stdout); 70 74 } 71 75 … … 103 107 } 104 108 109 static inline void print_cpuinfo(data_t *data) 110 { 111 unsigned int i; 112 uspace_cpu_info_t *cpus = data->cpus; 113 for (i = 0; i < data->cpu_count; ++i) { 114 printf("Cpu%u (%4u Mhz): Busy ticks: %6llu, Idle Ticks: %6llu\n", 115 i, (unsigned int)cpus[i].frequency_mhz, cpus[i].busy_ticks, 116 cpus[i].idle_ticks); 117 ++up_rows; 118 } 119 } 120 105 121 static inline void print_tasks(data_t *data, int row) 106 122 { … … 116 132 } 117 133 } 118 119 134 120 135 static inline void print_head(void) … … 139 154 print_load(data); 140 155 puts("\n"); 156 ++up_rows; 141 157 print_taskstat(data); 142 puts("\n\n"); 158 puts("\n"); 159 ++up_rows; 160 print_cpuinfo(data); 161 puts("\n"); 162 ++up_rows; 143 163 print_head(); 144 164 puts("\n"); -
uspace/app/top/screen.h
r8f56d93 r8b2aba5 44 44 extern void print_data(data_t *data); 45 45 46 extern int up_rows; 47 #define PRINT_WARNING(message, ...) \ 48 do { \ 49 moveto(up_rows - 1, 0); \ 50 printf(message, ##__VA_ARGS__); \ 51 fflush(stdout); \ 52 } while (0) 53 46 54 #endif 47 55 -
uspace/app/top/top.c
r8f56d93 r8b2aba5 38 38 #include <stdlib.h> 39 39 #include <unistd.h> 40 #include <io/console.h>41 40 #include <uptime.h> 42 41 #include <task.h> … … 55 54 #define MINUTE 60 56 55 57 static void read_ vars(data_t *target)56 static void read_data(data_t *target) 58 57 { 59 58 /* Read current time */ … … 80 79 /* Read task ids */ 81 80 target->task_count = get_tasks(&target->tasks); 81 82 /* Read cpu infos */ 83 target->cpu_count = get_cpu_infos(&target->cpus); 82 84 } 85 86 static void free_data(data_t *target) 87 { 88 free(target->tasks); 89 } 90 91 static inline void swap(data_t *first, data_t *second) 92 { 93 data_t *temp; 94 temp = first; 95 first = second; 96 second = temp; 97 } 98 99 static data_t data[2]; 83 100 84 101 int main(int argc, char *argv[]) 85 102 { 86 data_t old_data;87 data_t new_data;103 data_t *data1 = &data[0]; 104 data_t *data2 = &data[1]; 88 105 89 106 /* Read initial stats */ 90 107 printf("Reading initial data...\n"); 91 read_ vars(&old_data);108 read_data(data1); 92 109 sleep(UPDATE_INTERVAL); 93 read_vars(&new_data); 94 print_data(&new_data); 95 fflush(stdout); 110 read_data(data2); 96 111 97 112 screen_init(); 113 print_data(data2); 98 114 99 115 /* And paint screen until death... */ … … 101 117 char c = tgetchar(UPDATE_INTERVAL); 102 118 if (c < 0) { 103 read_vars(&new_data); 104 print_data(&new_data); 119 free_data(data1); 120 swap(data1, data2); 121 read_data(data2); 122 print_data(data2); 105 123 continue; 106 124 } 107 125 switch (c) { 108 126 case 'q': 127 clear_screen(); 109 128 return 0; 110 129 default: 111 moveto(10,10); 112 printf("Unknown command: %c", c); 113 fflush(stdout); 130 PRINT_WARNING("Unknown command: %c", c); 114 131 break; 115 132 } … … 117 134 } 118 135 119 free(new_data.tasks); 120 puts("\n\n"); 121 fflush(stdout); 136 free_data(data1); 137 free_data(data2); 122 138 return 0; 123 139 } -
uspace/app/top/top.h
r8f56d93 r8b2aba5 35 35 36 36 #include <task.h> 37 #include <kernel/ps/cpuinfo.h> 37 38 38 39 typedef struct { … … 50 51 task_id_t *tasks; 51 52 unsigned int task_count; 53 54 uspace_cpu_info_t *cpus; 55 unsigned int cpu_count; 52 56 } data_t; 53 57
Note:
See TracChangeset
for help on using the changeset viewer.