Commit Graph

56 Commits

Author SHA1 Message Date
Daniel Lange 711a7aacb0 Tiny cleanup from review comments 2021-08-23 14:50:46 +02:00
Christian Göttsche 9060a4179d Add option to change Header layout 2021-08-22 16:15:59 +02:00
Christian Göttsche 796bc36fe0 Add assert to improve backtraces on NULL function pointer 2021-08-10 21:26:50 +02:00
Nathan Scott bf853addc3 Ensure PCP dynamic metric configuration definition uniqueness
It can happen that pcp-htop is presented multiple definitions
of the same dynamic meter, e.g. if /etc/pcp/htop/meters has a
definition matching one in ~/.config/htop/meters - instead of
exiting with a duplicate metric error provide more meaningful
diagnostics (on close) and also just skip over such entries.
System files override home directories which overrides those
found below the current working directory.

Also fix the derived metric error diagnostic; because this is
using CRT_fatalError, which is like perror(3), we must give a
meaningful prefix (like program name) at the string end.
2021-07-14 11:58:46 +10:00
Nathan Scott a476490282 Ensure we do not attempt to add a DynamicMeter via the
htoprc that we didn't find during start up.  This just
leaves blank sections of the display as @smalinux found.

Related to https://github.com/htop-dev/htop/pull/682
2021-07-14 11:58:31 +10:00
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
Christian Göttsche a11d01568c Use unsigned types for CPU counts and associated variables 2021-03-19 23:30:54 +01:00
Christian Göttsche b862e36ee7 Separate data-update and drawing of header 2021-03-04 23:57:45 +01:00
Daniel Lange b612256486 Leave less right margin next to long (text) meters 2021-02-02 11:07:29 +01:00
Christian Göttsche 3035e29e74 Use typedef names instead of raw struct ones 2021-01-26 21:16:23 +01:00
Christian Göttsche 2ec44098f9 Allow meters in text mode to span empty neighbors to the right
Closes: #484
2021-01-23 15:20:47 +01:00
Christian Göttsche d72b0a682e Mark several non-modified pointer variables const 2021-01-11 20:12:34 +01:00
Christian Göttsche 3d15ba5197 Remove unused function Header_readMeterName 2020-12-06 16:03:25 +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
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 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 ba282cfe19 Mark Object instances 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
Hugo Musso Gualandi 9207401f97 Clean up some code duplication in the header files
PR htop-dev/htop#70 got rid of the infrastructure for generating header
files, but it left behind some code duplication.

Some of cases are things that belong in the header file and don't need
to be repeated in the C file. Other cases are things that belong in the
C file and don't need to be in the header file.

In this commit I tried to fix all of these that I could find. When given
a choice I preferred keeping things out of the header file, unless they
were being used by someone else.
2020-09-12 19:20:44 -03:00
Nathan Scott c5808c56db Consolidate repeated macro definitions into one header
The MIN, MAX, CLAMP, MINIMUM, and MAXIMUM macros appear
throughout the codebase with many re-definitions.  Make
a single copy of each in a common header file, and use
the BSD variants of MINIMUM/MAXIMUM due to conflicts in
the system <sys/param.h> headers.
2020-09-09 16:56:04 +10:00
Zev Weiss a1a027b9bd Axe automated header generation.
Reasoning:
 - implementation was unsound -- broke down when I added a fairly
   basic macro definition expanding to a struct initializer in a *.c
   file.

 - made it way too easy (e.g. via otherwise totally innocuous git
   commands) to end up with timestamps such that it always ran
   MakeHeader.py but never used its output, leading to overbuild noise
   when running what should be a null 'make'.

 - but mostly: it's just an awkward way of dealing with C code.
2020-09-03 11:58:58 -05:00
Christian Göttsche 21fb56e1e2 Avoid string overflow warning
Enough memory is allocated.

    Header.c: In function ‘Header_readMeterName’:
    Header.c:157:4: error: ‘strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
      157 |    strncpy(name, Meter_name(meter), nameLen);
          |    ^
    Header.c:154:18: note: length computed here
      154 |    int nameLen = strlen(Meter_name(meter));
          |                  ^
