Commit Graph

62 Commits

Author SHA1 Message Date
Benny Baumann edf319e53d Auto-size (normalized) CPU usage columns 2022-03-06 19:56:25 +01:00
Charlie Vieth d35db47c9a darwin: lazily set process TTY name
Fetching the TTY name of a process is extremely expensive on darwin and
the call to devname accounts for 95% of htop's CPU usage when there is
high process turnover (this is mostly due to devname calling lstat,
which is incredibly slow). This can make htop unresponsive.

To mitigate this only set the process TTY name if the it is being
actively displayed (PROCESS_FLAG_TTY), which by default it is not
on darwin.
2022-02-18 09:07:41 +01:00
Hisham Muhammad 72ba20fa5f Introduce screen tabs
This is a forward port (by nathans) of Hisham's original code.
2021-12-07 17:04:49 +11:00
marcluque d8dfbbd37c Tidy up process state handling 2021-11-02 20:02:54 +01:00
Silke Hofstra 696f79fe50 Dynamically scale the ST_UID size to support 32-bit UIDs
While most Unix-like systems use 16-bit user IDs,
Linux supports 32-bit UIDs since version 2.6.
UIDs above 65535 are used for UID namespacing of containers,
where a container has its own set of 16-bit user IDs.
Processes in such containers will have (much) larger UIDs than 65535.

Because the current format strings for `ST_UID` and `USER`
are `%5d` and `%9d` respectively, processes with such UIDs
lead to misaligned columns.

Dynamically scale the `ST_UID` column and increase the size of `USER`
to 10 characters (length of UINT32_MAX) to ensure that the user ID always fits.

Additionally: clean up how the titlebuffer size calculation and ensure
the PID column has a minimum size of 5.
2021-10-27 21:20:59 +02:00
Benny Baumann 57c1538887 Don't force allocation, as failure is handled 2021-10-03 19:18:25 +02:00
Daniel Lange 94ad111391 Update license headers to explicitly say GPLv2+ 2021-09-22 14:28:19 +02:00
Christian Göttsche 80a515abcc Fix typo 2021-09-18 15:55:21 +02:00
Alexander Momchilov 59d0c5b26a Refactor Darwin platform unit conversion helpers 2021-08-25 11:55:05 -04:00
Alexander Momchilov 7a4d6fa409 Style touch-ups 2021-08-23 10:37:49 -04:00
Alexander Momchilov 5b4d63d1be Fix macOS CPU time calculations 2021-08-23 10:37:49 -04:00
Benny Baumann 6a6b09b431 Darwin: Always update username 2021-06-22 09:32:11 +02:00
Benny Baumann 06073699ba Darwin: Implement CWD column 2021-05-25 21:55:04 +02:00
Christian Göttsche 550a141860 Add ELAPSED process column
Add process columns showing the elapsed time since the process was
started.
Similar to STARTTIME, but shows the time passed since the process start
instead of the fixed start time of the process.

Closes https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=782636
2021-05-23 15:43:23 +02:00
Christian Göttsche 8ff4eb72ac Darwin: use merged command line helpers 2021-05-23 09:22:21 +02:00
Benny Baumann a61a2e6d47 Call makeCommandStr on all platforms 2021-05-23 09:22:21 +02:00
Benny Baumann 7224d0e083 Move kernel/userland thread handling to platform-independent implementation 2021-05-23 09:22:21 +02:00
Benny Baumann 94a52cb5c9 Rename cmdlineBasenameOffset to cmdlineBasenameEnd to properly indicate the fields purpose 2021-05-23 09:22:21 +02:00
Benny Baumann b839987df7 Rename basenameOffset to cmdlineBasenameOffset 2021-05-23 09:22:21 +02:00
Benny Baumann 02431c43e1 Rename command line field from comm to cmdline 2021-05-23 09:22:21 +02:00
mayurdahibhate 3f86a011e6 platform-dependent files included relative to main source directory 2021-05-10 18:40:53 +02:00
Christian Göttsche 9a8221568a Rework TTY column
* Rename internal identifier from TTY_NR to just TTY
* Unify column header on platforms
* Use devname(3) on BSD derivate to show the actual terminal,
  simplifies current FreeBSD implementation.
* Use 'unsigned long int' as id type, to fit dev_t on Linux.

Only on Solaris the terminal path is not yet resolved.
2021-04-14 17:29:56 +02:00
Christian Göttsche 4f9cf1490f Darwin: add normalized CPU percentage column
Missed in 15eab2012d
2021-03-03 08:43:45 +01:00
Daniel Lange 4531b31d92 Sort out the mess around column sorting that had accumulated over time 2021-01-21 14:27:23 +01:00
Christian Göttsche 90ea3ac3c9 Object: return int on comparison
Comparisons do, due to the new introduced shaceship-comparisons,
only return -1, 0, 1 or the result of strcmp().
2021-01-02 00:00:17 +01:00
Benny Baumann 4a73e80338 Make remaining number literals use uppercase 2020-12-20 17:17:51 +01:00
Alexander Momchilov 67ccd6b909 Unhardcode tick-to-ms conversion
Division by 100000.0 worked because `sysconf(_SC_CLK_TCK)` happened to be 100.

