Subversion Repositories Kolibri OS

Rev

Rev 7878 | 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
sensor cpu;
8
sensor ram;
9
 
10
//===================================================//
11
//                                                   //
12
//                       CODE                        //
13
//                                                   //
14
//===================================================//
15
 
7906 leency 16
void DrawIconWithText(dword _x, _y, _icon, _title)
7614 leency 17
{
7906 leency 18
	DrawIcon16(_x, _y, sc.work, _icon);
19
	DrawBar(_x+ICONGAP, _y, WIN_CONTENT_W - ICONGAP - _x, 20, sc.work);
20
	WriteText(_x+ICONGAP, _y, 0x90, sc.work_text, _title);
21
}
22
 
23
void CPUnRAM__Main()
24
{
25
	dword cpu_frequency = GetCpuFrequency()/1000;
7614 leency 26
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON);
7906 leency 27
	goto _GENERAL_REDRAW_2;
7614 leency 28
	loop()
29
	{
30
		WaitEventTimeout(25);
31
		switch(EAX & 0xFF)
32
		{
7906 leency 33
			case evButton: Sysmon__ButtonEvent(); break;
34
			case evKey: Sysmon__KeyEvent(); break;
35
			case evReDraw:
36
				_GENERAL_REDRAW_2:
37
				Sysmon__DefineAndDrawWindow();
38
				cpu.set_size(WIN_PAD, WIN_CONTENT_Y+25, WIN_CONTENT_W, 100);
39
				ram.set_size(WIN_PAD, WIN_CONTENT_Y+170, WIN_CONTENT_W, 23);
7614 leency 40
			default:
41
				MonitorCpu();
7906 leency 42
				MonitorRam();
7614 leency 43
		}
44
	}
45
}
46
 
47
dword GetCpuLoad(dword max_h)
48
{
49
	dword idle;
50
	dword CPU_SEC = GetCpuFrequency() >> 20 + 1;
51
	dword IDLE_SEC = GetCpuIdleCount() >> 20 * max_h;
52
 
53
	EAX = IDLE_SEC;
54
	EBX = CPU_SEC;
55
	$cdq
56
	$div ebx
57
	idle = EAX;
58
 
59
	return max_h - idle;
60
}
61
 
62
int pos=0;
63
void MonitorCpu()
64
{
7906 leency 65
	static dword cpu_stack[1980*3];
7614 leency 66
	int i;
67
	if (!cpu.w) return;
68
 
69
	cpu_stack[pos] = GetCpuLoad(cpu.h);
70
	if (cpu_stack[pos]<=2) || (cpu_stack[pos]>cpu.h) cpu_stack[pos]=2;
71
 
7906 leency 72
	sprintf(#param, "CPU load %i%%", cpu_stack[pos]);
73
	DrawIconWithText(WIN_PAD, cpu.y - 25, 48, #param);
74
 
7614 leency 75
	for (i=0; i
76
		DrawBar(i+cpu.x, cpu.y, 1, cpu.h-cpu_stack[i], PROGRESS_BG);
77
		DrawBar(i+cpu.x, cpu.h-cpu_stack[i]+cpu.y, 1, cpu_stack[i], LOAD_CPU);
78
 
79
		DrawBar(i+1+cpu.x, cpu.y, 1, cpu.h, PROGRESS_BG);
80
	}
81
 
82
	pos++;
83
	if (pos>=WIN_CONTENT_W) {
84
		pos = WIN_CONTENT_W-1;
85
		for (i=0; i
86
			cpu_stack[i] = cpu_stack[i+1];
87
		}
88
	}
89
}
7906 leency 90
 
91
void MonitorRam()
92
{
93
	ram.draw_progress(GetFreeRAM()*ram.w/GetTotalRAM());
94
	sprintf(#param, "RAM usage: %i Mb free of %i Mb", GetFreeRAM()/1024, GetTotalRAM()/1024);
95
	DrawIconWithText(WIN_PAD, ram.y - 25, 51, #param);
96
}