Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 7613 → Rev 7614

/programs/cmm/sysmon/general.h
0,0 → 1,185
//===================================================//
// //
// DATA //
// //
//===================================================//
 
dword cpu_stack[1980*3];
 
sensor cpu;
sensor ram;
sensor rd;
sensor tmp[10];
 
dword tmp_size[10];
 
//===================================================//
// //
// CODE //
// //
//===================================================//
 
void General__Main()
{
dword cpu_frequency;
incn y;
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON);
 
cpu_frequency = GetCpuFrequency()/1000;
GetTmpDiskSizes();
 
goto _GENERAL_REDRAW;
loop()
{
WaitEventTimeout(25);
switch(EAX & 0xFF)
{
case evButton:
Sysmon__ButtonEvent(GetButtonID());
break;
case evKey:
GetKeys();
if (key_scancode == SCAN_CODE_ESC) ExitProcess();
break;
case evReDraw:
_GENERAL_REDRAW:
if (!Sysmon__DefineAndDrawWindow()) break;
 
y.n = WIN_CONTENT_Y;
if (cpu_frequency < 1000) sprintf(#param, "CPU frequency: %i Hz", cpu_frequency);
else sprintf(#param, "CPU frequency: %i MHz", cpu_frequency/1000);
DrawBlockHeader(WIN_PAD, y.inc(0), 37, "CPU load", #param);
cpu.set_size(WIN_PAD, y.inc(45), WIN_CONTENT_W, 100);
 
sprintf(#param, "Total RAM: %i MiB", GetTotalRAM()/1024);
DrawBlockHeader(WIN_PAD, y.inc(cpu.h + 25), 36, "RAM usage", #param);
ram.set_size(WIN_PAD, y.inc(45), WIN_CONTENT_W, 23);
 
DrawBlockHeader(WIN_PAD, y.inc(ram.h + 25), 3, "System RAM Disk usage", "Fixed size: 1.44 MiB");
rd.set_size(WIN_PAD, y.inc(45), WIN_CONTENT_W, 23);
 
sprintf(#param, "TMP Disk 0 size: %i MiB", tmp_size[0]);
DrawBlockHeader(WIN_PAD, y.inc(rd.h + 25), 50, "Virtual drive usage", #param);
tmp[0].set_size(WIN_PAD, y.inc(45), WIN_CONTENT_W, 23);
 
default:
MonitorCpu();
 
//MonitorRam();
ram.draw_progress(
GetFreeRAM()*ram.w/GetTotalRAM(),
GetTotalRAM()-GetFreeRAM()/1024,
GetFreeRAM()/1024,
"M"
);
DrawBar(ram.x+ram.w-96, ram.y-25, 96, 20, system.color.work);
sprintf(#param, "%i KiB", GetTotalRAM()-GetFreeRAM());
WriteText(ram.x+ram.w-calc(strlen(#param)*8), ram.y-25, 0x90, system.color.work_text, #param);
 
//MonitorRd();
dir_size.get("/rd/1");
dir_size.bytes += dir_size.files/2 + 32 * 512; //file attr size + FAT table size
dir_size.bytes /= 1024; //convert to KiB
dir_size.bytes = 1440 - dir_size.bytes;
rd.draw_progress(
dir_size.bytes*rd.w/1440,
1440 - dir_size.bytes,
dir_size.bytes,
"K"
);
 
//MonitorTmp();
if (tmp_size[0]) {
dir_size.get("/tmp0/1");
dir_size.bytes += dir_size.files/2 + 32 * 512; //file attr size + FAT table size
dir_size.bytes /= 1024*1024; //convert to MiB
dir_size.bytes= tmp_size[0] - dir_size.bytes;
tmp[0].draw_progress(
dir_size.bytes*tmp[0].w/tmp_size[0],
tmp_size[0] - dir_size.bytes,
dir_size.bytes,
"M"
);
}
}
}
}
 
void DrawBlockHeader(dword _x, _y, _icon, _title, _subtitle)
{
#define ICONGAP 45
WriteTextB(_x+ICONGAP, _y, 0x90, system.color.work_text, _title);
DrawIcon32(_x, _y, system.color.work, _icon);
WriteText(_x+ICONGAP, _y+20, 0x90, system.color.work_text, _subtitle);
}
 
dword GetCpuLoad(dword max_h)
{
dword idle;
dword CPU_SEC = GetCpuFrequency() >> 20 + 1;
dword IDLE_SEC = GetCpuIdleCount() >> 20 * max_h;
 
EAX = IDLE_SEC;
EBX = CPU_SEC;
$cdq
$div ebx
idle = EAX;
 
return max_h - idle;
}
 
dword GetDiskSize(dword disk_n)
{
BDVK bdvk;
char tmp_path[8];
strcpy(#tmp_path, "/tmp0/1");
tmp_path[4] = disk_n + '0';
GetFileInfo(#tmp_path, #bdvk);
return bdvk.sizelo;
}
void GetTmpDiskSizes()
{
char i;
for (i=0; i<=9; i++)
{
tmp_size[i] = GetDiskSize(i) / 1024 / 1024;
}
}
 
//===================================================//
// //
// MONITORS //
// //
//===================================================//
 
int pos=0;
void MonitorCpu()
{
int i;
if (!cpu.w) return;
 
cpu_stack[pos] = GetCpuLoad(cpu.h);
if (cpu_stack[pos]<=2) || (cpu_stack[pos]>cpu.h) cpu_stack[pos]=2;
DrawBar(cpu.x+cpu.w-30, cpu.y-25, 30, 20, system.color.work);
sprintf(#param, "%i%%", cpu_stack[pos]);
WriteText(cpu.x+cpu.w-calc(strlen(#param)*8), cpu.y-25, 0x90, system.color.work_text, #param);
 
for (i=0; i<WIN_CONTENT_W; i+=2) {
DrawBar(i+cpu.x, cpu.y, 1, cpu.h-cpu_stack[i], PROGRESS_BG);
DrawBar(i+cpu.x, cpu.h-cpu_stack[i]+cpu.y, 1, cpu_stack[i], LOAD_CPU);
 
DrawBar(i+1+cpu.x, cpu.y, 1, cpu.h, PROGRESS_BG);
}
 
pos++;
if (pos>=WIN_CONTENT_W) {
pos = WIN_CONTENT_W-1;
for (i=0; i<pos; i++) {
cpu_stack[i] = cpu_stack[i+1];
}
}
}
/programs/cmm/sysmon/process.h
0,0 → 1,148
//===================================================//
// //
// DATA //
// //
//===================================================//
 
#define T_WINDOW_TITLE "Process Manager"
#define T_SHOW_SYSTEM_PROCESSES "Show system"
#define T_DETAILS "Details"
#define T_END_PROCESS "End process"
 
#define BOTPANEL_H 36
 
enum {
BTN_ID_SHOW_SYSTEM_PROCESSES=200,
BTN_ID_KILL_PROCESS,
BTN_ID_SHOW_PROCESS_INFO
};
 
int current_process_id = 0;
unsigned maxcpu;
int proc_list[256];
 
checkbox show_system = { T_SHOW_SYSTEM_PROCESSES, false };
 
//===================================================//
// //
// CODE //
// //
//===================================================//
 
void Processes__Main()
{
int btn;
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
maxcpu = GetCpuFrequency();
goto _PROCESS_REDRAW;
loop()
{
WaitEventTimeout(50);
switch(EAX & 0xFF)
{
case evMouse:
SelectList_ProcessMouse();
break;
case evKey:
GetKeys();
if (select_list.ProcessKey(key_scancode)) SelectList_LineChanged();
break;
case evButton:
btn = GetButtonID();
Sysmon__ButtonEvent(btn);
 
if (show_system.click(btn))
{
SelectList_LineChanged();
}
if (BTN_ID_KILL_PROCESS == btn)
{
KillProcess(current_process_id);
pause(10);
SelectList_LineChanged();
}
if (BTN_ID_SHOW_PROCESS_INFO == btn)
{
io.run("/sys/tinfo", itoa(GetProcessSlot(current_process_id)));
}
break;
case evReDraw:
_PROCESS_REDRAW:
if (!Sysmon__DefineAndDrawWindow()) break;
 
SelectList_Init(WIN_PAD, WIN_CONTENT_Y,
WIN_CONTENT_W-scroll1.size_x,
WIN_CONTENT_H-BOTPANEL_H-TAB_HEIGHT, false);
SelectList_DrawBorder();
 
//DrawWideRectangle(0, 0, Form.cwidth, Form.cheight, 4, system.color.work);
DrawBar(select_list.x-2, select_list.y+select_list.h+2,
select_list.w+scroll1.size_x+4, BOTPANEL_H, system.color.work);
DrawCaptButton(Form.cwidth-110-WIN_PAD,
select_list.y+select_list.h+5,
110,25,BTN_ID_KILL_PROCESS,0xF38181, 0xFFFfff, T_END_PROCESS);
DrawCaptButton(Form.cwidth-230-WIN_PAD,
select_list.y+select_list.h+5,
110,25,BTN_ID_SHOW_PROCESS_INFO,
system.color.work_button, system.color.work_button_text, T_DETAILS);
show_system.draw(select_list.x + 3, select_list.y+select_list.h+10);
default:
SelectList_LineChanged();
}
}
}
 
void Processes__GetProcessList()
{
int i, j;
proc_info Process;
 
select_list.count=0;
for (i=0; i<MAX_PROCESS_COUNT; i++)
{
GetProcessInfo(#Process, i);
if (Process.name)
{
for (j=0; j<11; j++) if (Process.name[j]!=' ') {
if (show_system.checked==false) {
//do not show system process
if (Process.name[0]=='@') break;
if (!strcmp(#Process.name, "IDLE")) break;
if (!strcmp(#Process.name, "OS")) break;
}
proc_list[select_list.count] = i;
select_list.count++;
break;
}
}
}
}
 
void SelectList_DrawLine(dword i)
{
int posy;
char cpu_use[16];
dword bg_color;
proc_info Process;
 
GetProcessInfo(#Process, proc_list[i+select_list.first]);
posy = i *select_list.item_h + select_list.y;
if (i % 2) bg_color = 0xFFFfff; else bg_color = 0xF0F0F0;
if (i+select_list.first == select_list.cur_y) {
current_process_id = Process.ID;
bg_color = 0x67CCEB;
}
DrawBar(select_list.x, posy, select_list.w, select_list.item_h, bg_color);
WriteText(select_list.x+005, posy+select_list.text_y, select_list.font_type, 0, #Process.name);
WriteText(select_list.w/10*5+select_list.x, posy+select_list.text_y, select_list.font_type, 0x444444, ConvertSizeToKb(Process.use_memory));
sprintf(#cpu_use, "%i %%", Process.use_cpu*100/maxcpu);
if (maxcpu) WriteText(select_list.w/10*8+select_list.x - calc(strlen(#cpu_use)-4*8),
posy+select_list.text_y, select_list.font_type, 0x444444, #cpu_use);
}
 
void SelectList_LineChanged()
{
Processes__GetProcessList();
SelectList_Draw();
}
/programs/cmm/sysmon/sysmon.c
4,16 → 4,27
* Author: Leency
*/
 
#define MEMSIZE 4096*10
#define MEMSIZE 4096*30
 
//===================================================//
// //
// LIB //
// //
//===================================================//
 
#include "../lib/io.h"
#include "../lib/gui.h"
#include "../lib/fs.h"
#include "../lib/list_box.h"
 
#include "../lib/obj/libio.h"
#include "../lib/obj/libimg.h"
#include "../lib/obj/libini.h"
#include "../lib/obj/box_lib.h"
 
#include "../lib/patterns/select_list.h"
#include "../lib/patterns/restart_process.h"
 
//===================================================//
// //
// DATA //
20,188 → 31,67
// //
//===================================================//
 
#define CPU_STACK 440
dword cpu_stack[CPU_STACK];
#define WIN_PAD 20 //Window padding
#define WIN_CONTENT_X WIN_PAD
#define WIN_CONTENT_Y TAB_HEIGHT+WIN_PAD
#define WIN_CONTENT_W 400
#define WIN_CONTENT_H 465
proc_info Form;
 
sensor cpu;
sensor ram;
sensor rd;
sensor tmp[10];
#include "general.h"
#include "process.h"
 
dword tmp_size[10];
#define T_GENERAL "General"
#define T_PROCESSES "Processes"
 
//===================================================//
// //
// CODE //
// //
//===================================================//
enum {
TAB_GENERAL=20,
TAB_PROCESSES
};
_tabs tabs = { TAB_GENERAL, 4, 0, WIN_CONTENT_W+WIN_PAD+WIN_PAD-4-4, TAB_HEIGHT };
 
void main()
{
proc_info Form;
dword cpu_frequency = GetCpuFrequency()/1000;
int id;
 
incn y;
 
load_dll(libio, #libio_init,1);
load_dll(libimg, #libimg_init,1);
load_dll(libini, #lib_init,1);
load_dll(boxlib, #box_lib_init,0);
General__Main();
}
 
GetTmpDiskSizes();
loop()
int Sysmon__DefineAndDrawWindow()
{
WaitEventTimeout(25);
switch(EAX & 0xFF)
{
case evButton:
if (GetButtonID()) ExitProcess();
break;
case evKey:
GetKeys();
if (key_scancode == SCAN_CODE_ESC) ExitProcess();
break;
case evReDraw:
#define LEFT 25
#define ICONGAP 45
system.color.get();
DefineAndDrawWindow(150, 100, CPU_STACK+LEFT+LEFT+4+9, 480 + skin_height + 4, 0x34, system.color.work, "System Monitor",0);
DefineAndDrawWindow(screen.width - WIN_CONTENT_H - 200, 100, WIN_CONTENT_W + WIN_PAD + WIN_PAD +9,
WIN_CONTENT_H + TAB_HEIGHT + skin_height + 4, 0x34, system.color.work, "System Monitor",0);
GetProcessInfo(#Form, SelfInfo);
 
y.n = 0;
if (cpu_frequency < 1000) sprintf(#param, "CPU frequency: %i Hz", cpu_frequency);
else sprintf(#param, "CPU frequency: %i MHz", cpu_frequency/1000);
DrawBlockHeader(LEFT, y.inc(20), 37, "CPU load", #param);
cpu.set_size(LEFT, y.inc(45), CPU_STACK, 100);
 
sprintf(#param, "Total RAM: %i MiB", GetTotalRAM()/1024);
DrawBlockHeader(LEFT, y.inc(cpu.h + 25), 36, "RAM usage", #param);
ram.set_size(LEFT, y.inc(45), CPU_STACK, 23);
 
DrawBlockHeader(LEFT, y.inc(ram.h + 25), 3, "System RAM Disk usage", "Fixed size: 1.44 MiB");
rd.set_size(LEFT, y.inc(45), CPU_STACK, 23);
 
sprintf(#param, "TMP Disk 0 size: %i MiB", tmp_size[0]);
DrawBlockHeader(LEFT, y.inc(rd.h + 25), 50, "Virtual drive usage", #param);
tmp[0].set_size(LEFT, y.inc(45), CPU_STACK, 23);
 
default:
MonitorCpu();
 
//MonitorRam();
ram.draw_progress(
GetFreeRAM()*ram.w/GetTotalRAM(),
GetTotalRAM()-GetFreeRAM()/1024,
GetFreeRAM()/1024,
"M"
);
DrawBar(ram.x+ram.w-96, ram.y-25, 96, 20, system.color.work);
sprintf(#param, "%i KiB", GetTotalRAM()-GetFreeRAM());
WriteText(ram.x+ram.w-calc(strlen(#param)*8), ram.y-25, 0x90, system.color.work_text, #param);
 
//MonitorRd();
dir_size.get("/rd/1");
dir_size.bytes += dir_size.files/2 + 32 * 512; //file attr size + FAT table size
dir_size.bytes /= 1024; //convert to KiB
dir_size.bytes = 1440 - dir_size.bytes;
rd.draw_progress(
dir_size.bytes*rd.w/1440,
1440 - dir_size.bytes,
dir_size.bytes,
"K"
);
 
//MonitorTmp();
if (tmp_size[0]) {
dir_size.get("/tmp0/1");
dir_size.bytes += dir_size.files/2 + 32 * 512; //file attr size + FAT table size
dir_size.bytes /= 1024*1024; //convert to MiB
dir_size.bytes= tmp_size[0] - dir_size.bytes;
tmp[0].draw_progress(
dir_size.bytes*tmp[0].w/tmp_size[0],
tmp_size[0] - dir_size.bytes,
dir_size.bytes,
"M"
);
if (Form.status_window>2) return false;
//if (Form.width < 300) { MoveSize(OLD,OLD,300,OLD); break; }
//if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); break; }
tabs.draw_wrapper();
tabs.draw_button(tabs.x+TAB_PADDING, TAB_GENERAL, T_GENERAL);
tabs.draw_button(strlen(T_GENERAL)*8+tabs.x+TAB_PADDING+TAB_PADDING, TAB_PROCESSES, T_PROCESSES);
return true;
}
}
}
}
 
void DrawBlockHeader(dword _x, _y, _icon, _title, _subtitle)
{
WriteTextB(_x+ICONGAP, _y, 0x90, system.color.work_text, _title);
DrawIcon32(_x, _y, system.color.work, _icon);
WriteText(_x+ICONGAP, _y+20, 0x90, system.color.work_text, _subtitle);
}
 
dword GetCpuLoad(dword max_h)
{
dword idle;
dword CPU_SEC = GetCpuFrequency() >> 20 + 1;
dword IDLE_SEC = GetCpuIdleCount() >> 20 * max_h;
 
EAX = IDLE_SEC;
EBX = CPU_SEC;
$cdq
$div ebx
idle = EAX;
 
return max_h - idle;
}
 
dword GetDiskSize(dword disk_n)
{
BDVK bdvk;
char tmp_path[8];
strcpy(#tmp_path, "/tmp0/1");
tmp_path[4] = disk_n + '0';
GetFileInfo(#tmp_path, #bdvk);
return bdvk.sizelo;
}
void GetTmpDiskSizes()
{
char i;
for (i=0; i<=9; i++)
{
tmp_size[i] = GetDiskSize(i) / 1024 / 1024;
}
}
 
//===================================================//
// //
// MONITORS //
// EVENTS //
// //
//===================================================//
 
int pos=0;
void MonitorCpu()
void Sysmon__ButtonEvent(dword id)
{
int i;
if (!cpu.w) return;
 
cpu_stack[pos] = GetCpuLoad(cpu.h);
if (cpu_stack[pos]<=2) || (cpu_stack[pos]>cpu.h) cpu_stack[pos]=2;
DrawBar(cpu.x+cpu.w-30, cpu.y-25, 30, 20, system.color.work);
sprintf(#param, "%i%%", cpu_stack[pos]);
WriteText(cpu.x+cpu.w-calc(strlen(#param)*8), cpu.y-25, 0x90, system.color.work_text, #param);
 
for (i=0; i<CPU_STACK; i+=2) {
DrawBar(i+cpu.x, cpu.y, 1, cpu.h-cpu_stack[i], PROGRESS_BG);
DrawBar(i+cpu.x, cpu.h-cpu_stack[i]+cpu.y, 1, cpu_stack[i], LOAD_CPU);
 
DrawBar(i+1+cpu.x, cpu.y, 1, cpu.h, PROGRESS_BG);
if (1==id) ExitProcess();
if (TAB_GENERAL==id) {
tabs.active_tab = TAB_GENERAL;
General__Main();
}
 
pos++;
if (pos>=CPU_STACK) {
pos = CPU_STACK-1;
for (i=0; i<pos; i++) {
cpu_stack[i] = cpu_stack[i+1];
if (TAB_PROCESSES==id) {
tabs.active_tab = TAB_PROCESSES;
Processes__Main();
}
}
}
 
 
stop: