Changeset View
Changeset View
Standalone View
Standalone View
processui/ProcessModel.cpp
Show First 20 Lines • Show All 791 Lines • ▼ Show 20 Line(s) | 734 | } else { | |||
---|---|---|---|---|---|
792 | } | 792 | } | ||
793 | if(process->changes() & KSysGuard::Process::IO) { | 793 | if(process->changes() & KSysGuard::Process::IO) { | ||
794 | totalUpdated++; | 794 | totalUpdated++; | ||
795 | QModelIndex index = q->createIndex(row, ProcessModel::HeadingIoRead, process); | 795 | QModelIndex index = q->createIndex(row, ProcessModel::HeadingIoRead, process); | ||
796 | emit q->dataChanged(index, index); | 796 | emit q->dataChanged(index, index); | ||
797 | index = q->createIndex(row, ProcessModel::HeadingIoWrite, process); | 797 | index = q->createIndex(row, ProcessModel::HeadingIoWrite, process); | ||
798 | emit q->dataChanged(index, index); | 798 | emit q->dataChanged(index, index); | ||
799 | } | 799 | } | ||
800 | | ||||
801 | /* Normally this would only be called if changes() tells | ||||
802 | * us to. We need to update the timestamp even if the value | ||||
803 | * didn't change though. */ | ||||
804 | auto historyMapEntry = mMapProcessCPUHistory.find(process); | ||||
broulik: Use `find()` to avoid double lookup (contains+operator[]) | |||||
805 | if(historyMapEntry != mMapProcessCPUHistory.end()) { | ||||
806 | auto &history = *historyMapEntry; | ||||
807 | unsigned long timestamp = QDateTime::currentMSecsSinceEpoch(); | ||||
808 | // Only add an entry if the latest one is older than MIN_HIST_AGE | ||||
broulik: `isEmpty()` | |||||
809 | if(history.isEmpty() || timestamp - history.constLast().timestamp > MIN_HIST_AGE) { | ||||
broulik: Braces also for one-line statements | |||||
810 | if(history.size() == MAX_HIST_ENTRIES) { | ||||
811 | history.removeFirst(); | ||||
812 | } | ||||
813 | | ||||
814 | float usage = (process->totalUserUsage() + process->totalSysUsage()) / (100.0f * mNumProcessorCores); | ||||
815 | history.push_back({static_cast<unsigned long>(QDateTime::currentMSecsSinceEpoch()), usage}); | ||||
816 | } | ||||
817 | } | ||||
800 | } | 818 | } | ||
801 | } | 819 | } | ||
802 | 820 | | |||
803 | void ProcessModelPrivate::beginInsertRow( KSysGuard::Process *process) | 821 | void ProcessModelPrivate::beginInsertRow( KSysGuard::Process *process) | ||
804 | { | 822 | { | ||
805 | Q_ASSERT(process); | 823 | Q_ASSERT(process); | ||
806 | Q_ASSERT(!mRemovingRow); | 824 | Q_ASSERT(!mRemovingRow); | ||
807 | Q_ASSERT(!mInsertingRow); | 825 | Q_ASSERT(!mInsertingRow); | ||
Show All 29 Lines | |||||
837 | { | 855 | { | ||
838 | Q_ASSERT(process); | 856 | Q_ASSERT(process); | ||
839 | Q_ASSERT(process->pid() >= 0); | 857 | Q_ASSERT(process->pid() >= 0); | ||
840 | Q_ASSERT(!mRemovingRow); | 858 | Q_ASSERT(!mRemovingRow); | ||
841 | Q_ASSERT(!mInsertingRow); | 859 | Q_ASSERT(!mInsertingRow); | ||
842 | Q_ASSERT(!mMovingRow); | 860 | Q_ASSERT(!mMovingRow); | ||
843 | mRemovingRow = true; | 861 | mRemovingRow = true; | ||
844 | 862 | | |||
863 | mMapProcessCPUHistory.remove(process); | ||||
864 | | ||||
845 | if(mSimple) { | 865 | if(mSimple) { | ||
846 | return q->beginRemoveRows(QModelIndex(), process->index(), process->index()); | 866 | return q->beginRemoveRows(QModelIndex(), process->index(), process->index()); | ||
847 | } else { | 867 | } else { | ||
848 | int row = process->parent()->children().indexOf(process); | 868 | int row = process->parent()->children().indexOf(process); | ||
849 | if(row == -1) { | 869 | if(row == -1) { | ||
850 | qCDebug(LIBKSYSGUARD) << "A serious problem occurred in remove row."; | 870 | qCDebug(LIBKSYSGUARD) << "A serious problem occurred in remove row."; | ||
851 | mRemovingRow = false; | 871 | mRemovingRow = false; | ||
852 | return; | 872 | return; | ||
▲ Show 20 Lines • Show All 921 Lines • ▼ Show 20 Line(s) | 1775 | switch(index.column()) { | |||
1774 | case HeadingSharedMemory: | 1794 | case HeadingSharedMemory: | ||
1775 | if(process->vmURSS() == -1 || d->mMemTotal <= 0) | 1795 | if(process->vmURSS() == -1 || d->mMemTotal <= 0) | ||
1776 | return -1; | 1796 | return -1; | ||
1777 | return float(process->vmRSS() - process->vmURSS())/d->mMemTotal; | 1797 | return float(process->vmRSS() - process->vmURSS())/d->mMemTotal; | ||
1778 | default: | 1798 | default: | ||
1779 | return -1; | 1799 | return -1; | ||
1780 | } | 1800 | } | ||
1781 | } | 1801 | } | ||
1802 | case PercentageHistoryRole: { | ||||
1803 | KSysGuard::Process *process = reinterpret_cast< KSysGuard::Process * > (index.internalPointer()); | ||||
1804 | Q_CHECK_PTR(process); | ||||
1805 | switch(index.column()) { | ||||
1806 | case HeadingCPUUsage: { | ||||
1807 | auto it = d->mMapProcessCPUHistory.find(process); | ||||
1808 | if (it == d->mMapProcessCPUHistory.end()) { | ||||
1809 | it = d->mMapProcessCPUHistory.insert(process, {}); | ||||
1810 | it->reserve(ProcessModelPrivate::MAX_HIST_ENTRIES); | ||||
1811 | } | ||||
1812 | return QVariant::fromValue(*it); | ||||
1813 | } | ||||
1814 | default: {} | ||||
1815 | } | ||||
1816 | return QVariant::fromValue(QVector<PercentageHistoryEntry>{}); | ||||
1817 | } | ||||
1782 | case Qt::DecorationRole: { | 1818 | case Qt::DecorationRole: { | ||
1783 | if(index.column() == HeadingName) { | 1819 | if(index.column() == HeadingName) { | ||
1784 | #if HAVE_X11 | 1820 | #if HAVE_X11 | ||
1785 | KSysGuard::Process *process = reinterpret_cast< KSysGuard::Process * > (index.internalPointer()); | 1821 | KSysGuard::Process *process = reinterpret_cast< KSysGuard::Process * > (index.internalPointer()); | ||
1786 | if(!process->hasManagedGuiWindow()) { | 1822 | if(!process->hasManagedGuiWindow()) { | ||
1787 | if(d->mSimple) //When not in tree mode, we need to pad the name column where we do not have an icon | 1823 | if(d->mSimple) //When not in tree mode, we need to pad the name column where we do not have an icon | ||
1788 | return QIcon(d->mBlankPixmap); | 1824 | return QIcon(d->mBlankPixmap); | ||
1789 | else //When in tree mode, the padding looks bad, so do not pad in this case | 1825 | else //When in tree mode, the padding looks bad, so do not pad in this case | ||
▲ Show 20 Lines • Show All 389 Lines • Show Last 20 Lines |
Use find() to avoid double lookup (contains+operator[])