Skip to content

Two-channel graph (Graph2) meter style#1415

Open
Explorer09 wants to merge 13 commits intohtop-dev:mainfrom
Explorer09:graph-with-neg
Open

Two-channel graph (Graph2) meter style#1415
Explorer09 wants to merge 13 commits intohtop-dev:mainfrom
Explorer09:graph-with-neg

Conversation

@Explorer09
Copy link
Copy Markdown
Contributor

@Explorer09 Explorer09 commented Mar 17, 2024

This pull request implements the "two-channel" graph style as the new "Graph2" meter mode. This is based on #714 so that the graphs will be shown with colors.

This new mode is designed for a few meters only— only DiskIORateMeter (#1763, merged) and NetworkIOMeter can correctly utilise this mode by showing the input and output rates as separate channels.

The feature was previously discussed in #1390.

Below is a preview screenshot taken in macOS Sequoia.
I included both Unicode mode and --no-unicode mode.
htop-screenshot-graph2-meter-mode

@Explorer09 Explorer09 force-pushed the graph-with-neg branch 3 times, most recently from f47a975 to 745f394 Compare March 28, 2024 13:54
@BenBE BenBE added the feature request Completely new feature requested label Apr 13, 2024
@Explorer09 Explorer09 force-pushed the graph-with-neg branch 3 times, most recently from 31cb513 to bedca8f Compare April 21, 2024 06:39
@Explorer09 Explorer09 force-pushed the graph-with-neg branch 4 times, most recently from ade4922 to 54d3d1c Compare April 26, 2024 18:59
@Explorer09 Explorer09 force-pushed the graph-with-neg branch 3 times, most recently from 728ef87 to 3033b1d Compare May 2, 2024 21:01
@BenBE BenBE self-assigned this May 2, 2024
@Explorer09 Explorer09 force-pushed the graph-with-neg branch 2 times, most recently from aa96aa4 to 10bb617 Compare May 22, 2024 19:03
@Explorer09 Explorer09 force-pushed the graph-with-neg branch 2 times, most recently from f57affb to 5e3eeb1 Compare August 25, 2024 23:10
@Explorer09 Explorer09 force-pushed the graph-with-neg branch 2 times, most recently from b5560f5 to 8a8cfda Compare December 16, 2024 09:53
@Explorer09 Explorer09 force-pushed the graph-with-neg branch 3 times, most recently from c7c11bc to b446269 Compare February 9, 2025 18:16
@Explorer09 Explorer09 force-pushed the graph-with-neg branch 2 times, most recently from 8ce2c96 to 4ae1d01 Compare November 15, 2025 18:07
@Explorer09 Explorer09 mentioned this pull request Nov 16, 2025
@Explorer09 Explorer09 force-pushed the graph-with-neg branch 3 times, most recently from 95052ef to d370bf3 Compare December 2, 2025 17:13
@Explorer09 Explorer09 force-pushed the graph-with-neg branch 2 times, most recently from 5e7bb49 to 0d092e5 Compare January 9, 2026 08:12
@eworm-de
Copy link
Copy Markdown
Contributor

The traditional graphical meters have a gray baseline. Does it make sense to have that here as well?

@eworm-de
Copy link
Copy Markdown
Contributor

Oh, and another note... Personally I do not like just adding numbers to names, at least for new functionality. How about something a little bit more descriptive? Perhaps "NGraph" (for negative) or "TCGraph" (for two-channel)?

@Explorer09
Copy link
Copy Markdown
Contributor Author

Explorer09 commented Mar 30, 2026

The traditional graphical meters have a gray baseline. Does it make sense to have that here as well?

I've tried it. It would visually distract too much, as the "baseline" on the middle would be two times as thick. And I didn't like it.

Oh, and another note... Personally I do not like just adding numbers to names, at least for new functionality. How about something a little bit more descriptive? Perhaps "NGraph" (for negative) or "TCGraph" (for two-channel)?

"Graph2C" ?
For technical reason I would like to avoid putting digits in the front of the name. Although I believe the "Graph2" name is fine.

@eworm-de
Copy link
Copy Markdown
Contributor

I've tried it. It would visually distract too much, as the "baseline" on the middle would be two times as thick. And I didn't like it.

Ah, right... But I have some systems that have just little to no disk io activity, especially for reading. Some random blue dots floating around is distracting, too. 😝 Not sure what's better.

”Graph2C” ? For technical reason I would like to avoid putting digits in the front of the name. Although I believe the "Graph2" name is fine.

Oh, I read the name "Graph2" as "Graph, increment by one". If you take it as an abbreviation for "Graph two-channel" it makes kind of sense. 😉

Anyway, I would prefer your suggestion "Graph2C" if it is possible and fine for you. Any other opinions?

@eworm-de
Copy link
Copy Markdown
Contributor

eworm-de commented Apr 2, 2026

This screenshot is made in a machine started from live media.

Screenshot_2026-04-02_13-51-41

Nothing in the disk meter (as it is running from optical media nothing is ever written), and just very little activity in network meter. It's really hard to tell where the (virtual) base line is.

@eworm-de
Copy link
Copy Markdown
Contributor

eworm-de commented Apr 2, 2026

... and created a mockup.

Screenshot_2026-04-02_13-51-41

That's what a base line could look like.

Still not sure which one I would prefer...

@Explorer09
Copy link
Copy Markdown
Contributor Author

... and created a mockup.

That's what a base line could look like.

Still not sure which one I would prefer...

The baselines could look bad if you have a terminal emulator that displays braille matrix with gaps between characters.

See this screenshot for what I mean:

htop-screenshot-network-io-meter

In the screenshot I also use an alternative to two baselines in the middle.

@eworm-de
Copy link
Copy Markdown
Contributor

eworm-de commented Apr 2, 2026

Actually it's not that bad. I think that's the version I would prefer, and with proper spacing (I use font Terminus here, and my screenshot were made with that) this would look even better.

When both the options "Add guest time in CPU meter percentage" and
"Detailed CPU time" are turned off, the CPU meter used to show the
"virtual" CPU time in the bar display as a glitch. Now fix it.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
The time displayed is (steal+guest), not just guest CPU time.

Regression from 3d8fa0b

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Linux and PCP platform code used to write the 'virtualized'
(steal+guest) CPU time into the CPU_METER_IRQ item when the "detailed
CPU time" option is off, which would result in a wrong color painted for
virtual CPU time in bar mode. Write the 'virtualized' CPU time to
CPU_METER_STEAL instead, which is more appropriate for the job.

Also update the "virtualized" CPU meter item in the help screen: (1) The
color is now CPU_STEAL for consistency. (2) In monochrome mode, two
dummy items are displayed before the "virtualized" word so that the
bar meter symbol mapping is correct.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Round the graph meter's dynamic scale to a power of two and print the
graph scale. For a percent graph, a "%" character is printed in place
of the scale.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
This is a prerequisite for the feature "Graph meter coloring (with
GraphData structure rework)".