By unhardcoding:

1) It becomes more clear what this 100000.0 figure comes from.
2) It protects against bugs in the case `sysconf(_SC_CLK_TCK)` ever changes.
2020-12-19 21:30:39 +01:00
Christian Göttsche 9f68c8d341 Merge Process_pidColumns into Process_fields and rework auto-fit for PID-like columns 2020-12-19 21:13:32 +01:00
Christian Göttsche 89473cc9ae Rework enum ProcessField
Use only one enum instead of a global and a platform specific one.
Drop Platform_numberOfFields global variable.
Set known size of Process_fields array
2020-12-19 21:13:32 +01:00
Benny Baumann 77db240b48 Split boilerplate and platform-independent field comparison
This acheives two things:
- Allows for simple tie-breaking if values compare equal (needed to make sorting the tree-view stable)
- Allows for platform-dependent overriding of the sort-order for specific fields

Also fixes a small oversight on DragonFlyBSD when default-sorting.
2020-12-19 16:02:34 +01:00
Hisham Muhammad 3d1703f16f Invert Process_compare resolution so that superclass matches run first
* This removes duplicated code that adjusts the sort direction from every
  OS-specific folder.
* Most fields in a regular htop screen are OS-independent, so trying
  Process_compare first and only falling back to the OS-specific
  compareByKey function if it's an OS-specific field makes sense.
* This will allow us to override the sortKey in a global way without having
  to edit each OS-specific file.
2020-12-19 16:02:34 +01:00
Daniel Lange 4b1a4a4ebd Merge branch 'fix_mach_timebase' of benbe/htop 2020-12-13 20:02:38 +01:00
Dániel Bakai 3655b6ca0b Add column in darwin to indicate whether the the process is running under translation 2020-12-13 17:58:16 +01:00
Dániel Bakai 1506283aff Move Process_fields from darwin/Platform to darwin/DarwinProcess 2020-12-13 17:58:16 +01:00
Benny Baumann f32f0188cd Correct timebase for non-x86 CPUs on Darwin
Fixes: #368
2020-12-13 11:47:34 +01:00
Nathan Scott 75e9f9a8d9 Cull the definitions of pageSize and pageSizeKB from CRT.c
By storing the per-process m_resident and m_virt values in the form
htop wants to display them in (KB, not pages), we no longer need to
have definitions of pageSize and pageSizeKB in the common CRT code.

These variables were never really CRT (i.e. display) related in the
first place.  It turns out the darwin platform code doesn't need to
use these at all (the process values are extracted from the kernel
in bytes not pages) and the other platforms can each use their own
local pagesize variables, in more appropriate locations.

Some platforms were actually already doing this, so this change is
removing duplication of logic and variables there.
2020-12-10 11:57:48 +11:00
Christian Göttsche fa002c0ba9 Rename virtual memory column from M_SIZE to M_VIRT
Closes: #325
2020-11-21 19:39:45 +01:00
Christian Göttsche ba2d59020d DarwinProcess: mark local function static and sort includes 2020-11-17 21:50:38 +01:00
Benny Baumann 61e14d4bb2 Spacing around operators 2020-11-02 22:15:01 +01:00
Benny Baumann b23f8235e2 Whitespace and indentation issues 2020-11-02 22:15:01 +01:00
Benny Baumann 374edb9ed5 Spacing after keywords (if) 2020-11-02 22:14:59 +01:00
Christian Göttsche 4eb443926f Hold only a const version of Settings in Process 2020-10-26 19:30:38 +01:00
Christian Göttsche 361877454f Cache PAGE_SIZE
man:sysconf(3) states:
    The values obtained from these functions are system configuration constants.
    They do not change during the lifetime of a process.
2020-10-19 14:42:35 +02:00
Christian Göttsche a63cfc8b7c Refactor generating starttime string into Process class 2020-10-16 19:23:40 +02:00
Christian Göttsche 7af06659e2 Mark remaining classes const 2020-10-13 14:56:01 +02:00
Christian Göttsche 41eea8a355 Mark process argument of Process_isThread const 2020-10-09 10:18:40 +02:00
Daniel Lange 079c2abf8e Update License consistently to GPLv2 as per COPYING file 2020-10-05 10:13:12 +02: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
Daniel Flanagan dd33444f7e Clean up existing whitespace 2019-10-31 11:39:12 -05:00
Hisham d64f2bdd56 If task_for_pid fails, stop trying. 2016-03-31 00:18:42 -03:00