2020-08-25 11:59:59 +02:00
Nathan Scott a82fd262d7 Merge branch 'hishamhm-pull-960' 2020-08-20 14:19:53 +10:00
Daniel Flanagan dd33444f7e Clean up existing whitespace 2019-10-31 11:39:12 -05:00
wangqr 6f161e60e1 Restore meter name after used in Header_addMeterByName()
Fix #852
2019-02-12 22:13:58 -05:00
Hisham Muhammad 09e241fb12 Security review: check results of snprintf.
Calls marked with xSnprintf shouldn't fail.
Abort program cleanly if any of them does.
2017-07-27 16:07:50 -03:00
Explorer09 54621e8b8f Fix macro Header_forEachColumn
The (this_) token was not expanded properly, but the bug was not caught
because all uses of this macro specifies (this_)=this .

Also parenthesize macro tokens to prevent further problems.
2016-05-07 14:57:51 +08:00
Hisham b54d2dde40 Check for failure in allocations. 2016-02-02 15:53:02 +01:00
Christian Hesse e8970b6f32 fix calloc() calls
* size_t nmemb (number of elements) first, then size_t size
* do not assume char is size 1 but use sizeof()
* allocate for char, not pointer to char (found by Michael McConville,
  fixes #261)
2015-09-07 07:52:39 +02:00
David Hunt 5e602f18d5 Rename String to StringUtils.
Fixes building on case-insensitive filesystems where String.h gets confused with <string.h>.

From d734dacea0a10d0465dad4e95b3421511e7da112 Mon Sep 17 00:00:00 2001
From: David Hunt <dhunt@iolanthe.attlocal.net>
Date: Sat, 11 Jul 2015 20:56:31 -0500
Subject: [PATCH 1/8] Rename String to StringUtils
2015-08-19 13:45:20 -03:00
Christian Hesse a804f1f848 write header length (number of columns) back to configuration 2015-06-12 01:35:12 +02:00
Hisham Muhammad 9ff5d2b243 Fix saving of header states, motion in Setup screen. 2015-03-16 23:01:21 -03:00
Hisham Muhammad c2108e5a48 Another mega-patch for the refactoring process.
Kinda runs, but functionality from the original main loop
is still missing. Patience.
2015-01-23 03:08:21 -02:00
Hisham Muhammad 3383d8e556 Sorry about the mega-patch.
This is a work-in-progress, code is currently broken.
(Some actions, and notably, the header, are missing.)
2015-01-21 23:27:31 -02:00
Hisham Muhammad 357e7a3243 Move UptimeMeter into platform-dependent area.
Set up environment to move other meters.
2014-11-27 19:18:14 -02:00
Hisham Muhammad b192af006f Decouple Header from Meter classes.
(Yes, that's dynamic typing!)
2014-11-27 18:38:52 -02:00
Hisham Muhammad f239b62b90 Restrict size of read. 2014-04-21 19:18:08 -03:00
Hisham Muhammad 6d90e58c01 alignment improvements 2014-02-27 16:35:22 -03:00
Hisham Muhammad 76a715ee8c Fix order of calloc arguments.
(Patch by Dawid Gajownik)
2014-01-16 18:51:16 -02:00
Hisham Muhammad 00b324bfc1 Changes in object model: separate class objects to store vtable. Also, nicer UTF-8 display of big numbers. 2012-12-05 15:12:20 +00:00
Hisham Muhammad 45f7a4fc8d Remove old memory debugging routines. We have Valgrind nowadays. 2011-12-26 22:04:29 +00:00
Hisham Muhammad 84281bdc44 major header cleanup 2011-12-26 21:35:57 +00:00
Hisham Muhammad 7ca1081712 Mega-commit with features and tweaks for 1.0:
* Performance improvements
* Support for splitting CPU meters into two or four columns
  (thanks to Wim Heirman)
* Switch from PLPA, which is now deprecated, to HWLOC.
* Bring back support for native Linux sched_setaffinity,
  so we don't have to use HWLOC where we don't need to.
* Support for typing in user names and column fields in selection panels.
2011-11-18 06:08:56 +00:00
Hisham Muhammad 300caa076e Tempus fugit. 2011-05-26 16:35:07 +00:00
Hisham Muhammad b57b7e9a9e only reinit initializable meters 2011-03-29 15:02:46 +00:00
Hisham Muhammad a9c0ea3753 * Option for counting CPUs from zero
(thanks to Sean Noonan)
* Meters update in every screen (no longer halting while on Setup, etc.)
2011-03-22 20:37:08 +00:00
Hisham Muhammad a600d5a6e9 Tempus fugit. 2010-02-25 02:08:18 +00:00
Hisham Muhammad 807df03671 Avoid crashing when using many meters (thanks to David Cho for the report) 2007-11-26 22:06:25 +00:00