Rev 7491 | Rev 7614 | 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 | // DATA // |
||
20 | // // |
||
21 | //===================================================// |
||
22 | |||
23 | #define CPU_STACK 440 |
||
24 | dword cpu_stack[CPU_STACK]; |
||
25 | |||
26 | sensor cpu; |
||
27 | sensor ram; |
||
28 | sensor rd; |
||
29 | sensor tmp[10]; |
||
30 | |||
7369 | leency | 31 | dword tmp_size[10]; |
32 | |||
7361 | leency | 33 | //===================================================// |
34 | // // |
||
35 | // CODE // |
||
36 | // // |
||
37 | //===================================================// |
||
38 | |||
39 | void main() |
||
40 | { |
||
41 | proc_info Form; |
||
42 | dword cpu_frequency = GetCpuFrequency()/1000; |
||
43 | int id; |
||
44 | |||
45 | incn y; |
||
46 | |||
47 | load_dll(libio, #libio_init,1); |
||
48 | load_dll(libimg, #libimg_init,1); |
||
49 | load_dll(libini, #lib_init,1); |
||
7369 | leency | 50 | |
7532 | leency | 51 | GetTmpDiskSizes(); |
7361 | leency | 52 | |
53 | loop() |
||
54 | { |
||
55 | WaitEventTimeout(25); |
||
56 | switch(EAX & 0xFF) |
||
57 | { |
||
58 | case evButton: |
||
59 | if (GetButtonID()) ExitProcess(); |
||
60 | break; |
||
61 | |||
62 | case evKey: |
||
63 | GetKeys(); |
||
64 | if (key_scancode == SCAN_CODE_ESC) ExitProcess(); |
||
65 | break; |
||
66 | |||
67 | case evReDraw: |
||
68 | #define LEFT 25 |
||
69 | #define ICONGAP 45 |
||
70 | system.color.get(); |
||
71 | DefineAndDrawWindow(150, 100, CPU_STACK+LEFT+LEFT+4+9, 480 + skin_height + 4, 0x34, system.color.work, "System Monitor",0); |
||
72 | GetProcessInfo(#Form, SelfInfo); |
||
73 | |||
74 | y.n = 0; |
||
75 | if (cpu_frequency < 1000) sprintf(#param, "CPU frequency: %i Hz", cpu_frequency); |
||
76 | else sprintf(#param, "CPU frequency: %i MHz", cpu_frequency/1000); |
||
7369 | leency | 77 | DrawBlockHeader(LEFT, y.inc(20), 37, "CPU load", #param); |
78 | cpu.set_size(LEFT, y.inc(45), CPU_STACK, 100); |
||
7361 | leency | 79 | |
80 | sprintf(#param, "Total RAM: %i MiB", GetTotalRAM()/1024); |
||
7369 | leency | 81 | DrawBlockHeader(LEFT, y.inc(cpu.h + 25), 36, "RAM usage", #param); |
82 | ram.set_size(LEFT, y.inc(45), CPU_STACK, 23); |
||
7361 | leency | 83 | |
7369 | leency | 84 | DrawBlockHeader(LEFT, y.inc(ram.h + 25), 3, "System RAM Disk usage", "Fixed size: 1.44 MiB"); |
85 | rd.set_size(LEFT, y.inc(45), CPU_STACK, 23); |
||
7361 | leency | 86 | |
7369 | leency | 87 | sprintf(#param, "TMP Disk 0 size: %i MiB", tmp_size[0]); |
88 | DrawBlockHeader(LEFT, y.inc(rd.h + 25), 50, "Virtual drive usage", #param); |
||
89 | tmp[0].set_size(LEFT, y.inc(45), CPU_STACK, 23); |
||
7361 | leency | 90 | |
91 | default: |
||
92 | MonitorCpu(); |
||
93 | |||
7373 | leency | 94 | //MonitorRam(); |
7361 | leency | 95 | ram.draw_progress( |
96 | GetFreeRAM()*ram.w/GetTotalRAM(), |
||
97 | GetTotalRAM()-GetFreeRAM()/1024, |
||
98 | GetFreeRAM()/1024, |
||
99 | "M" |
||
100 | ); |
||
7373 | leency | 101 | DrawBar(ram.x+ram.w-96, ram.y-25, 96, 20, system.color.work); |
102 | sprintf(#param, "%i KiB", GetTotalRAM()-GetFreeRAM()); |
||
103 | WriteText(ram.x+ram.w-calc(strlen(#param)*8), ram.y-25, 0x90, system.color.work_text, #param); |
||
7361 | leency | 104 | |
7373 | leency | 105 | //MonitorRd(); |
106 | dir_size.get("/rd/1"); |
||
7369 | leency | 107 | dir_size.bytes += dir_size.files/2 + 32 * 512; //file attr size + FAT table size |
108 | dir_size.bytes /= 1024; //convert to KiB |
||
109 | dir_size.bytes = 1440 - dir_size.bytes; |
||
7361 | leency | 110 | rd.draw_progress( |
7369 | leency | 111 | dir_size.bytes*rd.w/1440, |
112 | 1440 - dir_size.bytes, |
||
113 | dir_size.bytes, |
||
7361 | leency | 114 | "K" |
115 | ); |
||
116 | |||
7373 | leency | 117 | //MonitorTmp(); |
7369 | leency | 118 | if (tmp_size[0]) { |
119 | dir_size.get("/tmp0/1"); |
||
120 | dir_size.bytes += dir_size.files/2 + 32 * 512; //file attr size + FAT table size |
||
121 | dir_size.bytes /= 1024*1024; //convert to MiB |
||
122 | dir_size.bytes= tmp_size[0] - dir_size.bytes; |
||
123 | tmp[0].draw_progress( |
||
124 | dir_size.bytes*tmp[0].w/tmp_size[0], |
||
125 | tmp_size[0] - dir_size.bytes, |
||
126 | dir_size.bytes, |
||
127 | "M" |
||
128 | ); |
||
129 | } |
||
7361 | leency | 130 | } |
131 | } |
||
132 | } |
||
133 | |||
7369 | leency | 134 | void DrawBlockHeader(dword _x, _y, _icon, _title, _subtitle) |
135 | { |
||
136 | WriteTextB(_x+ICONGAP, _y, 0x90, system.color.work_text, _title); |
||
137 | DrawIcon32(_x, _y, system.color.work, _icon); |
||
138 | WriteText(_x+ICONGAP, _y+20, 0x90, system.color.work_text, _subtitle); |
||
139 | } |
||
140 | |||
7361 | leency | 141 | dword GetCpuLoad(dword max_h) |
142 | { |
||
143 | dword idle; |
||
144 | dword CPU_SEC = GetCpuFrequency() >> 20 + 1; |
||
145 | dword IDLE_SEC = GetCpuIdleCount() >> 20 * max_h; |
||
146 | |||
147 | EAX = IDLE_SEC; |
||
148 | EBX = CPU_SEC; |
||
149 | $cdq |
||
150 | $div ebx |
||
151 | idle = EAX; |
||
152 | |||
153 | return max_h - idle; |
||
154 | } |
||
155 | |||
7532 | leency | 156 | dword GetDiskSize(dword disk_n) |
7369 | leency | 157 | { |
7532 | leency | 158 | BDVK bdvk; |
159 | char tmp_path[8]; |
||
160 | strcpy(#tmp_path, "/tmp0/1"); |
||
161 | tmp_path[4] = disk_n + '0'; |
||
162 | GetFileInfo(#tmp_path, #bdvk); |
||
163 | return bdvk.sizelo; |
||
164 | } |
||
165 | void GetTmpDiskSizes() |
||
166 | { |
||
167 | char i; |
||
7369 | leency | 168 | for (i=0; i<=9; i++) |
169 | { |
||
7532 | leency | 170 | tmp_size[i] = GetDiskSize(i) / 1024 / 1024; |
7369 | leency | 171 | } |
172 | } |
||
173 | |||
7361 | leency | 174 | //===================================================// |
175 | // // |
||
176 | // MONITORS // |
||
177 | // // |
||
178 | //===================================================// |
||
179 | |||
180 | int pos=0; |
||
181 | void MonitorCpu() |
||
182 | { |
||
183 | int i; |
||
184 | if (!cpu.w) return; |
||
185 | |||
186 | cpu_stack[pos] = GetCpuLoad(cpu.h); |
||
187 | if (cpu_stack[pos]<=2) || (cpu_stack[pos]>cpu.h) cpu_stack[pos]=2; |
||
188 | |||
189 | DrawBar(cpu.x+cpu.w-30, cpu.y-25, 30, 20, system.color.work); |
||
190 | sprintf(#param, "%i%%", cpu_stack[pos]); |
||
191 | WriteText(cpu.x+cpu.w-calc(strlen(#param)*8), cpu.y-25, 0x90, system.color.work_text, #param); |
||
192 | |||
193 | for (i=0; i |
||
7422 | leency | 194 | DrawBar(i+cpu.x, cpu.y, 1, cpu.h-cpu_stack[i], PROGRESS_BG); |
195 | DrawBar(i+cpu.x, cpu.h-cpu_stack[i]+cpu.y, 1, cpu_stack[i], LOAD_CPU); |
||
7361 | leency | 196 | |
7422 | leency | 197 | DrawBar(i+1+cpu.x, cpu.y, 1, cpu.h, PROGRESS_BG); |
7361 | leency | 198 | } |
199 | |||
200 | pos++; |
||
201 | if (pos>=CPU_STACK) { |
||
202 | pos = CPU_STACK-1; |
||
203 | for (i=0; i |
||
204 | cpu_stack[i] = cpu_stack[i+1]; |
||
205 | } |
||
206 | } |
||
207 | }=2)>=9;>> |