Subversion Repositories Kolibri OS

Rev

Rev 7532 | Rev 7806 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7532 Rev 7614
Line 2... Line 2...
2
 * System Monitor
2
 * System Monitor
3
 * version 0.87
3
 * version 0.87
4
 * Author: Leency
4
 * Author: Leency
5
*/
5
*/
Line 6... Line 6...
6
 
6
 
-
 
7
#define MEMSIZE 4096*30
-
 
8
 
-
 
9
//===================================================//
-
 
10
//                                                   //
-
 
11
//                       LIB                         //
-
 
12
//                                                   //
Line 7... Line 13...
7
#define MEMSIZE 4096*10
13
//===================================================//
8
 
14
 
9
#include "../lib/io.h"
15
#include "../lib/io.h"
-
 
16
#include "../lib/gui.h"
Line 10... Line 17...
10
#include "../lib/gui.h"
17
#include "../lib/fs.h"
11
#include "../lib/fs.h"
18
#include "../lib/list_box.h"
12
 
19
 
-
 
20
#include "../lib/obj/libio.h"
-
 
21
#include "../lib/obj/libimg.h"
-
 
22
#include "../lib/obj/libini.h"
-
 
23
#include "../lib/obj/box_lib.h"
Line 13... Line 24...
13
#include "../lib/obj/libio.h"
24
 
14
#include "../lib/obj/libimg.h"
25
#include "../lib/patterns/select_list.h"
15
#include "../lib/obj/libini.h"
26
#include "../lib/patterns/restart_process.h"
16
 
27
 
17
//===================================================//
28
//===================================================//
Line -... Line 29...
-
 
29
//                                                   //
-
 
30
//                       DATA                        //
-
 
31
//                                                   //
18
//                                                   //
32
//===================================================//
19
//                       DATA                        //
33
 
-
 
34
#define WIN_PAD 20   //Window padding
Line 20... Line -...
20
//                                                   //
-
 
21
//===================================================//
35
#define WIN_CONTENT_X WIN_PAD
22
 
-
 
23
#define CPU_STACK 440
36
#define WIN_CONTENT_Y TAB_HEIGHT+WIN_PAD
Line 24... Line 37...
24
dword cpu_stack[CPU_STACK];
37
#define WIN_CONTENT_W 400
-
 
38
#define WIN_CONTENT_H 465
Line -... Line 39...
-
 
39
proc_info Form;
25
 
40
 
26
sensor cpu;
-
 
27
sensor ram;
41
#include "general.h"
-
 
42
#include "process.h"
28
sensor rd;
43
 
29
sensor tmp[10];
-
 
Line 30... Line 44...
30
 
44
#define T_GENERAL "General"
31
dword tmp_size[10];
45
#define T_PROCESSES "Processes"
32
 
-
 
33
//===================================================//
-
 
34
//                                                   //
-
 
35
//                       CODE                        //
-
 
36
//                                                   //
-
 
37
//===================================================//
-
 
38
 
46
 
