Subversion Repositories Kolibri OS

Rev

Rev 7806 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7614 leency 1
//===================================================//
2
//                                                   //
3
//                       DATA                        //
4
//                                                   //
5
//===================================================//
6
 
7
dword cpu_stack[1980*3];
8
 
9
sensor cpu;
10
sensor ram;
11
sensor rd;
12
sensor tmp[10];
13
 
14
dword tmp_size[10];
15
 
16
//===================================================//
17
//                                                   //
18
//                       CODE                        //
19
//                                                   //
20
//===================================================//
21
 
22
void General__Main()
23
{
7878 leency 24
	DIR_SIZE dir_size;
7614 leency 25
	dword cpu_frequency;
26
	incn y;
27
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON);
28
 
29
	cpu_frequency = GetCpuFrequency()/1000;
30
	GetTmpDiskSizes();
31
 
32
	goto _GENERAL_REDRAW;
33
 
34
	loop()
35
	{
36
		WaitEventTimeout(25);
37
		switch(EAX & 0xFF)
38
		{
39
			case evButton:
40
				Sysmon__ButtonEvent(GetButtonID());
41
				break;
42
 
43
			case evKey:
44
				GetKeys();
45
				if (key_scancode == SCAN_CODE_ESC) ExitProcess();
46
				break;
47
 
48
			case evReDraw:
49
				_GENERAL_REDRAW:
50
				if (!Sysmon__DefineAndDrawWindow()) break;
51
 
52
				y.n = WIN_CONTENT_Y;
53
				if (cpu_frequency < 1000) sprintf(#param, "CPU frequency: %i Hz", cpu_frequency);
54
				else sprintf(#param, "CPU frequency: %i MHz", cpu_frequency/1000);
55
				DrawBlockHeader(WIN_PAD, y.inc(0), 37, "CPU load", #param);
56
				cpu.set_size(WIN_PAD, y.inc(45), WIN_CONTENT_W, 100);
57
 
58
				sprintf(#param, "Total RAM: %i MiB", GetTotalRAM()/1024);
59
				DrawBlockHeader(WIN_PAD, y.inc(cpu.h + 25), 36, "RAM usage", #param);
60
				ram.set_size(WIN_PAD, y.inc(45), WIN_CONTENT_W, 23);
61
 
62
				DrawBlockHeader(WIN_PAD, y.inc(ram.h + 25), 3, "System RAM Disk usage", "Fixed size: 1.44 MiB");
63
				rd.set_size(WIN_PAD, y.inc(45), WIN_CONTENT_W, 23);
64
 
65
				sprintf(#param, "TMP Disk 0 size: %i MiB", tmp_size[0]);
66
				DrawBlockHeader(WIN_PAD, y.inc(rd.h + 25), 50, "Virtual drive usage", #param);
67
				tmp[0].set_size(WIN_PAD, y.inc(45), WIN_CONTENT_W, 23);
68
 
69
			default:
70
				MonitorCpu();
71
 
72
				//MonitorRam();
73
				ram.draw_progress(
74
					GetFreeRAM()*ram.w/GetTotalRAM(),
75
					GetTotalRAM()-GetFreeRAM()/1024,
76
					GetFreeRAM()/1024,
77
					"M"
78
					);
7806 leency 79
				DrawBar(ram.x+ram.w-96, ram.y-25, 96, 20, sc.work);
7614 leency 80
				sprintf(#param, "%i KiB", GetTotalRAM()-GetFreeRAM());
7806 leency 81
				WriteText(ram.x+ram.w-calc(strlen(#param)*8), ram.y-25, 0x90, sc.work_text, #param);
7614 leency 82
 
83
				//MonitorRd();
84
				dir_size.get("/rd/1");
85
				dir_size.bytes += dir_size.files/2 + 32 * 512; //file attr size + FAT table size
86
				dir_size.bytes /= 1024; //convert to KiB
87
				dir_size.bytes = 1440 - dir_size.bytes;
88
				rd.draw_progress(
89
					dir_size.bytes*rd.w/1440,
90
					1440 - dir_size.bytes,
91
					dir_size.bytes,
92
					"K"
93
					);
94
 
95
				//MonitorTmp();
96
				if (tmp_size[0]) {
97
					dir_size.get("/tmp0/1");
98
					dir_size.bytes += dir_size.files/2 + 32 * 512; //file attr size + FAT table size
99
					dir_size.bytes /= 1024*1024; //convert to MiB
100
					dir_size.bytes= tmp_size[0] - dir_size.bytes;
101
					tmp[0].draw_progress(
102
						dir_size.bytes*tmp[0].w/tmp_size[0],
103
						tmp_size[0] - dir_size.bytes,
104
						dir_size.bytes,
105
						"M"
106
						);
107
				}
108
		}
109
	}
110
}
111
 
112
void DrawBlockHeader(dword _x, _y, _icon, _title, _subtitle)
113
{
114
	#define ICONGAP 45
7806 leency 115
	WriteTextB(_x+ICONGAP, _y, 0x90, sc.work_text, _title);
116
	DrawIcon32(_x, _y, sc.work, _icon);
117
	WriteText(_x+ICONGAP, _y+20, 0x90, sc.work_text, _subtitle);
7614 leency 118
}
119
 
120
dword GetCpuLoad(dword max_h)
121
{
122
	dword idle;
123
	dword CPU_SEC = GetCpuFrequency() >> 20 + 1;
124
	dword IDLE_SEC = GetCpuIdleCount() >> 20 * max_h;
125
 
126
	EAX = IDLE_SEC;
127
	EBX = CPU_SEC;
128
	$cdq
129
	$div ebx
130
	idle = EAX;
131
 
132
	return max_h - idle;
133
}
134
 
135
dword GetDiskSize(dword disk_n)
136
{
137
	BDVK bdvk;
138
	char tmp_path[8];
139
	strcpy(#tmp_path, "/tmp0/1");
140
	tmp_path[4] = disk_n + '0';
141
	GetFileInfo(#tmp_path, #bdvk);
142
	return bdvk.sizelo;
143
}
144
void GetTmpDiskSizes()
145
{
146
	char i;
147
	for (i=0; i<=9; i++)
148
	{
149
		tmp_size[i] = GetDiskSize(i) / 1024 / 1024;
150
	}
151
}
152
 
153
//===================================================//
154
//                                                   //
155
//                     MONITORS                      //
156
//                                                   //
157
//===================================================//
158
 
159
int pos=0;
160
void MonitorCpu()
161
{
162
	int i;
163
	if (!cpu.w) return;
164
 
165
	cpu_stack[pos] = GetCpuLoad(cpu.h);
166
	if (cpu_stack[pos]<=2) || (cpu_stack[pos]>cpu.h) cpu_stack[pos]=2;
167
 
7806 leency 168
	DrawBar(cpu.x+cpu.w-30, cpu.y-25, 30, 20, sc.work);
7614 leency 169
	sprintf(#param, "%i%%", cpu_stack[pos]);
7806 leency 170
	WriteText(cpu.x+cpu.w-calc(strlen(#param)*8), cpu.y-25, 0x90, sc.work_text, #param);
7614 leency 171
 
172
	for (i=0; i
173
		DrawBar(i+cpu.x, cpu.y, 1, cpu.h-cpu_stack[i], PROGRESS_BG);
174
		DrawBar(i+cpu.x, cpu.h-cpu_stack[i]+cpu.y, 1, cpu_stack[i], LOAD_CPU);
175
 
176
		DrawBar(i+1+cpu.x, cpu.y, 1, cpu.h, PROGRESS_BG);
177
	}
178
 
179
	pos++;
180
	if (pos>=WIN_CONTENT_W) {
181
		pos = WIN_CONTENT_W-1;
182
		for (i=0; i
183
			cpu_stack[i] = cpu_stack[i+1];
184
		}
185
	}
186
}