powerOf2Floor() will utilize __builtin_clz() or stdc_bit_floor_ui()
(__builtin_clz() is preferred) if either is supported.

popCount8() will utilize ARM NEON instructions and x86 POPCNT
instruction if the machine supports either of them.

I am not adopting the C23 standard interface stdc_count_ones_uc() yet,
as I am not sure C libraries would implement it as fast as our version.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Rewrite the entire graph meter drawing code to support color graph
drawing in addition to the dynamic scaling (both can work together
because of the new GraphData structure design).

The colors of a graph are based on the percentages of item values of
the meter. The rounding differences of each terminal character are
addressed through the different numbers of braille dots.

Due to low resolution of the character terminal, the rasterized colors
may not look nice, but better than nothing. :)

The new GraphData structure design has two technical limitations:
* The height of a graph meter now has a limit of 8191 (terminal rows).
* If dynamic scaling is used, the "total" value or scale of a graph now
  has to align to a power of 2.

The code is designed with the anticipation that the graph height may
change at runtime. No UI or option has been implemented for that yet.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Specifically 'PIXPERROW_*' and 'GraphMeterMode_dots*' constants.
They were commented out rather than removed in the previous commit (for
ease of code reviewing). Now this commit removes the constant defines
for good.
Introduce a new meter mode (meter style) called "Graph2". The "Graph2"
name stands for "two-channel graph" or "two-quadrant graph".

This meter mode is not in the list of default supported modes. This
"Graph2" mode is intended for meters with two item values. It plots
the first item above the x-axis and the second item below the x-axis.
Items other than the first two are always hidden.

This code is written with the intention to share as much code with the
Graph meter mode as possible.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Specifically it's the DiskIORateMeter part that supports "Graph2" mode.
For the combined DiskIOMeter, the "IO rate" part can show as two-channel
graph while the "IO time" part remains a one-channel graph.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
This special case of "details" value would print as ':' in the ASCII
display mode. It is used in "Graph2" meter drawing only.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request Completely new feature requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Graph meter style with negative values

3 participants