Subversion Repositories Kolibri OS

Rev

Rev 7491 | Rev 7806 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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