/* * System Monitor * version 1.3 * Author: Leency */ #define MEMSIZE 4096*30 #ifndef AUTOBUILD #include "lang.h--" #endif //===================================================// // // // 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/box_lib.h" #include "../lib/patterns/select_list.h" #include "../lib/patterns/restart_process.h" //===================================================// // // // CONST // // // //===================================================// #define GAP 16 //Window padding #define WIN_CONTENT_X GAP #define WIN_CONTENT_Y GAP+15 #define PROCESS_LIST_W 260 #define RIGHT_X PROCESS_LIST_W + GAP + GAP + 22 #define ICONGAP 26 #define BOTPANEL_H 36 #ifdef LANG_RUS #define T_CPU_AND_RAM "Процессор и ОЗУ" #define T_DRIVES "Диски" #define T_PROCESSES "Процессы" #define T_APP_TITLE "Системный монитор" #define T_SHOW_SYSTEM "Системные" #define T_DETAILS "Подробнее" #define T_PROC_KILL "Снять задачу" #define T_PROC_INFO "Инфо" #define T_PROC_HEADER "Процесс ОЗУ Кб ЦП %" #define T_CPU_LOAD "Загрузка процессора %i%% " #define T_RAM_USAGE "Память ОЗУ: %i Мб свободно из %i Мб" #define T_RD_USAGE "Системный диск: %i Кб свободно из 1.4 Мб" #define T_TMP_USAGE "TMP%i диск: %i Мб свободно из %i Мб" #else #define T_CPU_AND_RAM "CPU & RAM" #define T_DRIVES "Drives" #define T_PROCESSES "Processes" #define T_APP_TITLE "System Monitor" #define T_SHOW_SYSTEM "System" #define T_DETAILS "Details" #define T_PROC_KILL "Terminate" #define T_PROC_INFO "Info" #define T_PROC_HEADER "Process RAM Kb CPU %" #define T_CPU_LOAD "CPU load %i%% " #define T_RAM_USAGE "RAM usage: %i Mb free of %i Mb" #define T_RD_USAGE "System disk usage: %i Kb free of 1.4 Mb" #define T_TMP_USAGE "TMP%i usage: %i Mb free of %i Mb" #endif enum { BTN_ID_SHOW_SYSTEM_PROCESSES=200, BTN_ID_PROC_KILL, BTN_ID_PROC_INFO, BTN_ID_MENU }; //===================================================// // // // VARS // // // //===================================================// int current_process_id = 0; int proc_list[256]; checkbox show_system = { T_SHOW_SYSTEM, false }; sensor cpu; sensor ram; sensor rd; sensor tmp; proc_info Form; int right_w; //===================================================// // // // CODE // // // //===================================================// void load_lib() { load_dll(libio, #libio_init,1); load_dll(libimg, #libimg_init,1); load_dll(boxlib, #box_lib_init,0); } void main() { int btn; //dword cpu_frequency = GetCpuFrequency()/1000; load_lib(); SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER); loop() switch(@WaitEventTimeout(120)) { case evMouse: SelectList_ProcessMouse(); break; case evKey: GetKeys(); if (key_scancode == SCAN_CODE_ESC) ExitProcess(); if (key_scancode == SCAN_CODE_DEL) EventKillCurrentProcess(); if (select_list.ProcessKey(key_scancode)) SelectList_LineChanged(); break; case evButton: btn = GetButtonID(); if (1==btn) ExitProcess(); if (show_system.click(btn)) { SelectList_LineChanged(); } if (BTN_ID_PROC_KILL == btn) { EventKillCurrentProcess(); } if (BTN_ID_PROC_INFO == btn) { io.run("/sys/tinfo", itoa(GetProcessSlot(current_process_id))); } break; case evReDraw: sc.get(); DefineAndDrawWindow(screen.width/2 - 350, 100, 700, 490, 0x33, sc.work, T_APP_TITLE,0); GetProcessInfo(#Form, SelfInfo); if (Form.status_window>2) break; if (Form.width < RIGHT_X+370) { MoveSize(OLD,OLD,RIGHT_X+370,OLD); break; } if (Form.height < 420) { MoveSize(OLD,OLD,OLD,420); break; } right_w = Form.cwidth - RIGHT_X - GAP; right_w &= ~1; // make sure the number is even WriteText(GAP+5, WIN_CONTENT_Y-20, 0x90, sc.work_text, T_PROC_HEADER); //bool burger_active = false; //if (menu_id == OPEN_FILE) burger_active = true; //DrawTopPanelButton(BTN_ID_MENU, Form.cwidth-GAP-3, GAP, -1, burger_active); SelectList_Init(GAP, WIN_CONTENT_Y, PROCESS_LIST_W, Form.cheight-BOTPANEL_H-WIN_CONTENT_Y, false); SelectList_DrawBorder(); DrawBar(select_list.x-2, select_list.y+select_list.h+2, select_list.w+scroll1.size_x+4, BOTPANEL_H, sc.work); DrawCaptButton(PROCESS_LIST_W+GAP-110+18, select_list.y+select_list.h+5, 110,23,BTN_ID_PROC_KILL,0xF38181, 0xFFFfff, T_PROC_KILL); DrawCaptButton(PROCESS_LIST_W+GAP-165+18, select_list.y+select_list.h+5, 46,23,BTN_ID_PROC_INFO,sc.button, sc.button_text, T_PROC_INFO); show_system.draw(GAP-1, select_list.y+select_list.h+10); //WriteText(RIGHT_X, WIN_CONTENT_Y+25, 0x90, sc.work, "Update period: 5 seconds"); cpu.set_size(RIGHT_X, WIN_CONTENT_Y+25, right_w, 100); ram.set_size(RIGHT_X, WIN_CONTENT_Y+170, right_w, 23); rd.set_size(RIGHT_X, WIN_CONTENT_Y+240, right_w, 23); default: SelectList_LineChanged(); MonitorCpu(); MonitorRam(); MonitorRd(); MonitorTmp(); } } void EventKillCurrentProcess() { KillProcess(current_process_id); pause(10); SelectList_LineChanged(); } void Processes__GetProcessList() { int i, j; proc_info Process; select_list.count=0; for (i=0; i> 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, T_CPU_LOAD, cpu_stack[pos]); DrawIconWithText(RIGHT_X, cpu.y - 25, 48, #param); for (i=0; i=right_w) { pos = right_w-1; for (i=0; i