summaryrefslogtreecommitdiffstats
path: root/Meter.c
Commit message (Collapse)AuthorAgeFilesLines
* Adjust some code style for maintainabilityExplorer0913 days1-2/+2
|
* Define MeterModeId to unsigned int and use it throughoutExplorer0913 days1-1/+1
| | | | | | | | | All uses of meter drawing "mode" numbers now have the type `MeterModeId`, including the uses in structures and arrays. `MeterModeId` is defined as `unsigned int`, as (currently) it doesn't save any code size by defining it to any smaller type. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Make 'Meter_modes' private and simplify its structureExplorer0913 days1-33/+34
| | | | | | | | | | | All client codes that access this global `Meter_modes` array have been replaced in previous commits, thus it's no longer necessary to keep this internal information (draw functions, default heights, etc.) public. It was also a bad idea when the client codes need to avoid accessing `Meter_modes[0]` (which is reserved and contains null information) by themselves. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Reorder Meter.c sections. No code changes.Explorer0913 days1-123/+127
| | | | | This section reordering is a prerequisite to privatizing the `Meter_modes` array.
* Obsolete the CUSTOM_METERMODE use in default modeExplorer0913 days1-4/+3
| | | | | | | | | | | | | | | | | | | | | The use of CUSTOM_METERMODE value in meter default mode was a bad design. There are no meter that really has a "custom" mode to work with and currently that value serves as a useless placeholder that hides the real default mode for a meter. Replace CUSTOM_METERMODE in `defaultMode` of all meters with the real intended default modes. Currently only CPU meters and MemorySwapMeter used this, and their real defaults are BAR_METERMODE. In Meter_setMode(), remove the special treatment of `defaultMode == CUSTOM_METERMODE`, Meter_setMode() still calls the `updateMode` function for custom treatment when it's present for a meter class. As CUSTOM_METERMODE is obsolete from `defaultMode`, the init functions of CPU meters and MemorySwapMeter need to be adjusted to avoid incomplete initialization (Meter.draw function bring NULL). Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* BarMeterMode_draw() code formatting adjustmentExplorer092024-04-131-1/+7
| | | | Suggested by Benny Baumann (@BenBE). No code changes.
* Update includes based on IWYUBenny Baumann2023-12-261-2/+1
|
* Meter: use correct unicode characters for digit '9'Christian Hesse2023-12-251-1/+1
| | | | The bottom line was too short before...
* Use xSnprintf in Meter_humanUnit()Explorer092023-11-241-2/+2
|
* Rewrite Meter_humanUnit() to accept floating point valueExplorer092023-11-241-19/+27
| | | | | | | | | | | | | | | | | Since Meter_humanUnit() is often called with floating point values in Meter objects, rewrite the function to let it process `double` type natively, and save floating point to integer casts. The rewritten function: * Allows higher orders of magnitude including 'R' and 'Q', and addresses infinity. (The previous version has a maximum value of (2^64 - 1) representing 16 ZiB.) * Rounds values when they are in intervals (99.9, 100) and (9.99, 10), and displays them with correct precision (number of fraction digits). * Produces assertion error on negative and NaN values (undefined behavior). Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Use memmove() for moving previous graph valuesExplorer092023-11-121-2/+1
| | | | | | | Reduce code size a little in GraphMeterMode_draw() when compiled in `-Os` mode. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Assert on BarMeterMode_characters lengthExplorer092023-11-121-0/+1
| | | | | | | | | The number of items of a Meter can exceed the length of BarMeterMode_characters array. (The CPU Meter is an example.) Item numbers exceeding the length are unplottable in a bar. Add an assertion to note the fact. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Permit zero 'total' in meters; remove assertionExplorer092023-11-101-6/+4
| | | | | | | | | | | The `Meter.total` value may be 0 on BatteryMeter, SwapMeter, linux/HugePageMeter, linux/ZramMeter and others. In case of a zero total value, print an empty bar in bar meter mode. Also change GraphMeterMode_draw() so that it no longer writes back the `total` value if it is zero. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Record new graph data even when no graph is drawn.Explorer092023-10-261-7/+14
| | | | | | | | | Fixes a regression caused by 74b28849c4ee7234aa6018667ff6c8c9a6b41273. When a graph meter is too narrow to draw the graph, but the graph data buffer is allocated, the meter should keep recording new values. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Cap the maximum size of GraphData buffer to 32768 values.Explorer092023-10-101-2/+7
| | | | Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* GraphMeterMode_draw() code cleanupExplorer092023-10-101-9/+3
| | | | | | | | * Rework the logic of computing `i` (initial index of graph data records) slightly and remove unreachable code. * Rename k to `col` and change its data type from ssize_t back to int. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Reorder some GraphMeterMode_draw() codeExplorer092023-10-101-13/+12
| | | | | | | | In particular, move the code for adding a new graph record to before the GraphMeterMode_dots selection code. (The latter is the drawing part of the function.) Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Let GraphMeterMode_draw() return early when the meter is too narrow...Explorer092023-10-101-8/+9
| | | | | | | | | ...to draw even a single record of the graph. This makes the code more robust by checking (w <= 0) explicitly. Also avoids unnecessary reallocations of the GraphData buffer. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Use size_t/ssize_t for nValue-related variablesBenny Baumann2023-10-101-4/+6
|
* Fix inconsistent type castBenny Baumann2023-10-101-1/+1
| | | | Ref: https://github.com/htop-dev/htop/commit/a33cbae28826de4f20930d225e31f3be0db0502b#r129599267 by @Explorer09
* Meter: allocate GraphData buffer dynamicallyZev Weiss2023-10-081-8/+14
| | | | | | | | | On wide screens the previous value of 256 could end up insufficient to cover the screen space allocated to the graph, leaving it awkwardly truncated mid-column. We now allocate the buffer dynamically instead, growing it to accommodate whatever width the graph occupies. Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
* Fix Meter.c #include order; no code changesExplorer092023-08-291-1/+1
|
* Rework ZramMeter and remove MeterClass.comprisedValuesExplorer092023-08-291-12/+1
| | | | | | | | | | | | The 'comprisedValues' boolean property unnecessarily complicates the drawing algorithms of Bar meters and Graph meters. Since the only user of 'comprisedValues' is ZramMeter, it is better to rework the meter so that it no longer needs 'comprisedValues'. The 'values[ZRAM_METER_UNCOMPRESSED]' now stores the difference between uncompressed and compressed data size. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Explicitly ignore NaN values in BarMeterMode_draw()Explorer092023-08-291-2/+3
| | | | | | Do not throw FP exceptions if any value in a Meter object is a NaN. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Replace isnan() with better comparisons (isgreater(), etc.)Explorer092023-08-181-4/+1
| | | | | | | | | | | | | | | | | | The standard isnan() function is defined to never throw FP exceptions even when the argument is a "signaling" NaN. This makes isnan() more expensive than (x != x) expression unless the compiler flag '-fno-signaling-nans' is given. Introduce functions isNaN(), isNonnegative(), isPositive(), sumPositiveValues() and compareRealNumbers(), and replace isnan() in htop's codebase with the new functions. These functions utilize isgreater() and isgreaterequal() comparisons, which do not throw FP exceptions on "quiet" NaNs, which htop uses extensively. With isnan() removed, there is no need to suppress the warning '-Wno-c11-extensions' in FreeBSD. Remove the code from 'configure.ac'. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Introduce Machine class for host-specific info (split from ProcessList)Nathan Scott2023-05-081-6/+6
| | | | | | | | | | | First stage in sanitizing the process list structure so that htop can support other types of lists too (cgroups, filesystems, ...), in the not-too-distant future. This introduces struct Machine for system-wide information while keeping process-list information in ProcessList (now much less). Next step is to propogate this separation into each platform, to match these core changes.
* Meter: introduce comprisedValues optionChristian Göttsche2023-04-111-4/+15
| | | | | Useful for bar mode if latter values of the meter comprise previous ones.
* Ignore NAN values when drawing graphser-azh2023-02-041-1/+1
|
* Do not leave empty last column in headerChristian Göttsche2021-12-091-5/+5
| | | | | | | Do not leave empty last column in header meters by refactoring the width and separator logic. Closes: #784
* Update license headers to explicitly say GPLv2+Daniel Lange2021-09-221-1/+1
|
* Simplify delay.tv_usec calculation from BenBEDaniel Lange2021-08-231-1/+1
| | | | Closes #761
* Widen integer type before multiplicationChristian Göttsche2021-08-221-1/+1
| | | | | | Meter.c:320:71: warning: performing an implicit widening conversion to type '__suseconds_t' (aka 'long') of a multiplication performed in type 'int' [bugprone-implicit- widening-of-multiplication-result] struct timeval delay = { .tv_sec = globalDelay / 10, .tv_usec = (globalDelay - ((globalDelay / 10) * 10)) * 100000 }; ^
* Meter: limit LED mode by widthChristian Göttsche2021-08-171-1/+6
| | | | Stop displaying LED-mode if maximum width is reached.
* Whitespace around operatorsBenny Baumann2021-07-151-1/+1
|
* Pretty-print values in the PCP DynamicMeter codeNathan Scott2021-07-081-6/+10
| | | | | | | | | | | | | | | | | Several improvements to the way values are displayed in the PCP platform DynamicMeter implementation: - handle the initial 'caption' setting as with regular meters, this required a new meter callback because we no longer have just a single meter caption for the DynamicMeter case - if no label is provided for a metric in a configuration file use the short form metric name as a fallback - honour the suffix setting in the configuration file - convert metric values to the canonical units for htop (kbyte and seconds), and use Meter_humanUnit when it makes sense to do so. Also improves the handling of fatal string error messages in a couple of places, thanks to BenBE for the review feedback.
* Add a new DynamicMeter class for runtime Meter extensionNathan Scott2021-07-071-7/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* cleaned up includes with iwyumayurdahibhate2021-05-101-1/+0
|
* Request the realtime and monotonic clock times once per sampleNathan Scott2021-04-051-2/+2
| | | | | | | | | | | | | | | | 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
* Merging all the points related to calculating time in one placeSohaib2021-04-051-4/+4
| | | | | | | | | | | | | | 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
* Drop unused attributes of actually used function parametersChristian Göttsche2021-03-241-1/+1
| | | | These parameters were once unused, but not anymore.
* Use unsigned types for CPU counts and associated variablesChristian Göttsche2021-03-191-2/+2
|
* RichString: do not unnecessarily clean whole bufferChristian Göttsche2021-03-171-5/+4
| | | | | | | 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
* Meter: do not access RichString internalsChristian Göttsche2021-03-121-2/+2
| | | | Use a temporary local variable
* Merge branch 'misc' of https://github.com/cgzones/htop into cgzones-miscNathan Scott2021-03-051-3/+1
|\
| * Use ATTR_UNUSED instead of void castingChristian Göttsche2021-03-021-3/+1
| |
* | Separate data-update and drawing of headerChristian Göttsche2021-03-041-8/+0
| |
* | Save text buffer in MeterChristian Göttsche2021-03-041-19/+13
|/
* Rescale graph when value of total is changedMichael F. Schönitzer2021-02-281-3/+4
|
* Fix a couple of small spelling mistakes in commentsNathan Scott2021-02-151-1/+1
|
* LED Meter: display wide characters and restore non-wide ncurses supportChristian Göttsche2021-01-151-1/+6
| | | | | | 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.

© 2014-2024 Faster IT GmbH | imprint | privacy policy