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 904 Lines • ▼ Show 20 Line(s) | 1758 | switch(index.column()) { | |||
1757 | case HeadingSharedMemory: | 1777 | case HeadingSharedMemory: | ||
1758 | if(process->vmURSS() == -1 || d->mMemTotal <= 0) | 1778 | if(process->vmURSS() == -1 || d->mMemTotal <= 0) | ||
1759 | return -1; | 1779 | return -1; | ||
1760 | return float(process->vmRSS() - process->vmURSS())/d->mMemTotal; | 1780 | return float(process->vmRSS() - process->vmURSS())/d->mMemTotal; | ||
1761 | default: | 1781 | default: | ||
1762 | return -1; | 1782 | return -1; | ||
1763 | } | 1783 | } | ||
1764 | } | 1784 | } | ||
1785 | case PercentageHistoryRole: { | ||||
1786 | KSysGuard::Process *process = reinterpret_cast< KSysGuard::Process * > (index.internalPointer()); | ||||
1787 | Q_CHECK_PTR(process); | ||||
1788 | switch(index.column()) { | ||||
1789 | case HeadingCPUUsage: { | ||||
1790 | auto it = d->mMapProcessCPUHistory.find(process); | ||||
1791 | if (it == d->mMapProcessCPUHistory.end()) { | ||||
1792 | it = d->mMapProcessCPUHistory.insert(process, {}); | ||||
1793 | it->reserve(ProcessModelPrivate::MAX_HIST_ENTRIES); | ||||
1794 | } | ||||
1795 | return QVariant::fromValue(*it); | ||||
1796 | } | ||||
1797 | default: {} | ||||
1798 | } | ||||
1799 | return QVariant::fromValue(QVector<PercentageHistoryEntry>{}); | ||||
1800 | } | ||||
1765 | case Qt::DecorationRole: { | 1801 | case Qt::DecorationRole: { | ||
1766 | if(index.column() == HeadingName) { | 1802 | if(index.column() == HeadingName) { | ||
1767 | #if HAVE_X11 | 1803 | #if HAVE_X11 | ||
1768 | KSysGuard::Process *process = reinterpret_cast< KSysGuard::Process * > (index.internalPointer()); | 1804 | KSysGuard::Process *process = reinterpret_cast< KSysGuard::Process * > (index.internalPointer()); | ||
1769 | if(!process->hasManagedGuiWindow()) { | 1805 | if(!process->hasManagedGuiWindow()) { | ||
1770 | if(d->mSimple) //When not in tree mode, we need to pad the name column where we do not have an icon | 1806 | if(d->mSimple) //When not in tree mode, we need to pad the name column where we do not have an icon | ||
1771 | return QIcon(d->mBlankPixmap); | 1807 | return QIcon(d->mBlankPixmap); | ||
1772 | else //When in tree mode, the padding looks bad, so do not pad in this case | 1808 | 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[])