Changeset View
Changeset View
Standalone View
Standalone View
processcore/processes_linux_p.cpp
Show First 20 Lines • Show All 108 Lines • ▼ Show 20 Line(s) | 108 | public: | |||
---|---|---|---|---|---|
109 | Private() { mProcDir = opendir( "/proc" );} | 109 | Private() { mProcDir = opendir( "/proc" );} | ||
110 | ~Private(); | 110 | ~Private(); | ||
111 | inline bool readProcStatus(const QString &dir, Process *process); | 111 | inline bool readProcStatus(const QString &dir, Process *process); | ||
112 | inline bool readProcStat(const QString &dir, Process *process); | 112 | inline bool readProcStat(const QString &dir, Process *process); | ||
113 | inline bool readProcStatm(const QString &dir, Process *process); | 113 | inline bool readProcStatm(const QString &dir, Process *process); | ||
114 | inline bool readProcCmdline(const QString &dir, Process *process); | 114 | inline bool readProcCmdline(const QString &dir, Process *process); | ||
115 | inline bool readProcCGroup(const QString &dir, Process *process); | 115 | inline bool readProcCGroup(const QString &dir, Process *process); | ||
116 | inline bool readProcAttr(const QString &dir, Process *process); | 116 | inline bool readProcAttr(const QString &dir, Process *process); | ||
117 | inline bool readProcSmaps(const QString &dir, Process *process); | ||||
117 | inline bool getNiceness(long pid, Process *process); | 118 | inline bool getNiceness(long pid, Process *process); | ||
118 | inline bool getIOStatistics(const QString &dir, Process *process); | 119 | inline bool getIOStatistics(const QString &dir, Process *process); | ||
119 | QFile mFile; | 120 | QFile mFile; | ||
120 | char mBuffer[PROCESS_BUFFER_SIZE+1]; //used as a buffer to read data into | 121 | char mBuffer[PROCESS_BUFFER_SIZE+1]; //used as a buffer to read data into | ||
121 | DIR* mProcDir; | 122 | DIR* mProcDir; | ||
122 | }; | 123 | }; | ||
123 | 124 | | |||
124 | ProcessesLocal::Private::~Private() | 125 | ProcessesLocal::Private::~Private() | ||
▲ Show 20 Lines • Show All 325 Lines • ▼ Show 20 Line(s) | 440 | if(!process->command().isEmpty()) { | |||
450 | 451 | | |||
451 | process->command().replace(QLatin1Char('\0'), QLatin1Char(' ')); | 452 | process->command().replace(QLatin1Char('\0'), QLatin1Char(' ')); | ||
452 | } | 453 | } | ||
453 | 454 | | |||
454 | mFile.close(); | 455 | mFile.close(); | ||
455 | return true; | 456 | return true; | ||
456 | } | 457 | } | ||
457 | 458 | | |||
459 | bool ProcessesLocal::Private::readProcSmaps(const QString &dir, Process *process) | ||||
460 | { | ||||
461 | mFile.setFileName(dir + QStringLiteral("smaps_rollup")); | ||||
462 | if (!mFile.open(QIODevice::ReadOnly)) { | ||||
463 | return false; | ||||
464 | } | ||||
465 | | ||||
466 | auto totalPss = -1LL; | ||||
467 | while (mFile.readLine(mBuffer, sizeof(mBuffer)) > 0) { | ||||
468 | if (qstrncmp(mBuffer, "Pss:", strlen("Pss:")) == 0) { | ||||
469 | totalPss += atoll(mBuffer + sizeof("Pss:") - 1); | ||||
470 | } | ||||
471 | } | ||||
472 | | ||||
473 | mFile.close(); | ||||
474 | | ||||
475 | process->setVmPSS(totalPss); | ||||
476 | | ||||
477 | return true; | ||||
478 | } | ||||
479 | | ||||
458 | bool ProcessesLocal::Private::getNiceness(long pid, Process *process) { | 480 | bool ProcessesLocal::Private::getNiceness(long pid, Process *process) { | ||
459 | int sched = sched_getscheduler(pid); | 481 | int sched = sched_getscheduler(pid); | ||
460 | switch(sched) { | 482 | switch(sched) { | ||
461 | case (SCHED_OTHER): | 483 | case (SCHED_OTHER): | ||
462 | process->setScheduler(KSysGuard::Process::Other); | 484 | process->setScheduler(KSysGuard::Process::Other); | ||
463 | break; | 485 | break; | ||
464 | case (SCHED_RR): | 486 | case (SCHED_RR): | ||
465 | process->setScheduler(KSysGuard::Process::RoundRobin); | 487 | process->setScheduler(KSysGuard::Process::RoundRobin); | ||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Line(s) | 573 | { | |||
552 | bool success = true; | 574 | bool success = true; | ||
553 | QString dir = QStringLiteral("/proc/") + QString::number(pid) + QLatin1Char('/'); | 575 | QString dir = QStringLiteral("/proc/") + QString::number(pid) + QLatin1Char('/'); | ||
554 | if(!d->readProcStat(dir, process)) success = false; | 576 | if(!d->readProcStat(dir, process)) success = false; | ||
555 | if(!d->readProcStatus(dir, process)) success = false; | 577 | if(!d->readProcStatus(dir, process)) success = false; | ||
556 | if(!d->readProcStatm(dir, process)) success = false; | 578 | if(!d->readProcStatm(dir, process)) success = false; | ||
557 | if(!d->readProcCmdline(dir, process)) success = false; | 579 | if(!d->readProcCmdline(dir, process)) success = false; | ||
558 | if(!d->readProcCGroup(dir, process)) success = false; | 580 | if(!d->readProcCGroup(dir, process)) success = false; | ||
559 | if(!d->readProcAttr(dir, process)) success = false; | 581 | if(!d->readProcAttr(dir, process)) success = false; | ||
582 | if(!d->readProcSmaps(dir, process)) success = false; | ||||
560 | if(!d->getNiceness(pid, process)) success = false; | 583 | if(!d->getNiceness(pid, process)) success = false; | ||
561 | if(mUpdateFlags.testFlag(Processes::IOStatistics) && !d->getIOStatistics(dir, process)) success = false; | 584 | if(mUpdateFlags.testFlag(Processes::IOStatistics) && !d->getIOStatistics(dir, process)) success = false; | ||
562 | 585 | | |||
563 | return success; | 586 | return success; | ||
564 | } | 587 | } | ||
565 | 588 | | |||
566 | QSet<long> ProcessesLocal::getAllPids( ) | 589 | QSet<long> ProcessesLocal::getAllPids( ) | ||
567 | { | 590 | { | ||
▲ Show 20 Lines • Show All 189 Lines • Show Last 20 Lines |