Add a per-process CPU usage graph shown in the process list
ClosedPublic

Authored by fvogt on Jan 6 2018, 12:55 AM.

Details

Summary

By adding a new PercentageHistoryRole returning a QVector with timestamps and
values, the delegate can show the history of the percentage as background.

This is currently only done for the CPU usage, but can easily be added for
memory as well.

The history vector is only created and filled after the first access on each
process.

Test Plan

Added a small testcase which verifies that the history vector has an entry
with the current value after the first refresh after the initial access.
The end result looks like this:
https://phabricator.kde.org/file/data/5edv3vrjl6fvmwhjbccs/PHID-FILE-yk64umgu5qv72pblkfud/KSysguard_with_per-process_cpu_graph

Diff Detail

Repository
R111 KSysguard Library
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
fvogt created this revision.Jan 6 2018, 12:55 AM
Restricted Application added a project: Plasma. · View Herald TranscriptJan 6 2018, 12:55 AM
fvogt requested review of this revision.Jan 6 2018, 12:55 AM
fvogt updated this revision to Diff 24804.Jan 6 2018, 1:11 AM

Remove the history tail before appending the head to never exceed the reserved vector size

ngraham added a subscriber: ngraham.Jan 6 2018, 6:08 AM
fvogt updated this revision to Diff 24836.Jan 6 2018, 2:41 PM

Instead of updating the last entry's timestamp if the value is the same, add a new
entry only if the latest entry has a certain age.
Otherwise, the interpolation results would look differently and processes had different
lengths of histroy graphs depending on the values, which looks odd.

fvogt updated this revision to Diff 24838.Jan 6 2018, 3:02 PM

Forgot to save ProcessModel.cpp before git commit.

broulik added a subscriber: broulik.Jan 8 2018, 9:30 AM

Screenshot? :)

processui/ProcessModel.cpp
804

Use find() to avoid double lookup (contains+operator[])

808

isEmpty()

809

Braces also for one-line statements

fvogt updated this revision to Diff 24921.Jan 8 2018, 9:46 AM

Address review comments.

Set a unified alpha for percentage marker and history graph to avoid sudden changes:
33%: Percentage marker
66%: History graph
100%: Text

Screenshot is linked in the test plan.

fvogt retitled this revision from [WIP] Add a per-process CPU usage graph shown in the process list to Add a per-process CPU usage graph shown in the process list.Jan 8 2018, 9:46 AM
fvogt edited the test plan for this revision. (Show Details)
fvogt updated this revision to Diff 24935.Jan 8 2018, 12:39 PM

Rebase on current master. (Apparently my local master wasn't setup to follow origin...)

+1

processui/ksysguardprocesslist.cpp
124

Coding style

tests/processtest.cpp
221

This leaks (note how the other tests delete it afterwards), or wrap it in a QScopedPointer

226

rowCount() already has a default argument for index

fvogt updated this revision to Diff 25109.Jan 10 2018, 6:03 PM

Address review comments.

Looks like a very nice to have feature :) (no review though, not my playground, was just curious when you pointed to it on irc)

processui/ProcessModel.h
210

You could also add Q_DECLARE_TYPEINFO(ProcessModel::PercentageHistoryEntry, Q_PRIMITIVE_TYPE); for some mini-opt, given the vector is changing size now and then (and needs its data copied to the new array).

fvogt updated this revision to Diff 25206.Jan 12 2018, 9:18 AM

Declare PercentageHistoryEntry as Q_PRIMITIVE_TYPE

broulik accepted this revision.Jan 15 2018, 9:55 AM
This revision is now accepted and ready to land.Jan 15 2018, 9:55 AM
This revision was automatically updated to reflect the committed changes.