Rev 7373 | Rev 7491 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7361 | leency | 1 | /* |
2 | * System Monitor |
||
7422 | leency | 3 | * version 0.87 |
7361 | leency | 4 | * Author: Leency |
5 | */ |
||
6 | |||
7 | #define MEMSIZE 4096*10 |
||
8 | |||
9 | #include "../lib/io.h" |
||
10 | #include "../lib/gui.h" |
||
7369 | leency | 11 | #include "../lib/fs.h" |
7361 | leency | 12 | |
13 | #include "../lib/obj/libio.h" |
||
14 | #include "../lib/obj/libimg.h" |
||
15 | #include "../lib/obj/libini.h" |
||
16 | |||
17 | //===================================================// |
||
18 | // // |
||
19 | // SENSOR // |
||
20 | // // |
||
21 | //===================================================// |
||
22 | |||
23 | #define MIN_PB_BLOCK_W 19 |
||
7422 | leency | 24 | #define LOAD_CPU 0x2460C8 |
25 | #define PROGRESS_ACTIVE 0x489FE4 |
||
26 | #define PROGRESS_BG 0xFFFfff |
||
27 | #define PROGRESS_BG_TEXT 0x696969 |
||
7361 | leency | 28 | |
29 | struct sensor { |
||
30 | int x,y,w,h; |
||
31 | void set_size(); |
||
32 | void draw_wrapper(); |
||
33 | void draw_progress(); |
||
34 | }; |
||
35 | |||
36 | void sensor::set_size(dword _x, _y, _w, _h) |
||
37 | { |
||
38 | x=_x+2; |
||
39 | y=_y; |
||
40 | w=_w; |
||
41 | h=_h; |
||
7369 | leency | 42 | draw_wrapper(); |
7361 | leency | 43 | } |
44 | |||
45 | void sensor::draw_wrapper() |
||
46 | { |
||
47 | DrawRectangle(x-1, y-1, w+1, h+1, system.color.work_graph); |
||
48 | DrawRectangle3D(x-2, y-2, w+3, h+3, system.color.work_dark, system.color.work_light); |
||
49 | } |
||
50 | |||
51 | void sensor::draw_progress(dword progress_w, active_value, bg_value, mesure) |
||
52 | { |
||
53 | if (progress_w < MIN_PB_BLOCK_W) progress_w = MIN_PB_BLOCK_W; |
||
54 | if (progress_w > w-MIN_PB_BLOCK_W) progress_w = w-MIN_PB_BLOCK_W; |
||
55 | |||
7422 | leency | 56 | |
57 | DrawBar(x, y, w-progress_w, 1, MixColors(PROGRESS_ACTIVE, PROGRESS_BG, 200)); |
||
58 | DrawBar(x, y+1, w-progress_w, h-2, PROGRESS_ACTIVE); |
||
59 | DrawBar(x, y+h-1, w-progress_w, 1, MixColors(PROGRESS_ACTIVE, system.color.work_graph, 200)); |
||
60 | |||
61 | |||
7361 | leency | 62 | sprintf(#param, "%i%s", active_value, mesure); |
7422 | leency | 63 | WriteText(w-progress_w- calc(strlen(#param)*8) /2 + x, h/2-7+y, 0x90, PROGRESS_BG, #param); |
7361 | leency | 64 | |
7422 | leency | 65 | DrawBar(x+w-progress_w, y, progress_w, h, PROGRESS_BG); |
7361 | leency | 66 | sprintf(#param, "%i%s", bg_value, mesure); |
7422 | leency | 67 | WriteText(-progress_w - calc(strlen(#param)*8)/2 + w+x, h/2-7+y, 0x90, PROGRESS_BG_TEXT, #param); |
7361 | leency | 68 | } |
69 | |||
70 | //===================================================// |
||
71 | // // |
||
72 | // DATA // |
||
73 | // // |
||
74 | //===================================================// |
||
75 | |||
76 | #define CPU_STACK 440 |
||
77 | dword cpu_stack[CPU_STACK]; |
||
78 | |||
79 | sensor cpu; |
||
80 | sensor ram; |
||
81 | sensor rd; |
||
82 | sensor tmp[10]; |
||
83 | |||
7369 | leency | 84 | dword tmp_size[10]; |
85 | |||
7361 | leency | 86 | //===================================================// |
87 | // // |
||
88 | // CODE // |
||
89 | // // |
||
90 | //===================================================// |
||
91 | |||
92 | void main() |
||
93 | { |
||
94 | proc_info Form; |
||
95 | dword cpu_frequency = GetCpuFrequency()/1000; |
||
96 | int id; |
||
97 | |||
98 | incn y; |
||
99 | |||
100 | load_dll(libio, #libio_init,1); |
||
101 | load_dll(libimg, #libimg_init,1); |
||
102 | load_dll(libini, #lib_init,1); |
||
7369 | leency | 103 | |
104 | GetTmpDiskSizesFromIni(); |
||
7361 | leency | 105 | |
106 | loop() |
||
107 | { |
||
108 | WaitEventTimeout(25); |
||
109 | switch(EAX & 0xFF) |
||
110 | { |
||
111 | case evButton: |
||
112 | if (GetButtonID()) ExitProcess(); |
||
113 | break; |
||
114 | |||
115 | case evKey: |
||
116 | GetKeys(); |
||
117 | if (key_scancode == SCAN_CODE_ESC) ExitProcess(); |
||
118 | break; |
||
119 | |||
120 | case evReDraw: |
||
121 | #define LEFT 25 |
||
122 | #define ICONGAP 45 |
||
123 | system.color.get(); |
||
124 | DefineAndDrawWindow(150, 100, CPU_STACK+LEFT+LEFT+4+9, 480 + skin_height + 4, 0x34, system.color.work, "System Monitor",0); |
||
125 | GetProcessInfo(#Form, SelfInfo); |
||
126 | |||
127 | y.n = 0; |
||
128 | if (cpu_frequency < 1000) sprintf(#param, "CPU frequency: %i Hz", cpu_frequency); |
||
129 | else sprintf(#param, "CPU frequency: %i MHz", cpu_frequency/1000); |
||
7369 | leency | 130 | DrawBlockHeader(LEFT, y.inc(20), 37, "CPU load", #param); |
131 | cpu.set_size(LEFT, y.inc(45), CPU_STACK, 100); |
||
7361 | leency | 132 | |
133 | sprintf(#param, "Total RAM: %i MiB", GetTotalRAM()/1024); |
||
7369 | leency | 134 | DrawBlockHeader(LEFT, y.inc(cpu.h + 25), 36, "RAM usage", #param); |
135 | ram.set_size(LEFT, y.inc(45), CPU_STACK, 23); |
||
7361 | leency | 136 | |
7369 | leency | 137 | DrawBlockHeader(LEFT, y.inc(ram.h + 25), 3, "System RAM Disk usage", "Fixed size: 1.44 MiB"); |
138 | rd.set_size(LEFT, y.inc(45), CPU_STACK, 23); |
||
7361 | leency | 139 | |
7369 | leency | 140 | sprintf(#param, "TMP Disk 0 size: %i MiB", tmp_size[0]); |
141 | DrawBlockHeader(LEFT, y.inc(rd.h + 25), 50, "Virtual drive usage", #param); |
||
142 | tmp[0].set_size(LEFT, y.inc(45), CPU_STACK, 23); |
||
7361 | leency | 143 | |
144 | default: |
||
145 | MonitorCpu(); |
||
146 | |||
7373 | leency | 147 | //MonitorRam(); |
7361 | leency | 148 | ram.draw_progress( |
149 | GetFreeRAM()*ram.w/GetTotalRAM(), |
||
150 | GetTotalRAM()-GetFreeRAM()/1024, |
||
151 | GetFreeRAM()/1024, |
||
152 | "M" |
||
153 | ); |
||
7373 | leency | 154 | DrawBar(ram.x+ram.w-96, ram.y-25, 96, 20, system.color.work); |
155 | sprintf(#param, "%i KiB", GetTotalRAM()-GetFreeRAM()); |
||
156 | WriteText(ram.x+ram.w-calc(strlen(#param)*8), ram.y-25, 0x90, system.color.work_text, #param); |
||
7361 | leency | 157 | |
7373 | leency | 158 | //MonitorRd(); |
159 | dir_size.get("/rd/1"); |
||
7369 | leency | 160 | dir_size.bytes += dir_size.files/2 + 32 * 512; //file attr size + FAT table size |
161 | dir_size.bytes /= 1024; //convert to KiB |
||
162 | dir_size.bytes = 1440 - dir_size.bytes; |
||
7361 | leency | 163 | rd.draw_progress( |
7369 | leency | 164 | dir_size.bytes*rd.w/1440, |
165 | 1440 - dir_size.bytes, |
||
166 | dir_size.bytes, |
||
7361 | leency | 167 | "K" |
168 | ); |
||
169 | |||
7373 | leency | 170 | //MonitorTmp(); |
7369 | leency | 171 | if (tmp_size[0]) { |
172 | dir_size.get("/tmp0/1"); |
||
173 | dir_size.bytes += dir_size.files/2 + 32 * 512; //file attr size + FAT table size |
||
174 | dir_size.bytes /= 1024*1024; //convert to MiB |
||
175 | dir_size.bytes= tmp_size[0] - dir_size.bytes; |
||
176 | tmp[0].draw_progress( |
||
177 | dir_size.bytes*tmp[0].w/tmp_size[0], |
||
178 | tmp_size[0] - dir_size.bytes, |
||
179 | dir_size.bytes, |
||
180 | "M" |
||
181 | ); |
||
182 | } |
||
7361 | leency | 183 | } |
184 | } |
||
185 | } |
||
186 | |||
7369 | leency | 187 | void DrawBlockHeader(dword _x, _y, _icon, _title, _subtitle) |
188 | { |
||
189 | WriteTextB(_x+ICONGAP, _y, 0x90, system.color.work_text, _title); |
||
190 | DrawIcon32(_x, _y, system.color.work, _icon); |
||
191 | WriteText(_x+ICONGAP, _y+20, 0x90, system.color.work_text, _subtitle); |
||
192 | } |
||
193 | |||
7361 | leency | 194 | dword GetCpuLoad(dword max_h) |
195 | { |
||
196 | dword idle; |
||
197 | dword CPU_SEC = GetCpuFrequency() >> 20 + 1; |
||
198 | dword IDLE_SEC = GetCpuIdleCount() >> 20 * max_h; |
||
199 | |||
200 | EAX = IDLE_SEC; |
||
201 | EBX = CPU_SEC; |
||
202 | $cdq |
||
203 | $div ebx |
||
204 | idle = EAX; |
||
205 | |||
206 | return max_h - idle; |
||
207 | } |
||
208 | |||
7369 | leency | 209 | _ini ini = { "/sys/settings/system.ini", "DiskSizes" }; |
210 | void GetTmpDiskSizesFromIni() |
||
211 | { |
||
212 | char i, key[2]; |
||
213 | key[1]=0; |
||
214 | for (i=0; i<=9; i++) |
||
215 | { |
||
216 | key[0]=i+'0'; |
||
217 | tmp_size[i] = ini.GetInt(#key, 0) / 1024 / 1024; |
||
218 | } |
||
219 | } |
||
220 | |||
7361 | leency | 221 | //===================================================// |
222 | // // |
||
223 | // MONITORS // |
||
224 | // // |
||
225 | //===================================================// |
||
226 | |||
227 | int pos=0; |
||
228 | void MonitorCpu() |
||
229 | { |
||
230 | int i; |
||
231 | if (!cpu.w) return; |
||
232 | |||
233 | cpu_stack[pos] = GetCpuLoad(cpu.h); |
||
234 | if (cpu_stack[pos]<=2) || (cpu_stack[pos]>cpu.h) cpu_stack[pos]=2; |
||
235 | |||
236 | DrawBar(cpu.x+cpu.w-30, cpu.y-25, 30, 20, system.color.work); |
||
237 | sprintf(#param, "%i%%", cpu_stack[pos]); |
||
238 | WriteText(cpu.x+cpu.w-calc(strlen(#param)*8), cpu.y-25, 0x90, system.color.work_text, #param); |
||
239 | |||
240 | for (i=0; i |
||
7422 | leency | 241 | DrawBar(i+cpu.x, cpu.y, 1, cpu.h-cpu_stack[i], PROGRESS_BG); |
242 | DrawBar(i+cpu.x, cpu.h-cpu_stack[i]+cpu.y, 1, cpu_stack[i], LOAD_CPU); |
||
7361 | leency | 243 | |
7422 | leency | 244 | DrawBar(i+1+cpu.x, cpu.y, 1, cpu.h, PROGRESS_BG); |
7361 | leency | 245 | } |
246 | |||
247 | pos++; |
||
248 | if (pos>=CPU_STACK) { |
||
249 | pos = CPU_STACK-1; |
||
250 | for (i=0; i |
||
251 | cpu_stack[i] = cpu_stack[i+1]; |
||
252 | } |
||
253 | } |
||
254 | }=2)>=9;>>> |