SysMon: show all tmp disks, reparate general tab into two, precise calculation of rd disk empty space

git-svn-id: svn://kolibrios.org@7906 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2020-05-10 01:44:40 +00:00
parent d4d33ff3c1
commit 6d14f374a8
9 changed files with 203 additions and 260 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.7 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

View File

@ -24,22 +24,18 @@
:void sensor::draw_wrapper()
{
DrawRectangle(x-1, y-1, w+1, h+1, sc.work_graph);
DrawRectangle3D(x-2, y-2, w+3, h+3, sc.work_dark, sc.work_light);
DrawRectangle3D(x-2, y-2, w+3, h+3, sc.work, sc.work_light);
}
:void sensor::draw_progress(dword progress_w, active_value, bg_value, mesure)
:void sensor::draw_progress(dword progress_w)
{
if (progress_w < MIN_PB_BLOCK_W) progress_w = MIN_PB_BLOCK_W;
if (progress_w > w-MIN_PB_BLOCK_W) progress_w = w-MIN_PB_BLOCK_W;
char textp[16];
DrawBar(x, y, w-progress_w, 1, MixColors(PROGRESS_ACTIVE, PROGRESS_BG, 200));
DrawBar(x, y+1, w-progress_w, h-2, PROGRESS_ACTIVE);
DrawBar(x, y+h-1, w-progress_w, 1, MixColors(PROGRESS_ACTIVE, sc.work_graph, 200));
sprintf(#param, "%i%s", active_value, mesure);
WriteText(w-progress_w- calc(strlen(#param)*8) /2 + x, h/2-7+y, 0x90, PROGRESS_BG, #param);
DrawBar(x+w-progress_w, y, progress_w, h, PROGRESS_BG);
sprintf(#param, "%i%s", bg_value, mesure);
WriteText(-progress_w - calc(strlen(#param)*8)/2 + w+x, h/2-7+y, 0x90, PROGRESS_BG_TEXT, #param);
strcpy(#textp, itoa(w-progress_w*100/w));
chrcat(#textp, '%');
WriteText(-strlen(#textp)*8 + w / 2 + x, h/2-7+y, 0x90, 0x000000, #textp);
}

View File

@ -1,12 +1,14 @@
#ifndef TAB_PADDING
#define TAB_PADDING 15
#endif
#define TAB_HEIGHT 28
:struct _tabs
{
int active_tab;
int x,y,w,h;
void draw_button();
dword draw_button();
int click();
void draw_wrapper();
};
@ -14,10 +16,10 @@
:void _tabs::draw_wrapper()
{
DrawRectangle(x,y+TAB_HEIGHT,w-1,h-TAB_HEIGHT, sc.work_graph);
DrawRectangle(x+1,y+1+TAB_HEIGHT,w-3,h-2-TAB_HEIGHT, sc.work_light);
DrawBar(x+1,y+1+TAB_HEIGHT,w-3,1, sc.work_light);
}
:void _tabs::draw_button(dword xx, but_id, text)
:dword _tabs::draw_button(dword xx, but_id, text)
{
dword col_bg, col_text;
dword ww=strlen(text)*8, hh=TAB_HEIGHT;
@ -36,6 +38,7 @@
WriteText(xx, y+6, 0x90, col_text, text);
DrawBar(xx, y+hh-3, ww, 3, col_bg);
//DrawStandartCaptButton(xx, y, but_id, text); //GetFreeButtonId()
return xx;
}
:int _tabs::click(int N)

View File

@ -43,4 +43,15 @@
if (icon_n>=0) img_draw stdcall(icons32draw.image, x, y, 32, 32, 0, icon_n*32);
}
:libimg_image icons16draw;
:void DrawIcon16(dword x,y, bg, icon_n) {
//load_dll(libimg, #libimg_init,1);
if (!icons16draw.image) {
Libimg_LoadImage(#icons16draw, "/sys/icons16.png");
Libimg_ReplaceColor(icons16draw.image, icons16draw.w, icons16draw.h, 0xffFFFfff, bg);
Libimg_ReplaceColor(icons16draw.image, icons16draw.w, icons16draw.h, 0xffCACBD6, MixColors(bg, 0, 220));
}
if (icon_n>=0) img_draw stdcall(icons16draw.image, x, y, 16, 16, 0, icon_n*16);
}
#endif

View File

@ -0,0 +1,96 @@
//===================================================//
// //
// DATA //
// //
//===================================================//
sensor cpu;
sensor ram;
//===================================================//
// //
// CODE //
// //
//===================================================//
void DrawIconWithText(dword _x, _y, _icon, _title)
{
DrawIcon16(_x, _y, sc.work, _icon);
DrawBar(_x+ICONGAP, _y, WIN_CONTENT_W - ICONGAP - _x, 20, sc.work);
WriteText(_x+ICONGAP, _y, 0x90, sc.work_text, _title);
}
void CPUnRAM__Main()
{
dword cpu_frequency = GetCpuFrequency()/1000;
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON);
goto _GENERAL_REDRAW_2;
loop()
{
WaitEventTimeout(25);
switch(EAX & 0xFF)
{
case evButton: Sysmon__ButtonEvent(); break;
case evKey: Sysmon__KeyEvent(); break;
case evReDraw:
_GENERAL_REDRAW_2:
Sysmon__DefineAndDrawWindow();
cpu.set_size(WIN_PAD, WIN_CONTENT_Y+25, WIN_CONTENT_W, 100);
ram.set_size(WIN_PAD, WIN_CONTENT_Y+170, WIN_CONTENT_W, 23);
default:
MonitorCpu();
MonitorRam();
}
}
}
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;
}
int pos=0;
void MonitorCpu()
{
static dword cpu_stack[1980*3];
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;
sprintf(#param, "CPU load %i%%", cpu_stack[pos]);
DrawIconWithText(WIN_PAD, cpu.y - 25, 48, #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];
}
}
}
void MonitorRam()
{
ram.draw_progress(GetFreeRAM()*ram.w/GetTotalRAM());
sprintf(#param, "RAM usage: %i Mb free of %i Mb", GetFreeRAM()/1024, GetTotalRAM()/1024);
DrawIconWithText(WIN_PAD, ram.y - 25, 51, #param);
}

View File

@ -1,186 +0,0 @@
//===================================================//
// //
// DATA //
// //
//===================================================//
dword cpu_stack[1980*3];
sensor cpu;
sensor ram;
sensor rd;
sensor tmp[10];
dword tmp_size[10];
//===================================================//
// //
// CODE //
// //
//===================================================//
void General__Main()
{
DIR_SIZE dir_size;
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, sc.work);
sprintf(#param, "%i KiB", GetTotalRAM()-GetFreeRAM());
WriteText(ram.x+ram.w-calc(strlen(#param)*8), ram.y-25, 0x90, sc.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, sc.work_text, _title);
DrawIcon32(_x, _y, sc.work, _icon);
WriteText(_x+ICONGAP, _y+20, 0x90, sc.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, sc.work);
sprintf(#param, "%i%%", cpu_stack[pos]);
WriteText(cpu.x+cpu.w-calc(strlen(#param)*8), cpu.y-25, 0x90, sc.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];
}
}
}

View File

@ -32,9 +32,9 @@ checkbox show_system = { T_SHOW_SYSTEM_PROCESSES, false };
void Processes__Main()
{
int btn;
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
maxcpu = GetCpuFrequency();
goto _PROCESS_REDRAW;
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
goto _PROCESS_REDRAW_3;
loop()
{
WaitEventTimeout(50);
@ -44,35 +44,31 @@ void Processes__Main()
SelectList_ProcessMouse();
break;
case evKey:
GetKeys();
Sysmon__KeyEvent();
if (select_list.ProcessKey(key_scancode)) SelectList_LineChanged();
break;
case evButton:
btn = GetButtonID();
Sysmon__ButtonEvent(btn);
btn = Sysmon__ButtonEvent();
if (show_system.click(btn))
{
if (show_system.click(btn)) {
SelectList_LineChanged();
}
if (BTN_ID_KILL_PROCESS == btn)
{
if (BTN_ID_KILL_PROCESS == btn) {
KillProcess(current_process_id);
pause(10);
SelectList_LineChanged();
}
if (BTN_ID_SHOW_PROCESS_INFO == btn)
{
if (BTN_ID_SHOW_PROCESS_INFO == btn) {
io.run("/sys/tinfo", itoa(GetProcessSlot(current_process_id)));
}
break;
case evReDraw:
_PROCESS_REDRAW:
_PROCESS_REDRAW_3:
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);
WIN_CONTENT_H-BOTPANEL_H-WIN_CONTENT_Y, false);
SelectList_DrawBorder();
//DrawWideRectangle(0, 0, Form.cwidth, Form.cheight, 4, sc.work);

View File

@ -1,6 +1,6 @@
/*
* System Monitor
* version 0.87
* version 1.0
* Author: Leency
*/
@ -33,22 +33,83 @@
#define WIN_PAD 20 //Window padding
#define WIN_CONTENT_X WIN_PAD
#define WIN_CONTENT_Y TAB_HEIGHT+WIN_PAD
#define WIN_CONTENT_Y TAB_HEIGHT+WIN_PAD+20
#define WIN_CONTENT_W 400
#define WIN_CONTENT_H 465
#define ICONGAP 26
proc_info Form;
#include "general.h"
#include "process.h"
#define T_GENERAL "General"
#ifdef LANG_RUS
#define T_CPU_AND_RAM "<22>à®æ¥áá®à ¨ Ž‡“"
#define T_DRIVES "„¨áª¨"
#define T_PROCESSES "<22>à®æ¥ááë"
#define T_APP_TITLE "System Monitor"
#else
#define T_CPU_AND_RAM "CPU & RAM"
#define T_DRIVES "Drives"
#define T_PROCESSES "Processes"
#define T_APP_TITLE "System Monitor"
#endif
enum {
TAB_GENERAL=20,
TAB_DRIVES,
TAB_PROCESSES
};
_tabs tabs = { TAB_GENERAL, 4, 0, WIN_CONTENT_W+WIN_PAD+WIN_PAD-4-4, TAB_HEIGHT };
_tabs tabs = { TAB_GENERAL, 4, 10, WIN_CONTENT_W+WIN_PAD+WIN_PAD-4-4, TAB_HEIGHT };
//===================================================//
// //
// GENERAL EVENTS //
// //
//===================================================//
int Sysmon__DefineAndDrawWindow()
{
dword butx;
sc.get();
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, sc.work, T_APP_TITLE,0);
GetProcessInfo(#Form, SelfInfo);
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();
butx = tabs.draw_button(tabs.x+TAB_PADDING, TAB_GENERAL, T_CPU_AND_RAM);
butx = tabs.draw_button(strlen(T_CPU_AND_RAM)*8+TAB_PADDING+butx, TAB_DRIVES, T_DRIVES);
tabs.draw_button(strlen(T_DRIVES)*8+TAB_PADDING+butx, TAB_PROCESSES, T_PROCESSES);
return true;
}
int Sysmon__ButtonEvent()
{
int bid = GetButtonID();
if (1==bid) ExitProcess();
if (TAB_GENERAL==bid) {
tabs.active_tab = TAB_GENERAL;
CPUnRAM__Main();
}
if (TAB_PROCESSES==bid) {
tabs.active_tab = TAB_PROCESSES;
Processes__Main();
}
if (TAB_DRIVES==bid) {
tabs.active_tab = TAB_DRIVES;
Drives__Main();
}
return bid;
}
void Sysmon__KeyEvent()
{
GetKeys();
if (key_scancode == SCAN_CODE_ESC) ExitProcess();
}
#include "cpu_ram.h"
#include "drives.h"
#include "process.h"
void main()
{
@ -56,42 +117,5 @@ void main()
load_dll(libimg, #libimg_init,1);
load_dll(libini, #lib_init,1);
load_dll(boxlib, #box_lib_init,0);
General__Main();
}
int Sysmon__DefineAndDrawWindow()
{
sc.get();
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, sc.work, "System Monitor",0);
GetProcessInfo(#Form, SelfInfo);
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;
}
//===================================================//
// //
// EVENTS //
// //
//===================================================//
void Sysmon__ButtonEvent(dword id)
{
if (1==id) ExitProcess();
if (TAB_GENERAL==id) {
tabs.active_tab = TAB_GENERAL;
General__Main();
}
if (TAB_PROCESSES==id) {
tabs.active_tab = TAB_PROCESSES;
Processes__Main();
}
}
stop:
CPUnRAM__Main();
}

View File

@ -82,7 +82,10 @@ edit_box:
mov ed_height,eax
call .draw_border
.draw_bg_cursor_text:
;test word ed_flags,ed_focus ; for unfocused controls =>
;jz .sjip_offset ; do not recalculate offset (big OS behaviour)
call .check_offset
;.sjip_offset:
call .draw_bg
test word ed_flags,ed_focus ; for unfocused controls =>
jz .draw_cursor_text ; do not draw selection(named shift)