Size: a a a

2020 February 12

АФ

Александр Фолькмер in Python
Максим
Как получить список программ и их использование процессора в процентах?
какая ОС?
источник

АФ

Александр Фолькмер in Python
на мелкомягком - диспетчер задач, на Линуксе - через терминал
источник

АФ

Александр Фолькмер in Python
foreach (Process proc in Process.GetProcesses()) {
   using (PerformanceCounter pcProcess = new PerformanceCounter("Process", "% Processor Time", proc.ProcessName)) {
       pcProcess.NextValue();
       System.Threading.Thread.Sleep(1000);
       Console.WriteLine("Process:{0} CPU% {1}", proc.ProcessName, pcProcess.NextValue());    
   }
}
источник

АФ

Александр Фолькмер in Python
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "perfgrap"
#pragma resource "*.dfm"

#define SystemProcessorTimes 8
#define MAX_PROCESSORS 32

TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
   : TForm(Owner)
{
}
//---------------------------------------------------------------------------
typedef struct _SYSTEM_BASIC_INFORMATION
{
   ULONG Unknown,
   MaximumIncrement,
   PhysicalPageSize,
   NumberOfPhysicalPages,
   LowestPhysicalPage,
   HighestPhysicalPage,
   AllocationGranularity,
   LowestUserAddress,
   HighestUserAddress,
   ActiveProcessors;
   char NumberProcessors;
}SYSTEM_BASIC_INFORMATION, *PSYSTEM_BASIC_INFORMATION;

typedef struct _SYSTEM_PROCESSOR_TIMES
{
   __int64 IdleTime,
   KernelTime,
   UserTime,
   DpcTime,
   InterruptTime;
   ULONG InterruptCount;
} SYSTEM_PROCESSORS_TIMES[MAX_PROCESSORS], SYSTEM_PROCESSOR_TIMES, *PSYSTEM_PROCESSOR_TIMES;

typedef UINT __stdcall (*ZwQuerySystemInformation)(DWORD,void*,DWORD,DWORD*);

/*function*/

SYSTEM_INFO SYSINFO;

int GetProcessorsCount(void)
{
 SYSTEM_INFO SYSINFO;
 GetSystemInfo(&SYSINFO);
 return SYSINFO.dwNumberOfProcessors;
}

int GetProcessorType(SYSTEM_INFO& SYSINFO)
{
GetSystemInfo(&SYSINFO);
return SYSINFO.dwProcessorType;
}

int GetProcessorOemId(SYSTEM_INFO& SYSINFO)
{
GetSystemInfo(&SYSINFO);
return SYSINFO.dwOemId;
}

int * cpu_usage;
__int64 temp = 0;
unsigned int cycle_count = 0,
            count_mas = 0,
            interval = 1000; //период опроса (мс)

HMODULE lib = NULL;
DWORD nowtime, oldtime, pertime, rez, curtime = 0;
SYSTEM_PROCESSORS_TIMES CurrentSysProcTimes, PreviousSysProcTimes;

ZwQuerySystemInformation func;

String msg = "";
char * windowname = new char[20];

bool init = false;