39
void main()
47
enum {
40
{
48
	TAB_GENERAL=20,
-
 
49
	TAB_PROCESSES
-
 
50
};
-
 
51
_tabs tabs = { TAB_GENERAL, 4, 0, WIN_CONTENT_W+WIN_PAD+WIN_PAD-4-4, TAB_HEIGHT };
Line 41... Line -...
41
	proc_info Form;
-
 
42
	dword cpu_frequency = GetCpuFrequency()/1000;
-
 
43
	int id;
-
 
44
 
-
 
45
	incn y;
52
 
46
 
-
 
47
	load_dll(libio, #libio_init,1);
53
void main()
48
	load_dll(libimg, #libimg_init,1);
-
 
49
	load_dll(libini, #lib_init,1);
-
 
50
 
-
 
51
	GetTmpDiskSizes();
-
 
52
	
-
 
53
	loop()
-
 
54
	{
-
 
55
		WaitEventTimeout(25);
-
 
56
		switch(EAX & 0xFF)
-
 
57
		{
-
 
58
			case evButton:
-
 
59
				if (GetButtonID()) ExitProcess();
-
 
60
				break;
54
{
-
 
55
	load_dll(libio, #libio_init,1);
61
		  
56
	load_dll(libimg, #libimg_init,1);
62
			case evKey:
57
	load_dll(libini, #lib_init,1);
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);
58
	load_dll(boxlib, #box_lib_init,0);
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);
-
 
77
				DrawBlockHeader(LEFT, y.inc(20), 37, "CPU load", #param);
59
	General__Main();
78
				cpu.set_size(LEFT, y.inc(45), CPU_STACK, 100);
-
 
79
 
60
}
80
				sprintf(#param, "Total RAM: %i MiB", GetTotalRAM()/1024);
-
 
81
				DrawBlockHeader(LEFT, y.inc(cpu.h + 25), 36, "RAM usage", #param);
-
 
82
				ram.set_size(LEFT, y.inc(45), CPU_STACK, 23);
-
 
83
 
-
 
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);
61
 
86
 
-
 
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);
-
 
90
 
-
 
91
			default:
-
 
92
				MonitorCpu();
62
int Sysmon__DefineAndDrawWindow()
93
 
63
{
94
				//MonitorRam();
-
 
95
				ram.draw_progress(
-
 
96
					GetFreeRAM()*ram.w/GetTotalRAM(), 
-
 
97
					GetTotalRAM()-GetFreeRAM()/1024, 
-
 
98
					GetFreeRAM()/1024,
-
 
99
					"M"
-
 
100
					);
-
 
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);
-
 
104
 
-
 
105
				//MonitorRd();
-
 
106
				dir_size.get("/rd/1");			
-
 
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; 
-
 
110
				rd.draw_progress(
-
 
111
					dir_size.bytes*rd.w/1440,
-
 
112
					1440 - dir_size.bytes,
-
 
113
					dir_size.bytes,
-
 
114
					"K"
-
 
115
					);
-
 
116
 
-
 
117
				//MonitorTmp();
-
 
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
				}
-
 
130
		}
-
 
131
	}
-
 
132
}
-
 
133
 
-
 
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
 
-
 
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;
64
	system.color.get();
154
}
-
 
155
 
-
 
156
dword GetDiskSize(dword disk_n)
-
 
157
{
-
 
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);		
65
	DefineAndDrawWindow(screen.width - WIN_CONTENT_H - 200, 100, WIN_CONTENT_W + WIN_PAD + WIN_PAD +9, 
Line 163... Line 66...
163
	return bdvk.sizelo;
66
		WIN_CONTENT_H + TAB_HEIGHT + skin_height + 4, 0x34, system.color.work, "System Monitor",0);
164
}
67
	GetProcessInfo(#Form, SelfInfo);
165
void GetTmpDiskSizes()
68
	if (Form.status_window>2) return false;
166
{
69
	//if (Form.width  < 300) { MoveSize(OLD,OLD,300,OLD); break; }
167
	char i;
70
	//if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); break; }
Line 168... Line -...
168
	for (i=0; i<=9; i++)
-
 
169
	{
71
	tabs.draw_wrapper();
170
		tmp_size[i] = GetDiskSize(i) / 1024 / 1024;
72
	tabs.draw_button(tabs.x+TAB_PADDING, TAB_GENERAL, T_GENERAL);	
171
	}
-
 
172
}
73
	tabs.draw_button(strlen(T_GENERAL)*8+tabs.x+TAB_PADDING+TAB_PADDING, TAB_PROCESSES, T_PROCESSES);
173
 
-
 
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);
74
	return true;
190
	sprintf(#param, "%i%%", cpu_stack[pos]);
75
}
191
	WriteText(cpu.x+cpu.w-calc(strlen(#param)*8), cpu.y-25, 0x90, system.color.work_text, #param);
76
 
192
 
-
 
193
	for (i=0; i
77
//===================================================//
-
 
78
//                                                   //
-
 
79
//                      EVENTS                       //
-
 
80
//                                                   //
194
		DrawBar(i+cpu.x, cpu.y, 1, cpu.h-cpu_stack[i], PROGRESS_BG);
81
//===================================================//
195
		DrawBar(i+cpu.x, cpu.h-cpu_stack[i]+cpu.y, 1, cpu_stack[i], LOAD_CPU);
82
 
-
 
83
void Sysmon__ButtonEvent(dword id)
-
 
84
{
-
 
85
	if (1==id) ExitProcess();
196
 
86
	if (TAB_GENERAL==id) {