-
-
Notifications
You must be signed in to change notification settings - Fork 441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Highlight new and old processes (#74) #241
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General change requests:
- This should also be a setting in the setup menu
- This should highlight the whole line like the search bar and the current process and not only the length of the text
Please also document the command line flag (preferably -H, see above) in the main page (htop.1.in
).
@fasterit @BenBE Thanks for the review. I addressed most of the review comments in cf1f9a7. Remaining work:
The first three will take some refactoring I think. Pausing here for review. |
What's the difference between the global ProcessList_scanTs and the scanTs value in the ProcessList structure? |
Congratulations 🎉. DeepCode analyzed your code in 1.65 seconds and we found no issues. Enjoy a moment of no bugs ☀️. 👉 View analysis in DeepCode’s Dashboard | Configure the bot |
I removed the global in 7caabfc. |
Hello. Can someone add a |
What is the status of these? I.e. why don't you finish the PR so we can merge it? |
This is resolved by 7caabfc.
I can add this if you'd like.
I believe these should be tracked in separate issues as they require heavier refactoring. |
Please do.
That doesn't make sense as we won't merge it as is. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While testing the branch recently I noticed the highlighted line markup doesn't reach the end of the line. This is kinda irritating. Also with 5 seconds it feels kinda hectic, thus having a configuration for this would be nice.
Apart from this, this PR should be rebased onto current master to resolve the merge conflicts..
Still working on this @adsr? Need any help? |
The flag is now Also rebased and resolved conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, thank you very much @adsr.
Just as a comment:
As we save --delay
values in htoprc
and not allow setting them via the setup GUI, this seems fine for --highlight-changes
as well.
Medium term we may want a setup screen for these numeric values as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small issues I noticed:
- Thombstones are shown for threads even when threads are hidden
- Minor code issues
Future PRs could also include:
- Scrolling right on a thumbstone still shows the issue with the incomplete line markup (this seems to be a general issue with h-scrolling though).
- Would be nice to have a key mapping (
C
???) to quickly enable/disable at runtime
I maybe found a nice way around your firstScanTs
issue: If you manage to get the scanTs
for the first process list scan set to 0 you should be fine (htop does one scan which is AFAIR never displayed). Would allow to remove the firstScanTs
field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
The idea is basically to use the first process scan of htop (which never gets displayed AFAIR) to set all pre-existing processes to a timestamp far in the past. The first regular scan then uses just the normal timestamps. Each process that existed in the first scan would then have a scanTs so small, that it is considered not changed. Suggestion for a patch: diff --git a/ProcessList.c b/ProcessList.c
index 364de1e..8b244df 100644
--- a/ProcessList.c
+++ b/ProcessList.c
@@ -29,7 +29,6 @@ ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, Users
this->cpuCount = 0;
this->scanTs = 0;
- this->firstScanTs = 0;
#ifdef HAVE_LIBHWLOC
this->topologyOk = false;
@@ -87,12 +86,8 @@ void ProcessList_add(ProcessList* this, Process* p) {
assert(Hashtable_get(this->processTable, p->pid) == NULL);
p->processList = this;
- if (this->scanTs == this->firstScanTs) {
- // prevent highlighting processes found in first scan
- p->seenTs = this->firstScanTs - this->settings->highlightDelaySecs - 1;
- } else {
- p->seenTs = this->scanTs;
- }
+ // highlighting processes found in first scan by first scan marked "far in the past"
+ p->seenTs = this->scanTs;
Vector_add(this->processes, p);
Hashtable_put(this->processTable, p->pid, p);
@@ -318,10 +313,11 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) {
// set scanTs
- if (clock_gettime(CLOCK_MONOTONIC, &now) == 0) {
- if (this->firstScanTs == 0) {
- this->firstScanTs = now.tv_sec;
- }
+ static bool firstScanDone = false;
+ if (!firstScanDone) {
+ this->scanTs = 0;
+ firstScanDone = true;
+ } else if (clock_gettime(CLOCK_MONOTONIC, &now) == 0) {
this->scanTs = now.tv_sec;
}
diff --git a/ProcessList.h b/ProcessList.h
index db0549a..3e35130 100644
--- a/ProcessList.h
+++ b/ProcessList.h
@@ -71,7 +71,6 @@ typedef struct ProcessList_ {
int cpuCount;
time_t scanTs;
- time_t firstScanTs;
} ProcessList;
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); |
Adam Saponara (2): Highlight new and old processes (#74) Address items from review Bart Joy (1): Add screen shot of htop to readme Benny Baumann (100): Barely ever seen any 1000 digit PIDs … Properly close pipe handles when work is done Avoid hardcoding of buffer size Enhance highlighting of semi-large and large numbers Fix minor regression in number highlighting Update battery API to use NAN on error Update IO rate display to use NAN on error Properly query sysconf settting and use NAN if unavailable Use threshold for display of guest/steal/irq meters Update CPU freq display to use NAN on error Update delay accounting to use NAN on error Add -Wfloat-equal to default build flags Use return value of CLAMP function Reimplement xAsnprintf and xSnprintf as type-safe functions Cleanse xStrdup mess Fix FreeBSD compile issue Sort headers/includes Enable NULL pointer checks via compiler if supported Use memmove for Vector_take Replace copy loop by memmove in Vector_insert Handle parsing envID & VPid from process status file Some more locations for ARRAYSIZE Add conf*/ and callgrind.out.* to list of ignored files Centralise fault handling Keep building on errors Move xAsprintf, xSnprintf and xStrdup to StringUtils.h Rename StringUtils.[ch] to XUtils.[ch] Combine XAlloc.[ch] into XUtils.[ch] Release old memory on error Fix misaligned access inside taskstats structure Fix various file descriptor leaks Ensure full initialization of all fields Provide basic configuration for IWYU Make all required includes explicit Refactor code for reading process environment from procfs Refactor LinuxProcessList_readSmapsFile to work line-oriented Documentation on the repository style guide Remove unnecessary trailing semicolon on macros Remove accidental syntax collision Convert addattrstr to static inline function Spacing after keywords (#define) Spacing after keywords (while) Spacing after keywords (if) Spacing after keywords (for) Fix indentation to 3 spaces Make scope of match macro symmetric Whitespace and indentation issues Spacing around operators Embracing branches Wrap inline structure definitions Avoid RichString_beginAllocated being ammendable Shorten initializer Integrate NAN check into assignment Remove unnecessary braces Add compat wrapper for readlinkat Split platform dependent parts for file locks screen Split data array for file lock information into separate fields Avoid calling Object_isA from inside Vector_isConsistent Remove unnecessary parens Fix build for custom make targets Fix NULL pointer dereference on kstat_lookup failure Reduce scope of totaltime No need to check for change when no action is required Simplify code flow by inlining declarations where they are used Reduce scope of local variables Reduce scope of cached values Compatibility function for faccessat Add heuristic for space-separated cmdline Reduce visual noise to when comm and cmdline actually disagree on the program basename Minor indentation fix Make kernel thread display for COMM/EXE columns less visible and more consistent Refactor command string creation Group the "Merge Command" related options visually Include comm before cmdline if exe could not be read, but comm mismatches basename from cmdline Only calculate M_LRS size every 5 seconds Hardcode actual conversions to read the maps file data Roll our own strtoull implementation specialized to handle the parsing requirements Distinguish display of no permissions for reading M_LRS Randomly refresh M_LRS calculation, but latest after 2s Make casing of N/A consistent (majority was N/A) Use 'N/A' instead of 'no perm' for more consistency Include documentation for COMM and EXE Typo fix in docs Implement Hashtable_clear to empty an existing Hashtable Use common values for initial size estimates for Hashtables Code style cleanup and documentation/comments Reorder field initialization to group fields by task Avoid useless search for pid 0 Avoid expensive build of tree when not using it Some minor spelling issues Minor code streamlining Common order for ESC/q/F10 Reduce code duplication Use common handling for scrolling Some visual code cleanup Handle 'q' as quit if first character Allow to pass '/' for item search Document implicit incremental search Some minor additions to the changelog Initialize buffer for retrieved path Christian Goettsche (4): FreeBSD: rework tty process column FreeBSD: implement Platform_getDiskIO() IWYU update (FreeBSD) FreeBSD: fix crash on empty environment Christian Göttsche (217): Avoid potential buffer overflow in LinuxProcessList_readStatFile Check for fdopen failure in OpenFilesScreen_getProcessData Use PROCDIR throughout instead of /proc on Linux autotools: enable warnings and cleanup Reorder check to avoid crash on invalid process field setting Add Linux process column for context switches Avoid unsigned integer overflow Allow third party sigsegv handler Avoid modifying optarg Call character checking function with unsigned char Free movingBar memory on exit Fix memory leak in actionSetAffinity() Add script to run htop under valgrind Drop unused variable Convert short version option to capital V Sort option in help message Add some default compiler warnings Refactor __attribute__ usage Use strict function prototypes Avoid checking of undefined macros Mark noreturn functions Resolve unused variable on FreeBSD Fail travis CI on compiler warnings Add format attribute Fix memory leak on cgroup read failure Use checked allocation wrappers Avoid arithmetic on booleans Drop dead code after break Drop dead process fields Avoid unsigned integer overflow Make --enable-hwloc and --enable-linux-affinity mutual exclusive Add DeepCode inline suppression Add DeepCode inline suppression Read CPU frequency from sysfs by default Drop unused macros Include prototype in Battery implementation Drop unnecessary usage of comma operator Avoid bad function cast warning Avoid warning about unreachable break statement Do not drop qualifier in cast Add -Wmissing-prototypes compiler warning Drop redundant casts to the same type Covert Meter attributes to file-local constant arrays Drop redundant return statements Drop redundant declarations InfoScreen: update content on resize Adjust colors Add security attribute process column Add DiskIOMeter for IO read/write usage Add --enable-debug configure option to enable asserts Resolve DEBUG compilation issues Add clang analyzer CI job Introduce ARRAYSIZE Assert that low value is lower than the high value in CLAMP Merge identical declarations Mark argument in Object_isA const Mention platform for platform specific configure options DateMeter followup Handle Panel_getSelected() returning NULL Enable -Wcast-qual compiler warning Enclose CLAMP macro arguments in parentheses Drop redundant cast to same type Simplify statm parsing and document unused fields Mark Object classes and Object class fields const Mark Object instances const Mark process argument of Process_isThread const Makefile sort correction Mark Object pointer to _display function const OpenFilesScreen update Compress size of default FunctionBar Add key to pause process list updates Read CPU count every cycle to avoid issues when HT/SMT mode changes Meter: use explicit type for drawData CPUMeter: avoid crashes and leaks in case the CPU count changes Settings: do not save initial cpu count Mark remaining classes const Enclose macro argument in parentheses Misc CRT cleanup Do not hard-code line numbers in help screen building code Mark search parameter in Vector_indexOf const Keep building on errors Mark Vector parameter const for non-modifying functions Automatically detect if backtrace(3) needs -lexecinfo Misc conversion fixes Add SELinuxMeter Do not use extra starttime process field on Linux Refactor generating starttime string into Process class Misc Vector updates Generalize Meter value colors for IO Add NetworkIOMeter Allow low and high value of CLAMP to be equal Cache PAGE_SIZE Continue to update generic data in paused mode Assert allocating non-zero size memory XUtils string related updates Drop tabs in source indentions update Github CI IWYU update Increase print buffer in NetworkIOMeter_display Drop unnecessary cast Fix wrong strncmp replacement Drop unused Platform functions Platform_setTasksValues Mark user field of Process const Improve handling of no data in Disk and Network IO Meters Hold only a const version of the ProcessList in Meters Mark process parameter of Process_writeField consistently const Hold only a const version of Settings in Process Hold only a const version of Settings in ProcessList Drop duplicate and always true condition Drop unneeded variablw initialization and reduce scope Avoid some unnecessary casts and mark some not changing variables const Drop always true condition Drop duplicate assignment Unify function argument names Enclose macro arguments in parentheses Implement RichString_setLen as function Implement IncSet_filter as function Implement LinuxProcess_effectiveIOPriority as function Implement Process_isUserlandThread as function Implement Process_getParentPid and Process_isChildOf as functions Simplify RichString_begin Small ListItem update Add HTOP_$platform defines to config.h header FreeBSD: Platform update FreeBSD: update ProcessList FreeBSD: update Process Add compat wrapper for fstatat Use integer type for item count instead of char Add SystemdMeter Enclose macro arguments in parentheses Handle data wraparounds in IO Meters Assert Vector_get returns an object Fixup of SystemdMeter merge Introduce spaceship comparison for Processes Use uid_t type for Process_getuid Mark ProcessList_keyAt argument const Mark local functions static Drop hideThreads Setting Early skip non-directories when searching for process information Use spaceship comparison for TTYs Show CPU temperature in CPU meter Add process column for normalized CPU usage Hashtable update Hashtable: use dynamic growth and use primes as size Silence theoretical memory leak Use 0 as no-match value for sortkey DarwinProcess: mark local function static and sort includes DarwinProcessList: mark local functions static and sort includes Align command line argument descriptions in help output Spelling corrections IWYU update (Linux) fix indent LinuxProcess: mark LinuxProcess_printDelay static Rename virtual memory column from M_SIZE to M_VIRT Simplify page size related calculations Object: assert callbacks exists LinuxProcessList: skip parsing threads if the kind of thread is disabled Linux: fix display of new thread for one cycle when hidden DarwinProcessList: retry getting list of all processes on ENOMEM LinuxProcessList: fix misspelling LinuxProcess_adjustTime: simplify by not using double Fix file descriptor leak in LinuxProcessList_readCmdlineFile after xread failure ProcessLocksScreen_draw: use Process_getCommand instead of raw comm Improve Fahrenheit temperature configuration text Unify naming of first argument of Platform_getBattery LinuxProcessList: fix misspelling Fully support non-ascii characters in Meter-Bar Add support to change numeric options in settings screen Drop cgroup conditional Drop taskstats conditional Track file descriptors in valgrind script LinuxProcessList_recurseProcTree: compute time only once and mark parent const Fix crash when getCommandStr not overloaded for a platform process configure: create typedefs for fixed-sized integers if needed IOPriorityPanel: drop unnecessary buffer size decrement LinuxProcessList: use openat instead of building path strings Add compat mode for systems without openat(2) configure: do not check functions we are using unconditionally Update even more snprintfs Hide process selection on ESC Typo Linux: fix process parsing for hidden pid directories Print G in gigabyte color Use enum element name instead of magic number Compare indices not index with pair Drop redundant return statements Merge identical conditional branches Add cast to unsigned char to avoid signed char misuse Use String_eq for readability and consistency Meter: document MeterClass string fields PressureStallMeter: improve display strings Add xReadfile wrapper for reading small to medium size files Dynamically load libsensors at runtime Set locale only once and do not override it later Add Linux cwd process column Silence possible NULL dereference Linux: avoid float division by 0 after system sleep ci: use correct configure flags for sensors ci: use clang-11 Fix sensors configure argument Convert personal copyright authorship to team Resolve conversion from ssize_t to int for readlink return value Resolve conversion from int to short Resolve conversion from int to unsigned and back Resolve conversion from int to char Hide degree character without wide ncurses support RichString: avoid signed integer misuse Meter: fix bar coloring without wide ncurses support LinuxProcessList: add underscore suffix for raw struct name DragonFlyBSDProcessList: fix missing type IWYU update Remove unused function Header_readMeterName Use size_t as len type for xSnprintf Use size_t as len type for Meter_UpdateValues Use size_t as type for buffer length in Process Introduce METER_BUFFER_CHECK and METER_BUFFER_APPEND_CHR to cleanup writing to bar buffers OpenBSD update Christian Hesse (1): align cpu id to right Daniel Lange (16): Update README with correct tarball locations, ncurses hints and support / bug reporting pointers. Update creation date to 2004 (thanks rubyFeedback) Update copyright statement Update License consistently to GPLv2 as per COPYING file Add Copyright statement to --help (needed as it has the license info) Set a -dev version to bug reports show a useful version and not the last release Remove duplicate test for NUL Apply patch from BenBE as per htop-dev/htop#241 (comment) Fix whitespace before comma in the new color definitions hwloc = (portable) HardWare LOCality, not related to lock Add debug state to the configure report (thanks @BenBE for the idea) Move treeView setting to make status bar item correct when using --sort-key, patch from @cgzones Fix reading of device nodes > 2 chars from memory maps Replace more snprintfs, reduce buffer sizes to what is printed Update AUTHORS file with htop-dev team Update htop logo, provide .svg file as well Erdem Ersoy (1): Fix segmentation fault when column name is NULL. Fynn Wulf (3): Fix Hashtable_put to allow storing the same pointer Implement screen for active file locks Calculate library size (M_LRS column) from maps file Jan Palus (1): Parse POWER_SUPPLY_CAPACITY Maxim Zhiburt (2): Implement sorting in tree mode Fix issue with inconsistent displayTreeSet Michael F. Schönitzer (5): Change option '-m' to '-M' for consistency of cli Document field M_SWAP in man page Document M_PSS and M_PSSWP in man page Consistent wording/formatting of field descriptions Add a date and datetime meter (#159) Michael Witten (1): Process.{h,c}: Use integer types that are more portable Murloc Knight (1): Zram Meter feature Narendran Gopalakrishnan (4): Improving Command display/sort Cleanup some documentation Include merge status with column title when enabled Assume full basename matches COMM when matching full COMM buffer Nathan Scott (13): Merge individual Battery.[ch] files into Platform.[ch] Merge individual Battery.[ch] files into Platform.[ch] Add missing OpenBSD battery function declaration Minor cleanups to platform-specific init and done Add whitespace to improve Linux Platform_init readability Consistent ordering of function declarations for FreeBSD Drop unneeded parameters to the ScreenManager constructor Drop unused global ProcessList memory fields Tweak style guide wording around single code statements Update docs/styleguide.md Fix a little typo (spelling) in the styleguide Update changelog for upcoming 3.0.3 release, annotate rc1 Bump version number for 3.0.3 release Ross Williams (2): Add process environment for FreeBSD Simplify environment-reading code Stephen Gregoratto (1): configure.ac: axe python check Zev Weiss (1): Number CPUs from zero by default. ckath (1): minor typo in Vector.c laydervus (1): Option to set initial filter multi (4): Linux: consider the ZFS ARC to be cache. CPUMeter: refactor common CPU meter rendering code. Add missing 4-column CPU meters to non-Linux platforms. CPUMeter: add octuple-column CPU meters. ryenus (4): show selected command wrapped in a separate window command screen: fill current line when scanning limit max screen title length to window width use 'w' for command wrapping as 'M' is already used senjan (2): htop crashes on Solaris 11.4 due to missing ZFS ARC kstats htop shows no used memory in Solaris zone srajmane (1): s390x support for travis
(Hacktoberfest entry.) Relies on
starttime_ctime
which does not appear to be set in Linux. (Thestarttime
field in/proc/<pid>/stat
is not immediately useable.)