void __fastcall TForm1::Button1Click(TObject *Sender)
{
   strcpy(windowname,"CPU usage");

   ZeroMemory(&CurrentSysProcTimes[0],sizeof(CurrentSysProcTimes));
   ZeroMemory(&PreviousSysProcTimes[0],sizeof(PreviousSysProcTimes));

   lib = LoadLibrary(L"Ntdll.dll");   //динамическая загрузка библиотеки

   if (!lib)
   {
       msg = "Error #1: Не удалось динамически загрузить быблиотеку!";
       Application->MessageBox(msg.c_str(), L"Warning", MB_OK | MB_ICONERROR);
       return;
   }

   func = (ZwQuerySystemInformation)GetProcAddress(lib,"ZwQuerySystemInformation");  //запрос адреса функции

   if (!func)
   {
       msg = "Error #2: Не удалось получить адрес функции!";
       Application->MessageBox(msg.c_str(), L"Warning", MB_OK | MB_ICONERROR);
       FreeLibrary(lib);
       return;
   }

   Label1->Caption = "количество ядер : " + IntToStr(GetProcessorsCount()) + " / тип процессора : " + IntToStr(GetProcessorType(SYSINFO)) + " / OemId : " + IntToStr(GetProcessorOemId(SYSINFO));
   init = true;
   msg = "Инициализация успешна!";
   Application->MessageBox(msg.c_str(), (String(windowname)).c_str(), MB_OK | MB_ICONINFORMATION);
   Button1->Enabled = false;
   Button3->Enabled = true;

   cpu_usage = new int[100000];
   count_mas = 0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
       nowtime = GetTickCount();
       pertime = nowtime - oldtime;
       curtime += pertime;
       oldtime = nowtime;

       /*read the usage*/
       func(SystemProcessorTimes,
             &CurrentSysProcTimes[0],
             sizeof(CurrentSysProcTimes),
             &rez);

       temp = 0;
       for(int j=0;j<MAX_PROCESSORS;j++)
       {
           temp += CurrentSysProcTimes[j].IdleTime - PreviousSysProcTimes[j].IdleTime;
       }
       temp /= 10000;  //переводим из наносекунд в миллисекунды
       temp /= (int) GetProcessorsCount(); //делим на количество ядер
источник

АФ

Александр Фолькмер in Python
temp = (int) pertime - temp;


       if (cycle_count >= 1)
       {
       msg = "";
       msg += "Current time: " + String(curtime) + " milisecond(s). Processor usage on " + String(temp) + " milisecond.";
 //        Memo1->Lines->Add(msg);


       cpu_usage[count_mas] = temp / (float) pertime*100;
//      Edit4->Text = IntToStr(count_mas + 1);

       msg = "";
       msg += "Usage of processors is " + IntToStr(cpu_usage[count_mas]) + "%";
//      Memo1->Lines->Add(msg);
//      Memo1->Lines->Add("");
       Caption = msg;
       PerformanceGraph1->Scale += 1;
//      PerformanceGraph1->StepSize = 1;

       count_mas++;
       }

       cycle_count++;
//        Edit2->Text = IntToStr(cycle_count);

       memcpy(&PreviousSysProcTimes[0],
               &CurrentSysProcTimes[0],
               sizeof(PreviousSysProcTimes));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PerformanceGraph1ScaleChange(TObject *Sender)
{
 PerformanceGraph1->DataPoint(clLime, cpu_usage[count_mas]);
 PerformanceGraph1->Update();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
if (Timer1->Enabled)
{
Timer1->Enabled = false;

//cycle_count = 0;
temp = 0;
curtime = 0;
oldtime = GetTickCount();

Button2->Enabled = false;
Button3->Enabled = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
if (init)
{
   Button3->Enabled = false;

   /*init prev processors data*/

   //вызываем функцию по таймеру и один раз до запуска таймера.
   oldtime =  GetTickCount();
   if (func(SystemProcessorTimes,
             &PreviousSysProcTimes[0],
             sizeof(PreviousSysProcTimes),0) != 0)
   {
       msg = "Error #3: Ошибка функции!";
       Application->MessageBox(msg.c_str(), L"Warning", MB_OK | MB_ICONERROR);
       FreeLibrary(lib);
       return;
   }

Sleep(100);
cycle_count = 0;

Button2->Enabled = true;

Timer1->Interval = interval;
Timer1->Enabled = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
if (lib) FreeLibrary(lib);
delete[] cpu_usage;
}
//---------------------------------------------------------------------------
источник

АФ

Александр Фолькмер in Python
AIDA64
источник

АФ

Александр Фолькмер in Python
3125 alexand+  20   0 3863820 788232 105596 R   8,3  8,6  49:47.07 gnome-shell                                                                  
5553 alexand+  20   0   21008  13532   1768 S   5,6  0,1  44:56.61 wineserver                                                                  
20422 alexand+  20   0 1842984 213708  33792 S   5,6  2,3   1:16.85 1cv8c.exe                                                                    
23635 alexand+  20   0 2832744 275364 154900 S   5,6  3,0   0:11.60 Web Content                                                                  
3003 root      20   0  443440 147384  99504 S   5,3  1,6  12:08.98 Xorg                                                                        
3164 alexand+   9 -11 3103656  20840  15808 S   5,3  0,2   1:12.66 pulseaudio                                                                  
4036 alexand+  20   0 11,760g 173480 101864 R   5,0  1,9  65:39.46 franz                                                                        
22965 alexand+  20   0 3009044 203132  28964 S   4,6  2,2   1:12.22 SolSuite.exe                                                                
3445 alexand+  20   0 1332964 174176  99444 S   3,0  1,9  34:00.07 franz                                                                        
5898 alexand+  20   0  810964  44108  30240 S   2,3  0,5   0:30.05 gnome-terminal-                                                              
22897 alexand+  20   0 11,947g 206304  77344 S   2,3  2,2   0:50.91 franz                                                                        
3454 alexand+  20   0 4088796 374788 152532 S   2,0  4,1  16:37.39 firefox                                                                      
5335 alexand+  20   0 2142564 696396 118520 S   1,3  7,6  23:30.20 telegram-deskto                                                              
5568 alexand+  20   0 1940728  46916  15560 S   1,3  0,5   2:39.35 explorer.exe                                                                
3844 alexand+  20   0 3118100 310872 135048 S   1,0  3,4  18:23.10 Web Content                                                                  
  10 root      20   0       0      0      0 I   0,7  0,0   5:07.79 rcu_sched                                                                    
1021 root      20   0  521364  13220   8488 S   0,7  0,1   2:10.91 udisksd
источник

АФ

Александр Фолькмер in Python
это у меня
источник

A

Ananimys in Python
Александр Фолькмер
3125 alexand+  20   0 3863820 788232 105596 R   8,3  8,6  49:47.07 gnome-shell                                                                  
5553 alexand+  20   0   21008  13532   1768 S   5,6  0,1  44:56.61 wineserver                                                                  
20422 alexand+  20   0 1842984 213708  33792 S   5,6  2,3   1:16.85 1cv8c.exe                                                                    
23635 alexand+  20   0 2832744 275364 154900 S   5,6  3,0   0:11.60 Web Content                                                                  
3003 root      20   0  443440 147384  99504 S   5,3  1,6  12:08.98 Xorg                                                                        
3164 alexand+   9 -11 3103656  20840  15808 S   5,3  0,2   1:12.66 pulseaudio                                                                  
4036 alexand+  20   0 11,760g 173480 101864 R   5,0  1,9  65:39.46 franz                                                                        
22965 alexand+  20   0 3009044 203132  28964 S   4,6  2,2   1:12.22 SolSuite.exe                                                                
3445 alexand+  20   0 1332964 174176  99444 S   3,0  1,9  34:00.07 franz                                                                        
5898 alexand+  20   0  810964  44108  30240 S   2,3  0,5   0:30.05 gnome-terminal-                                                              
22897 alexand+  20   0 11,947g 206304  77344 S   2,3  2,2   0:50.91 franz                                                                        
3454 alexand+  20   0 4088796 374788 152532 S   2,0  4,1  16:37.39 firefox                                                                      
5335 alexand+  20   0 2142564 696396 118520 S   1,3  7,6  23:30.20 telegram-deskto                                                              
5568 alexand+  20   0 1940728  46916  15560 S   1,3  0,5   2:39.35 explorer.exe                                                                
3844 alexand+  20   0 3118100 310872 135048 S   1,0  3,4  18:23.10 Web Content                                                                  
  10 root      20   0       0      0      0 I   0,7  0,0   5:07.79 rcu_sched                                                                    
1021 root      20   0  521364  13220   8488 S   0,7  0,1   2:10.91 udisksd
Да ну нах
источник

АФ

Александр Фолькмер in Python
команда - тор в иерминале
источник

АФ

Александр Фолькмер in Python
источник

A

Ananimys in Python
Называется: Сижу на работе 🤣
источник

A

Ananimys in Python
источник

АФ

Александр Фолькмер in Python
скучаю на работе
источник

АФ

Александр Фолькмер in Python
всего        занято        свободно      общая  буф./врем.   доступно
Память:    16358848     7261940     6260360      412472     2836548     8389700
Подкачка:     2097148     2022024       75124
источник

АФ

Александр Фолькмер in Python
источник

М

Максим in Python
Питон
источник

М

Максим in Python
Без разницы какая ос
источник

ЗР

Зайчаток Разума in Python
в зависимости от ОС переводи вывод с различных утилит в свою прогу и обрабатывай как хочешь
источник

ЗР

Зайчаток Разума in Python
источник