Commit Graph

43 Commits

Author SHA1 Message Date
Daniel Lange
94ad111391 Update license headers to explicitly say GPLv2+ 2021-09-22 14:28:19 +02:00
Explorer09
2d1b6f4783 TasksMeter: save some float casts
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
2021-08-14 11:16:03 +02:00
Christian Göttsche
41af31be7f Rework CPU counting
Currently htop does not support offline CPUs and hot-swapping, e.g. via
    echo 0 > /sys/devices/system/cpu/cpu2/online

Split the current single cpuCount variable into activeCPUs and
existingCPUs.

Supersedes: #650
Related: #580
2021-07-18 07:44:02 +02:00
Christian Göttsche
436808ff99 Use RichString_appendnAscii where possible
`RichString_appendnAscii()` avoids a `strlen(3)` call over
` RichString_appendAscii()`.
Use the former where the length is available from a previous checked
`snprintf(3)` call.

Keep `RichString_appendAscii()` when passing a string literal and
rely on compilers to optimize the `strlen(3)` call away.
2021-04-26 17:51:45 +02:00
Christian Göttsche
8163b8164f TaskMeter: always show number of threads
Always show the number of kernel and userland threads, even when they
are disabled to not be shown in the process list.

The data is already available and might improve understanding the system
utilization.

Use a shadow color in case the kind of thread is hidden, else the normal
meter one.
2021-03-31 00:27:14 +02:00
Christian Göttsche
2d1042adb3 Save text buffer in Meter 2021-03-04 23:57:45 +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
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
72103e9613 Hold only a const version of the ProcessList in Meters 2020-10-26 19:30:38 +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
Benny Baumann
c6f04a9c5d Move xAsprintf, xSnprintf and xStrdup to StringUtils.h 2020-10-16 20:29:45 +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
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
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
Nathan Scott
a82fd262d7 Merge branch 'hishamhm-pull-960' 2020-08-20 14:19:53 +10:00
Nathan Scott
b30c22d687 Merge branch 'hishamhm-pull-914' 2020-08-20 14:09:27 +10:00
Daniel Flanagan
dd33444f7e Clean up existing whitespace 2019-10-31 11:39:12 -05:00
senjan
01a1cc063f fixed Linux build 2019-05-30 16:34:30 +02:00
Lucas C. Villa Real
ad99187680 htop scans /proc to determine how many running tasks exist. Since that
operation is not possible to be conducted in an atomic fashion, task
scheduling effects can lead to a count greater than the number of actual
processors; this is more easily noticed on machines with several CPUs
and under heavy workload.
This patch simply adds an upper bound on cpuCount to guarantee
consistent reports of the number of running tasks at any given time.
2018-01-23 14:11:47 -02: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
Tomasz Kramkowski
2b5c1b4b13 Replace all uses of sprintf with snprintf
In all the cases where sprintf was being used within htop, snprintf
could have been used. This patch replaces all uses of sprintf with
snprintf which makes sure that if a buffer is too small to hold the
resulting string, the string is simply cut short instead of causing
a buffer overflow which leads to undefined behaviour.

`sizeof(variable)` was used in these cases, as opposed to `sizeof
variable` which is my personal preference because `sizeof(variable)`
was already used in one way or another in other parts of the code.
2016-12-29 19:42:41 +01:00
Explorer09
9dea20e068 Rename Meter.setValues() functions to updateValues()
Rationale (copied from htop issue #471):
The function name "setValues" is misleading. For most OOP (object-
oriented programming) contexts, setXXX functions mean they will change
some member variables of an object into something specified in
function arguments. But in the *Meter_setValues() case, the new values
are not from the arguments, but from a hard-coded source. The caller
is not supposed to change the values[] to anything it likes, but
rather to "update" the values from the source. Hence, updateValues is
a better name for this family of functions.
2016-05-04 13:39:26 +08:00
Explorer09
99fb3070a2 Explicit "maxItems" property of meters
Two changes in this commit:
- All meters now explicitly specify "maxItems" property, even for just
  1 item. (Exception is "container" CPU meter classes, which use
  CUSTOM_METERMODE.)
- "maxItems" being 0 is now allowed. This will let bar meters and graph
  meters render an empty meter.
2016-03-11 10:54:34 +08:00
Hisham Muhammad
272e2d9b34 Major advances in FreeBSD port. 2015-03-16 23:02:03 -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
c1e0f6e17c BUGFIX: Fix crash when adding meters and toggling detailed CPU time.
See https://bugzilla.redhat.com/show_bug.cgi?id=987805 for details.
(thanks to Dawid Gajownik for the detailed analysis!)
2014-01-16 01:40:47 -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
300caa076e Tempus fugit. 2011-05-26 16:35:07 +00:00
Hisham Muhammad
831538b0f9 Split process and thread counts in tasks meter 2010-11-23 13:28:47 +00:00
Hisham Muhammad
d8e1480a27 Remove arbitrary limit from rich strings
Fix subtree hiding
Fix reading of CPU values in hidden threads
Fix hiding of zombie processes as kernel threads
Remove "debug proc" code
Code cleanup in processElements
2010-11-22 12:40:20 +00:00
Hisham Muhammad
a600d5a6e9 Tempus fugit. 2010-02-25 02:08:18 +00:00
Hisham Muhammad
da23c8c5a1 Clean up headers by using 'static' whenever possible.
Reduces resulting code size.
2008-03-09 08:58:38 +00:00
Hisham Muhammad
dbe2670b69 Perform RichString operations by hand.
Avoid unnecessary operations when processing entries on ProcessList.
2006-07-12 01:16:03 +00:00
Hisham Muhammad
2f1f82ee87 Updates for new version of the MakeHeader.py script. 2006-06-06 20:41:01 +00:00
Hisham Muhammad
33113fe0d7 - Overhaul meters implementation;
- add AllCPUsMeter;
- because of that, the new .htoprc is incompatible with previous released versions.
2006-04-10 20:40:38 +00:00
Hisham Muhammad
d6231bab89 Initial import. 2006-03-04 18:16:49 +00:00