Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. //===================================================//
  2. //                                                   //
  3. //                       DATA                        //
  4. //                                                   //
  5. //===================================================//
  6.  
  7. dword cpu_stack[1980*3];
  8.  
  9. sensor cpu;
  10. sensor ram;
  11. sensor rd;
  12. sensor tmp[10];
  13.  
  14. dword tmp_size[10];
  15.  
  16. //===================================================//
  17. //                                                   //
  18. //                       CODE                        //
  19. //                                                   //
  20. //===================================================//
  21.  
  22. void General__Main()
  23. {
  24.         dword cpu_frequency;
  25.         incn y;
  26.         SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON);
  27.  
  28.         cpu_frequency = GetCpuFrequency()/1000;
  29.         GetTmpDiskSizes();
  30.  
  31.         goto _GENERAL_REDRAW;
  32.        
  33.         loop()
  34.         {
  35.                 WaitEventTimeout(25);
  36.                 switch(EAX & 0xFF)
  37.                 {
  38.                         case evButton:
  39.                                 Sysmon__ButtonEvent(GetButtonID());
  40.                                 break;
  41.                  
  42.                         case evKey:
  43.                                 GetKeys();
  44.                                 if (key_scancode == SCAN_CODE_ESC) ExitProcess();
  45.                                 break;
  46.                          
  47.                         case evReDraw:
  48.                                 _GENERAL_REDRAW:
  49.                                 if (!Sysmon__DefineAndDrawWindow()) break;
  50.  
  51.                                 y.n = WIN_CONTENT_Y;
  52.                                 if (cpu_frequency < 1000) sprintf(#param, "CPU frequency: %i Hz", cpu_frequency);
  53.                                 else sprintf(#param, "CPU frequency: %i MHz", cpu_frequency/1000);
  54.                                 DrawBlockHeader(WIN_PAD, y.inc(0), 37, "CPU load", #param);
  55.                                 cpu.set_size(WIN_PAD, y.inc(45), WIN_CONTENT_W, 100);
  56.  
  57.                                 sprintf(#param, "Total RAM: %i MiB", GetTotalRAM()/1024);
  58.                                 DrawBlockHeader(WIN_PAD, y.inc(cpu.h + 25), 36, "RAM usage", #param);
  59.                                 ram.set_size(WIN_PAD, y.inc(45), WIN_CONTENT_W, 23);
  60.  
  61.                                 DrawBlockHeader(WIN_PAD, y.inc(ram.h + 25), 3, "System RAM Disk usage", "Fixed size: 1.44 MiB");
  62.                                 rd.set_size(WIN_PAD, y.inc(45), WIN_CONTENT_W, 23);
  63.  
  64.                                 sprintf(#param, "TMP Disk 0 size: %i MiB", tmp_size[0]);
  65.                                 DrawBlockHeader(WIN_PAD, y.inc(rd.h + 25), 50, "Virtual drive usage", #param);
  66.                                 tmp[0].set_size(WIN_PAD, y.inc(45), WIN_CONTENT_W, 23);
  67.  
  68.                         default:
  69.                                 MonitorCpu();
  70.  
  71.                                 //MonitorRam();
  72.                                 ram.draw_progress(
  73.                                         GetFreeRAM()*ram.w/GetTotalRAM(),
  74.                                         GetTotalRAM()-GetFreeRAM()/1024,
  75.                                         GetFreeRAM()/1024,
  76.                                         "M"
  77.                                         );
  78.                                 DrawBar(ram.x+ram.w-96, ram.y-25, 96, 20, system.color.work);
  79.                                 sprintf(#param, "%i KiB", GetTotalRAM()-GetFreeRAM());
  80.                                 WriteText(ram.x+ram.w-calc(strlen(#param)*8), ram.y-25, 0x90, system.color.work_text, #param);
  81.  
  82.                                 //MonitorRd();
  83.                                 dir_size.get("/rd/1");                 
  84.                                 dir_size.bytes += dir_size.files/2 + 32 * 512; //file attr size + FAT table size
  85.                                 dir_size.bytes /= 1024; //convert to KiB
  86.                                 dir_size.bytes = 1440 - dir_size.bytes;
  87.                                 rd.draw_progress(
  88.                                         dir_size.bytes*rd.w/1440,
  89.                                         1440 - dir_size.bytes,
  90.                                         dir_size.bytes,
  91.                                         "K"
  92.                                         );
  93.  
  94.                                 //MonitorTmp();
  95.                                 if (tmp_size[0]) {
  96.                                         dir_size.get("/tmp0/1");
  97.                                         dir_size.bytes += dir_size.files/2 + 32 * 512; //file attr size + FAT table size
  98.                                         dir_size.bytes /= 1024*1024; //convert to MiB
  99.                                         dir_size.bytes= tmp_size[0] - dir_size.bytes;
  100.                                         tmp[0].draw_progress(
  101.                                                 dir_size.bytes*tmp[0].w/tmp_size[0],
  102.                                                 tmp_size[0] - dir_size.bytes,
  103.                                                 dir_size.bytes,
  104.                                                 "M"
  105.                                                 );                                     
  106.                                 }
  107.                 }
  108.         }
  109. }
  110.  
  111. void DrawBlockHeader(dword _x, _y, _icon, _title, _subtitle)
  112. {
  113.         #define ICONGAP 45
  114.         WriteTextB(_x+ICONGAP, _y, 0x90, system.color.work_text, _title);
  115.         DrawIcon32(_x, _y, system.color.work, _icon);
  116.         WriteText(_x+ICONGAP, _y+20, 0x90, system.color.work_text, _subtitle); 
  117. }
  118.  
  119. dword GetCpuLoad(dword max_h)
  120. {
  121.         dword idle;
  122.         dword CPU_SEC = GetCpuFrequency() >> 20 + 1;
  123.         dword IDLE_SEC = GetCpuIdleCount() >> 20 * max_h;
  124.  
  125.         EAX = IDLE_SEC;
  126.         EBX = CPU_SEC;
  127.         $cdq
  128.         $div ebx
  129.         idle = EAX;
  130.  
  131.         return max_h - idle;
  132. }
  133.  
  134. dword GetDiskSize(dword disk_n)
  135. {
  136.         BDVK bdvk;
  137.         char tmp_path[8];
  138.         strcpy(#tmp_path, "/tmp0/1");
  139.         tmp_path[4] = disk_n + '0';
  140.         GetFileInfo(#tmp_path, #bdvk);         
  141.         return bdvk.sizelo;
  142. }
  143. void GetTmpDiskSizes()
  144. {
  145.         char i;
  146.         for (i=0; i<=9; i++)
  147.         {
  148.                 tmp_size[i] = GetDiskSize(i) / 1024 / 1024;
  149.         }
  150. }
  151.  
  152. //===================================================//
  153. //                                                   //
  154. //                     MONITORS                      //
  155. //                                                   //
  156. //===================================================//
  157.  
  158. int pos=0;
  159. void MonitorCpu()
  160. {
  161.         int i;
  162.         if (!cpu.w) return;
  163.  
  164.         cpu_stack[pos] = GetCpuLoad(cpu.h);
  165.         if (cpu_stack[pos]<=2) || (cpu_stack[pos]>cpu.h) cpu_stack[pos]=2;
  166.        
  167.         DrawBar(cpu.x+cpu.w-30, cpu.y-25, 30, 20, system.color.work);
  168.         sprintf(#param, "%i%%", cpu_stack[pos]);
  169.         WriteText(cpu.x+cpu.w-calc(strlen(#param)*8), cpu.y-25, 0x90, system.color.work_text, #param);
  170.  
  171.         for (i=0; i<WIN_CONTENT_W; i+=2) {
  172.                 DrawBar(i+cpu.x, cpu.y, 1, cpu.h-cpu_stack[i], PROGRESS_BG);
  173.                 DrawBar(i+cpu.x, cpu.h-cpu_stack[i]+cpu.y, 1, cpu_stack[i], LOAD_CPU);
  174.  
  175.                 DrawBar(i+1+cpu.x, cpu.y, 1, cpu.h, PROGRESS_BG);
  176.         }
  177.  
  178.         pos++;
  179.         if (pos>=WIN_CONTENT_W) {
  180.                 pos = WIN_CONTENT_W-1;
  181.                 for (i=0; i<pos; i++) {
  182.                         cpu_stack[i] = cpu_stack[i+1];
  183.                 }
  184.         }
  185. }
  186.