source: mainline/uspace/app/top/screen.c@ 516adce

lfn serial ticket/834-toolchain-update topic/fix-logger-deadlock topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 516adce was 516adce, checked in by Stanislav Kozina <stanislav.kozina@…>, 16 years ago

top echoes also physical memory overview

  • Property mode set to 100644
File size: 5.1 KB
Line 
1/*
2 * Copyright (c) 2010 Stanislav Kozina
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup top
30 * @brief Top utility.
31 * @{
32 */
33/**
34 * @file
35 */
36
37#include <stdio.h>
38#include <io/console.h>
39#include <vfs/vfs.h>
40#include <load.h>
41#include <kernel/ps/taskinfo.h>
42#include <ps.h>
43#include "screen.h"
44#include "top.h"
45#include "func.h"
46
47int rows;
48int colls;
49int up_rows;
50
51#define WHITE 0xf0f0f0
52#define BLACK 0x000000
53
54static void print_float(float f, int precision)
55{
56 printf("%2u.", (unsigned int) f);
57 int i;
58 float rest = (f - (int)f) * 10;
59 for (i = 0; i < precision; ++i) {
60 printf("%d", (unsigned int)rest);
61 rest = (rest - (int)rest) * 10;
62 }
63}
64
65static void resume_normal(void)
66{
67 fflush(stdout);
68 console_set_rgb_color(fphone(stdout), 0, WHITE);
69}
70
71void screen_init(void)
72{
73 console_get_size(fphone(stdout), &colls, &rows);
74 up_rows = 0;
75 console_cursor_visibility(fphone(stdout), 0);
76 resume_normal();
77 clear_screen();
78}
79
80void clear_screen(void)
81{
82 console_clear(fphone(stdout));
83 moveto(0, 0);
84 up_rows = 0;
85 fflush(stdout);
86}
87
88void moveto(int r, int c)
89{
90 fflush(stdout);
91 console_goto(fphone(stdout), c, r);
92}
93
94static inline void print_time(data_t *data)
95{
96 printf("%02d:%02d:%02d ", data->hours, data->minutes, data->seconds);
97}
98
99static inline void print_uptime(data_t *data)
100{
101 printf("up %4d days, %02d:%02d:%02d, ", data->uptime_d, data->uptime_h,
102 data->uptime_m, data->uptime_s);
103}
104
105static inline void print_load(data_t *data)
106{
107 puts("load avarage: ");
108 print_load_fragment(data->load[0], 2);
109 puts(" ");
110 print_load_fragment(data->load[1], 2);
111 puts(" ");
112 print_load_fragment(data->load[2], 2);
113}
114
115static inline void print_taskstat(data_t *data)
116{
117 puts("Tasks: ");
118 printf("%4u total", data->task_count);
119}
120
121static inline void print_cpuinfo(data_t *data)
122{
123 unsigned int i;
124 uspace_cpu_info_t *cpus = data->cpus;
125 for (i = 0; i < data->cpu_count; ++i) {
126 printf("Cpu%u (%4u Mhz): Busy ticks: %6llu, Idle Ticks: %6llu",
127 i, (unsigned int)cpus[i].frequency_mhz, cpus[i].busy_ticks,
128 cpus[i].idle_ticks);
129 printf(", idle: ");
130 print_float(data->cpu_perc[i].idle, 2);
131 puts("%, busy: ");
132 print_float(data->cpu_perc[i].busy, 2);
133 puts("%\n");
134 ++up_rows;
135 }
136}
137
138static inline void print_meminfo(data_t *data)
139{
140 uint64_t newsize;
141 char suffix;
142 order(data->mem_info.total, &newsize, &suffix);
143 printf("Mem: %8llu %c total", newsize, suffix);
144 order(data->mem_info.used, &newsize, &suffix);
145 printf(", %8llu %c used", newsize, suffix);
146 order(data->mem_info.free, &newsize, &suffix);
147 printf(", %8llu %c free", newsize, suffix);
148}
149
150static inline void print_tasks(data_t *data, int row)
151{
152 int i;
153 for (i = 0; i < (int)data->task_count; ++i) {
154 if (row + i > rows)
155 return;
156 task_info_t *taskinfo = &data->taskinfos[i];
157 printf("%8llu %8u %8u ", taskinfo->taskid,
158 taskinfo->thread_count, taskinfo->pages);
159 task_perc_t *taskperc = &data->task_perc[i];
160 puts(" ");
161 print_float(taskperc->pages, 2);
162 puts("% ");
163 print_float(taskperc->ucycles, 2);
164 puts("% ");
165 print_float(taskperc->kcycles, 2);
166 puts("% ");
167 printf("%s\n", taskinfo->name);
168 }
169}
170
171static inline void print_head(void)
172{
173 fflush(stdout);
174 console_set_rgb_color(fphone(stdout), WHITE, BLACK);
175 printf(" ID Threads Pages %%Pages %%uCycles %%kCycles Name");
176 int i;
177 for (i = 60; i < colls; ++i)
178 puts(" ");
179 fflush(stdout);
180 console_set_rgb_color(fphone(stdout), BLACK, WHITE);
181}
182
183void print_data(data_t *data)
184{
185 clear_screen();
186 fflush(stdout);
187 printf("top - ");
188 print_time(data);
189 print_uptime(data);
190 print_load(data);
191 puts("\n");
192 ++up_rows;
193 print_taskstat(data);
194 puts("\n");
195 ++up_rows;
196 print_cpuinfo(data);
197 print_meminfo(data);
198 puts("\n");
199 ++up_rows;
200 puts("\n");
201 ++up_rows;
202 print_head();
203 puts("\n");
204 print_tasks(data, up_rows);
205 fflush(stdout);
206}
207
208/** @}
209 */
Note: See TracBrowser for help on using the repository browser.