Rev 7362 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7361 | leency | 1 | /* |
2 | * System Monitor |
||
3 | * version 0.7 |
||
4 | * Author: Leency |
||
5 | */ |
||
6 | |||
7 | #define MEMSIZE 4096*10 |
||
8 | |||
9 | #include "../lib/io.h" |
||
10 | #include "../lib/gui.h" |
||
11 | |||
12 | #include "../lib/obj/libio.h" |
||
13 | #include "../lib/obj/libimg.h" |
||
14 | #include "../lib/obj/libini.h" |
||
15 | |||
16 | //===================================================// |
||
17 | // // |
||
18 | // SENSOR // |
||
19 | // // |
||
20 | //===================================================// |
||
21 | |||
22 | #define MIN_PB_BLOCK_W 19 |
||
23 | #define LOAD_BG 0xFFFfff |
||
24 | #define LOAD_ACTIVE 0x4C52FF |
||
25 | |||
26 | struct sensor { |
||
27 | int x,y,w,h; |
||
28 | void set_size(); |
||
29 | void draw_wrapper(); |
||
30 | void draw_progress(); |
||
31 | }; |
||
32 | |||
33 | void sensor::set_size(dword _x, _y, _w, _h) |
||
34 | { |
||
35 | x=_x+2; |
||
36 | y=_y; |
||
37 | w=_w; |
||
38 | h=_h; |
||
39 | } |
||
40 | |||
41 | void sensor::draw_wrapper() |
||
42 | { |
||
43 | DrawRectangle(x-1, y-1, w+1, h+1, system.color.work_graph); |
||
44 | DrawRectangle3D(x-2, y-2, w+3, h+3, system.color.work_dark, system.color.work_light); |
||
45 | } |
||
46 | |||
47 | void sensor::draw_progress(dword progress_w, active_value, bg_value, mesure) |
||
48 | { |
||
49 | if (progress_w < MIN_PB_BLOCK_W) progress_w = MIN_PB_BLOCK_W; |
||
50 | if (progress_w > w-MIN_PB_BLOCK_W) progress_w = w-MIN_PB_BLOCK_W; |
||
51 | |||
52 | DrawBar(x, y, w-progress_w, h, LOAD_ACTIVE); |
||
53 | sprintf(#param, "%i%s", active_value, mesure); |
||
54 | WriteText(w-progress_w- calc(strlen(#param)*8) /2 + x, h/2-7+y, 0x90, LOAD_BG, #param); |
||
55 | |||
56 | DrawBar(x+w-progress_w, y, progress_w, h, LOAD_BG); |
||
57 | sprintf(#param, "%i%s", bg_value, mesure); |
||
58 | WriteText(-progress_w - calc(strlen(#param)*8)/2 + w+x, h/2-7+y, 0x90, LOAD_ACTIVE, #param); |
||
59 | } |
||
60 | |||
61 | //===================================================// |
||
62 | // // |
||
63 | // GetSizeDir // |
||
64 | // // |
||
65 | //===================================================// |
||
66 | |||
67 | BDVK file_info_dirsize; |
||
68 | dword dir_count; |
||
69 | dword file_count; |
||
70 | dword size_dir; |
||
71 | |||
72 | void GetDirSizeAndCountFiles(dword way) |
||
73 | { |
||
74 | dir_count=0; |
||
75 | file_count=0; |
||
76 | size_dir=0; |
||
77 | GetDirSizeAndCountFiles_loop(way); |
||
78 | } |
||
79 | |||
80 | void GetDirSizeAndCountFiles_loop(dword way) |
||
81 | { |
||
82 | dword dirbuf, fcount, i, filename; |
||
83 | dword cur_file; |
||
84 | if (dir_exists(way)) |
||
85 | { |
||
86 | cur_file = malloc(4096); |
||
87 | // In the process of recursive descent, memory must be allocated dynamically, |
||
88 | // because the static memory -> was a bug !!! But unfortunately pass away to sacrifice speed. |
||
89 | GetDir(#dirbuf, #fcount, way, DIRS_ONLYREAL); |
||
90 | for (i=0; i |
||
91 | { |
||
92 | filename = i*304+dirbuf+72; |
||
93 | sprintf(cur_file,"%s/%s",way,filename); |
||
94 | |||
95 | if (TestBit(ESDWORD[filename-40], 4) ) |
||
96 | { |
||
97 | dir_count++; |
||
98 | GetDirSizeAndCountFiles_loop(cur_file); |
||
99 | } |
||
100 | else |
||
101 | { |
||
102 | GetFileInfo(cur_file, #file_info_dirsize); |
||
103 | size_dir += file_info_dirsize.sizelo; |
||
104 | file_count++; |
||
105 | } |
||
106 | } |
||
107 | free(cur_file); |
||
108 | } |
||
109 | } |
||
110 | |||
111 | //===================================================// |
||
112 | // // |
||
113 | // DATA // |
||
114 | // // |
||
115 | //===================================================// |
||
116 | |||
117 | #define CPU_STACK 440 |
||
118 | dword cpu_stack[CPU_STACK]; |
||
119 | |||
120 | sensor cpu; |
||
121 | sensor ram; |
||
122 | sensor rd; |
||
123 | sensor tmp[10]; |
||
124 | |||
125 | //===================================================// |
||
126 | // // |
||
127 | // CODE // |
||
128 | // // |
||
129 | //===================================================// |
||
130 | |||
131 | void main() |
||
132 | { |
||
133 | proc_info Form; |
||
134 | dword cpu_frequency = GetCpuFrequency()/1000; |
||
135 | int id; |
||
136 | |||
137 | incn y; |
||
138 | |||
139 | load_dll(libio, #libio_init,1); |
||
140 | load_dll(libimg, #libimg_init,1); |
||
141 | load_dll(libini, #lib_init,1); |
||
142 | |||
143 | loop() |
||
144 | { |
||
145 | WaitEventTimeout(25); |
||
146 | switch(EAX & 0xFF) |
||
147 | { |
||
148 | case evButton: |
||
149 | if (GetButtonID()) ExitProcess(); |
||
150 | break; |
||
151 | |||
152 | case evKey: |
||
153 | GetKeys(); |
||
154 | if (key_scancode == SCAN_CODE_ESC) ExitProcess(); |
||
155 | break; |
||
156 | |||
157 | case evReDraw: |
||
158 | #define LEFT 25 |
||
159 | #define ICONGAP 45 |
||
160 | system.color.get(); |
||
161 | DefineAndDrawWindow(150, 100, CPU_STACK+LEFT+LEFT+4+9, 480 + skin_height + 4, 0x34, system.color.work, "System Monitor",0); |
||
162 | GetProcessInfo(#Form, SelfInfo); |
||
163 | |||
164 | y.n = 0; |
||
165 | WriteTextB(LEFT+ICONGAP, y.inc(20), 0x90, system.color.work_text, "CPU load"); |
||
166 | DrawIcon32(LEFT, y.n, system.color.work, 37); |
||
167 | |||
168 | if (cpu_frequency < 1000) sprintf(#param, "CPU frequency: %i Hz", cpu_frequency); |
||
169 | else sprintf(#param, "CPU frequency: %i MHz", cpu_frequency/1000); |
||
170 | WriteText(LEFT+ICONGAP, y.inc(20), 0x90, system.color.work_text, #param); |
||
171 | cpu.set_size(LEFT, y.inc(25), CPU_STACK, 100); |
||
172 | cpu.draw_wrapper(); |
||
173 | |||
174 | WriteTextB(LEFT+ICONGAP, y.inc(cpu.h + 25), 0x90, system.color.work_text, "RAM usage"); |
||
175 | DrawIcon32(LEFT, y.n, system.color.work, 36); |
||
176 | sprintf(#param, "Total RAM: %i MiB", GetTotalRAM()/1024); |
||
177 | WriteText(LEFT+ICONGAP, y.inc(20), 0x90, system.color.work_text, #param); |
||
178 | ram.set_size(LEFT, y.inc(25), CPU_STACK, 25); |
||
179 | ram.draw_wrapper(); |
||
180 | |||
181 | WriteTextB(LEFT+ICONGAP, y.inc(ram.h + 25), 0x90, system.color.work_text, "System RAM Disk usage"); |
||
182 | DrawIcon32(LEFT, y.n, system.color.work, 3); |
||
183 | WriteText(LEFT+ICONGAP, y.inc(20), 0x90, system.color.work_text, "Fixed size: 1.44 MiB"); |
||
184 | rd.set_size(LEFT, y.inc(25), CPU_STACK, 25); |
||
185 | rd.draw_wrapper(); |
||
186 | |||
187 | WriteTextB(LEFT+ICONGAP, y.inc(ram.h + 25), 0x90, system.color.work_text, "Virtual drive usage"); |
||
188 | DrawIcon32(LEFT, y.n, system.color.work, 50); |
||
189 | WriteText(LEFT+ICONGAP, y.inc(20), 0x90, system.color.work_text, "TMP Disk 0 size: 49 MiB"); |
||
190 | tmp[0].set_size(LEFT, y.inc(25), CPU_STACK, 25); |
||
191 | tmp[0].draw_wrapper(); |
||
192 | |||
193 | default: |
||
194 | MonitorCpu(); |
||
195 | |||
196 | ram.draw_progress( |
||
197 | GetFreeRAM()*ram.w/GetTotalRAM(), |
||
198 | GetTotalRAM()-GetFreeRAM()/1024, |
||
199 | GetFreeRAM()/1024, |
||
200 | "M" |
||
201 | ); |
||
202 | |||
203 | GetDirSizeAndCountFiles("/rd/1"); |
||
204 | size_dir += 32*512; //add FAT table size |
||
205 | size_dir += file_count*512/2; //add MAGIC NUMBER |
||
206 | size_dir /= 1024; //convert to KiB |
||
207 | size_dir= 1440 - size_dir; |
||
208 | rd.draw_progress( |
||
209 | size_dir*rd.w/1440, |
||
210 | 1440-size_dir, |
||
211 | size_dir, |
||
212 | "K" |
||
213 | ); |
||
214 | |||
215 | GetDirSizeAndCountFiles("/tmp0/1"); |
||
216 | size_dir += 32*512; //add FAT table size |
||
217 | size_dir += file_count*512/2; //add MAGIC NUMBER |
||
218 | size_dir /= 1024*1024; //convert to MiB |
||
219 | size_dir= 49 - size_dir; |
||
220 | tmp[0].draw_progress( |
||
221 | size_dir*tmp[0].w/49, |
||
222 | 49-size_dir, |
||
223 | size_dir, |
||
224 | "M" |
||
225 | ); |
||
226 | } |
||
227 | } |
||
228 | } |
||
229 | |||
230 | dword GetCpuLoad(dword max_h) |
||
231 | { |
||
232 | dword idle; |
||
233 | dword CPU_SEC = GetCpuFrequency() >> 20 + 1; |
||
234 | dword IDLE_SEC = GetCpuIdleCount() >> 20 * max_h; |
||
235 | |||
236 | EAX = IDLE_SEC; |
||
237 | EBX = CPU_SEC; |
||
238 | $cdq |
||
239 | $div ebx |
||
240 | idle = EAX; |
||
241 | |||
242 | return max_h - idle; |
||
243 | } |
||
244 | |||
245 | //===================================================// |
||
246 | // // |
||
247 | // MONITORS // |
||
248 | // // |
||
249 | //===================================================// |
||
250 | |||
251 | int pos=0; |
||
252 | void MonitorCpu() |
||
253 | { |
||
254 | int i; |
||
255 | if (!cpu.w) return; |
||
256 | |||
257 | cpu_stack[pos] = GetCpuLoad(cpu.h); |
||
258 | if (cpu_stack[pos]<=2) || (cpu_stack[pos]>cpu.h) cpu_stack[pos]=2; |
||
259 | |||
260 | DrawBar(cpu.x+cpu.w-30, cpu.y-25, 30, 20, system.color.work); |
||
261 | sprintf(#param, "%i%%", cpu_stack[pos]); |
||
262 | WriteText(cpu.x+cpu.w-calc(strlen(#param)*8), cpu.y-25, 0x90, system.color.work_text, #param); |
||
263 | |||
264 | for (i=0; i |
||
265 | DrawBar(i+cpu.x, cpu.y, 1, cpu.h-cpu_stack[i], LOAD_BG); |
||
266 | DrawBar(i+cpu.x, cpu.h-cpu_stack[i]+cpu.y, 1, cpu_stack[i], LOAD_ACTIVE); |
||
267 | |||
268 | DrawBar(i+1+cpu.x, cpu.y, 1, cpu.h, LOAD_BG); |
||
269 | } |
||
270 | |||
271 | pos++; |
||
272 | if (pos>=CPU_STACK) { |
||
273 | pos = CPU_STACK-1; |
||
274 | for (i=0; i |
||
275 | cpu_stack[i] = cpu_stack[i+1]; |
||
276 | } |
||
277 | } |
||
278 | }=2)>>> |