Commit Graph

124 Commits

Author SHA1 Message Date
Nathan Scott f0ed0fdafb Add a new DynamicMeter class for runtime Meter extension
This commit is based on exploratory work by Sohaib Mohamed.
The end goal is two-fold - to support addition of Meters we
build via configuration files for both the PCP platform and
for scripts ( https://github.com/htop-dev/htop/issues/526 )

Here, we focus on generic code and the PCP support.  A new
class DynamicMeter is introduced - it uses the special case
'param' field handling that previously was used only by the
CPUMeter, such that every runtime-configured Meter is given
a unique identifier.  Unlike with the CPUMeter this is used
internally only.  When reading/writing to htoprc instead of
CPU(N) - where N is an integer param (CPU number) - we use
the string name for each meter.  For example, if we have a
configuration for a DynamicMeter for some Redis metrics, we
might read and write "Dynamic(redis)".  This identifier is
subsequently matched (back) up to the configuration file so
we're able to re-create arbitrary user configurations.

The PCP platform configuration file format is fairly simple.
We expand configs from several directories, including the
users homedir alongside htoprc (below htop/meters/) and also
/etc/pcp/htop/meters.  The format will be described via a
new pcp-htop(5) man page, but its basically ini-style and
each Meter has one or more metric expressions associated, as
well as specifications for labels, color and so on via a dot
separated notation for individual metrics within the Meter.

A few initial sample configuration files are provided below
./pcp/meters that give the general idea.  The PCP "derived"
metric specification - see pmRegisterDerived(3) - is used
as the syntax for specifying metrics in PCP DynamicMeters.
2021-07-07 10:59:36 +10:00
mayurdahibhate 1b74dfe187 cleaned up includes with iwyu 2021-05-10 18:40:53 +02:00
Nathan Scott 356488aa53 Request the realtime and monotonic clock times once per sample
Refactor the sample time code to make one call to gettimeofday
(aka the realtime clock in clock_gettime, when available) and
one to the monotonic clock.  Stores each in more appropriately
named ProcessList fields for ready access when needed.  Every
platform gets the opportunity to provide their own clock code,
and the existing Mac OS X specific code is moved below darwin
instead of in Compat.

A couple of leftover time(2) calls are converted to use these
ProcessList fields as well, instead of yet again sampling the
system clock.

Related to https://github.com/htop-dev/htop/pull/574
2021-04-05 23:41:07 +02:00
Sohaib 421bdeec60 Merging all the points related to calculating time in one place
The end goal is to consolidate all the points in htop that can only work in
live-only mode today, so that will be able to inject PCP archive mode and have
a chance at it working.
The biggest problem we've got at this moment is all the places that are
independently asking the kernel to 'give me the time right now'.
Each of those needs to be audited and ultimately changed to allow platforms to
manage their own idea of time.
So, all the calls to gettimeofday(2) and time(2) are potential problems.
Ultimately I want to get these down to just one or two.

Related to https://github.com/htop-dev/htop/pull/574
2021-04-05 23:40:41 +02:00
Christian Göttsche 9c437ceb0c Drop unused attributes of actually used function parameters
These parameters were once unused, but not anymore.
2021-03-24 19:27:03 +01:00
Christian Göttsche a11d01568c Use unsigned types for CPU counts and associated variables 2021-03-19 23:30:54 +01:00
Christian Göttsche 1e806f9899 RichString: do not unnecessarily clean whole buffer
The local stack buffer does not need to be cleaned to zeros when
  - just initialized, cause the length is set to 0 and the first
    character is set to '\0', so all printing functions will safely stop
  - no further used, i.e. the variable goes out of scope
2021-03-17 15:54:17 +01:00
Christian Göttsche 350b48e44c Meter: do not access RichString internals
Use a temporary local variable
2021-03-12 16:49:45 +01:00
Nathan Scott 31e59cc60d Merge branch 'misc' of https://github.com/cgzones/htop into cgzones-misc 2021-03-05 13:38:19 +11:00
Christian Göttsche b862e36ee7 Separate data-update and drawing of header 2021-03-04 23:57:45 +01:00
Christian Göttsche 2d1042adb3 Save text buffer in Meter 2021-03-04 23:57:45 +01:00
Christian Göttsche df818b9904 Use ATTR_UNUSED instead of void casting 2021-03-02 22:03:20 +01:00
Michael F. Schönitzer 76350c0350 Rescale graph when value of total is changed 2021-02-28 17:42:10 +01:00
Nathan Scott 8cd90f0c4a Fix a couple of small spelling mistakes in comments 2021-02-15 12:54:20 +11:00
Christian Göttsche b5a5e83470 LED Meter: display wide characters and restore non-wide ncurses support
Print wide characters, like degree sign, properly via mvadd_wch().
Ignore attributes when returning value from RichString_getCharVal() in
non-wide ncurses mode to test against raw characters.
2021-01-15 20:41:10 +01:00
Christian Göttsche 5fde0e0127 RichString_appendChr: add parameter to set attributes
Allows to set attributes when padding process fields in non-wide ncurses
mode.

Closes: #475
2021-01-13 19:22:33 +01:00
Christian Göttsche d72b0a682e Mark several non-modified pointer variables const 2021-01-11 20:12:34 +01:00
Christian Göttsche 70f48f1f44 Add wrapper function for free and strdup
Reduces code in callers and helps avoiding memory leaks.
2021-01-11 20:12:34 +01:00
Christian Göttsche 3bb731c645 RichString_setAttrn: refactor to take a length instead of a stop index
Fixes: #459
2021-01-10 16:51:25 +01:00
Christian Göttsche 6301d5c1da Convert unnecessary static variables
They are not used in any other function and are not used maybe
uninitialized.
2021-01-09 14:31:07 +01:00
Christian Göttsche 2c06566405 LoadMeter: dynamically adjust color and total of bar
Change the color and total based on the actual 1min load value:

    < 1         : green and total of 1.0
    < cpu-count : yellow and total of cpu-count
    else        : red and total of 2*cpu-count

Closes: #32
2020-12-26 13:32:29 +01:00
Benny Baumann 5fa1c7040d Minor typo and comment clarification 2020-12-20 17:15:51 +01:00
Christian Göttsche 6e46fd6f1f BarMeter: rework text padding
In case the text is too long for the bar, try to fit by truncating at a
space character.

E.g.
    [|24.1% 2000Mhz 40°C]
    [24.1% 2000Mhz 40°C]
    [||||24.1% 2000Mhz]
    [|||24.1% 2000Mhz]
    [||24.1% 2000Mhz]
    [|24.1% 2000Mhz]
    [24.1% 2000Mhz]
    [||||   24.1%]
    [||||  24.1%]
    [|||| 24.1%]
    [||||24.1%]
    [|||24.1%]
    [||24.1%]
    [|24.1%]
    [24.1%]
    [24.1]
    [24.]
    [24]
    [2]
2020-12-20 16:55:17 +01:00
Christian Göttsche c5e31ba4aa Meter: fix artifacts with very tiny width
- The Bar Meter might override the right border
- The TextMeter might wrap-around into the next line
2020-12-20 16:55:17 +01:00
Christian Göttsche 79970f05f3 Meter: restore non-wide-character build
Use mbstowcs() only with wide ncurses support.

Closes: #401
2020-12-15 12:05:39 +01:00
Christian Göttsche 157086e750 Split RichString_(append|appendn|write) into wide and ascii
RichString_writeFrom takes a top spot during performance analysis due to the
calls to mbstowcs() and iswprint().

Most of the time we know in advance that we are only going to print regular
ASCII characters.
2020-12-08 20:58:40 +01:00
Christian Göttsche ad764ff972 Introduce METER_BUFFER_CHECK and METER_BUFFER_APPEND_CHR to cleanup writing to bar buffers
Closes: #294
2020-12-06 16:03:44 +01:00
Christian Göttsche e1ce141bc3 Use size_t as len type for Meter_UpdateValues
Most of the time the parameter is passed to snprintf type functions
2020-12-06 16:03:44 +01:00
Christian Göttsche 7ba25aa3c4 IWYU update 2020-12-06 15:32:16 +01:00
Christian Göttsche 5f528b7455 Meter: fix bar coloring without wide ncurses support
attrset() seems to not work with mvaddchnstr()
2020-12-05 20:01:10 +01:00
Christian Göttsche f0a9dfc37e Resolve conversion from int to char 2020-12-05 19:58:32 +01:00
Christian Göttsche 1e9b184367 Resolve conversion from int to unsigned and back 2020-12-05 19:58:32 +01:00
Christian Göttsche ea4f33409a Update even more snprintfs
Use size of actual buffers instead of magic numbers
2020-11-28 19:33:07 +01:00
Christian Göttsche 267014cbfe Add support to change numeric options in settings screen
Like delay or highlightDelaySecs
2020-11-25 20:46:27 +01:00
Christian Göttsche adf9185209 Fully support non-ascii characters in Meter-Bar
Currently the code does not handle multi-byte characters, so length-
computations take the raw count of C characters and not the to displayed
size into account.

An example is the degree sign for temperatures.

Closes: #329
2020-11-25 20:45:54 +01:00
Benny Baumann 45869513bf Embracing branches 2020-11-02 22:15:01 +01:00
Benny Baumann 61e14d4bb2 Spacing around operators 2020-11-02 22:15:01 +01:00
Benny Baumann adf797c295 Spacing after keywords (for) 2020-11-02 22:15:01 +01:00
Christian Göttsche 43d274a617 Use integer type for item count instead of char 2020-10-31 18:36:55 +01:00
Christian Göttsche 72103e9613 Hold only a const version of the ProcessList in Meters 2020-10-26 19:30:38 +01:00
Christian Göttsche 577416d1a9 Assert allocating non-zero size memory
Allocating zero size memory results in implementation-defined behavior:

  man:malloc(3) :
    If size is 0, then malloc() returns either NULL, or a unique pointer
    value that can later be successfully passed to free().
2020-10-19 15:35:43 +02:00
Benny Baumann 0f5262917f Make all required includes explicit
Information as seen by IWYU 0.12 + clang 9 on Linux
2020-10-18 20:09:05 +02:00
Benny Baumann 872e542f4e Rename StringUtils.[ch] to XUtils.[ch] 2020-10-16 20:30:21 +02:00
Christian Göttsche 0b9a001498 Meter: use explicit type for drawData 2020-10-12 13:15:23 +02:00
Christian Göttsche 79ad39c718 Mark Object pointer to _display function const 2020-10-10 11:25:19 +02:00
Christian Göttsche ba282cfe19 Mark Object instances const 2020-10-07 13:01:53 +02:00
Christian Göttsche 08d85e6143 Mark Object classes and Object class fields const 2020-10-07 13:01:53 +02:00
Daniel Lange 079c2abf8e Update License consistently to GPLv2 as per COPYING file 2020-10-05 10:13:12 +02:00
Christian Göttsche 6db2d52261 Covert Meter attributes to file-local constant arrays 2020-09-29 10:44:42 +02:00
Christian Göttsche 843949131a Drop redundant casts to the same type 2020-09-29 10:44:42 +02:00