@@ -414,6 +414,19 @@ void ProcessMonitor::getHighMemoryProcesses(const std::string & output)
414
414
getTopratedProcesses (&memory_tasks_, &p2);
415
415
}
416
416
417
+ bool ProcessMonitor::getCommandLineFromPiD (const std::string & pid, std::string * command)
418
+ {
419
+ std::string commandLineFilePath = " /proc/" + pid + " /cmdline" ;
420
+ std::ifstream commandFile (commandLineFilePath);
421
+ if (commandFile.is_open ()) {
422
+ std::getline (commandFile, *command);
423
+ commandFile.close ();
424
+ return true ;
425
+ } else {
426
+ return false ;
427
+ }
428
+ }
429
+
417
430
void ProcessMonitor::getTopratedProcesses (
418
431
std::vector<std::shared_ptr<DiagTask>> * tasks, bp::pipe * p)
419
432
{
@@ -462,7 +475,14 @@ void ProcessMonitor::getTopratedProcesses(
462
475
info.virtualImage >> info.residentSize >> info.sharedMemSize >> info.processStatus >>
463
476
info.cpuUsage >> info.memoryUsage >> info.cpuTime ;
464
477
465
- std::getline (stream, info.commandName );
478
+ std::string program_name;
479
+ std::getline (stream, program_name);
480
+
481
+ bool flag_find_command_line = getCommandLineFromPiD (info.processId , &info.commandName );
482
+
483
+ if (!flag_find_command_line) {
484
+ info.commandName = program_name; // if command line is not found, use program name instead
485
+ }
466
486
467
487
tasks->at (index )->setDiagnosticsStatus (DiagStatus::OK, " OK" );
468
488
tasks->at (index )->setProcessInformation (info);
@@ -515,7 +535,7 @@ void ProcessMonitor::onTimer()
515
535
std::ostringstream os;
516
536
517
537
// Get processes
518
- bp::child c (" top -bcn1 -o %CPU -w 256 " , bp::std_out > is_out, bp::std_err > is_err);
538
+ bp::child c (" top -bn1 -o %CPU -w 128 " , bp::std_out > is_out, bp::std_err > is_err);
519
539
c.wait ();
520
540
521
541
if (c.exit_code () != 0 ) {
0 commit comments