htop icon indicating copy to clipboard operation
htop copied to clipboard

new: Added support for "truss" (FreeBSD equivalent of "strace")

Open dmilith opened this issue 2 years ago • 9 comments

The patch is for FreeBSD, but I'm quite certain "truss" will be present in the base systems of NetBSD, OpenBSD and DragonflyBSD. It's confirmed to work only on FreeBSD.

dmilith avatar Mar 12 '22 23:03 dmilith

That should do it :) Confirmed that it works on my build system. Thanks

dmilith avatar Mar 13 '22 16:03 dmilith

Is it possible to check for truss at the configure time? I think it's bet not to assume the program is available unless htop is built to be a "cross" (--host machine different from --target machine). Same goes for strace, too.

Explorer09 avatar Mar 15 '22 06:03 Explorer09

Sure, whatever works @Explorer09. I don't know how m4/autoconf stuff works under the hood. So I prepared a quick patch to get the things done. I agree that htop should detect that strace exists only in Linux from the start.

dmilith avatar Mar 15 '22 10:03 dmilith

@Explorer09: I'm indifferent about the exact implementation, be it configure or compile time, as long as it properly covers all platforms …

BenBE avatar Mar 15 '22 14:03 BenBE

@BenBE I don't know what platform "PCP" is… so I just assumed it's unsupported. Now the platform list is exhaustive.

dmilith avatar Mar 15 '22 15:03 dmilith

I don't know what platform "PCP" is…

It's the code below pcp/ in the git repo and the --enable-pcp configure option (https://pcp.io) that produces pcp-htop. It's fine to not include tracing functionality for this platform.

natoscott avatar Mar 15 '22 18:03 natoscott

truss(1) on Solaris didn't support -s <strsize>, instead it has a completely different option with same name:

-s [!]<signal>[,...]

Therefore -s 512 must be removed in case of Solaris.

Low-power avatar Apr 26 '22 15:04 Low-power

Two more things needed (besides the Solaris split):

  • Mention truss in htop.1.in (man file)
  • #ifdef help screen (Action.c) to change strace -> truss on the affected platforms

fasterit avatar Apr 27 '22 11:04 fasterit

I'm quite certain "truss" will be present in the base systems of NetBSD, OpenBSD and DragonflyBSD.

On NetBSD the command is ktruss. It is quite easy to check the manual pages of other BSDs on man.freebsd.org.

alarixnia avatar May 10 '22 06:05 alarixnia

@dmilith Can you please update this PR to resolve the merge conflicts?

BenBE avatar Feb 04 '23 23:02 BenBE

Hey. It looks like issue #644 can be addressed together with this PR.

Explorer09 avatar Aug 12 '23 04:08 Explorer09

On MacOS there's dtruss, but tests have shown, that it's far to broken to be usable.

If you are eager to tests:

$ git diff
diff --git a/TraceScreen.c b/TraceScreen.c
index 8232418d..f88a34b2 100644
--- a/TraceScreen.c
+++ b/TraceScreen.c
@@ -96,13 +96,18 @@ bool TraceScreen_forkTracer(TraceScreen* this) {
 
          const char* message = "Could not execute 'truss'. Please make sure it is available in your $PATH.";
          (void)! write(STDERR_FILENO, message, strlen(message));
+      #if defined(HTOP_DARWIN)
+         execlp("dtruss", "dtruss", "-a", "-p", buffer, NULL);
+
+         const char* message = "Could not execute 'dtruss'. Please make sure it is available in your $PATH.";
+         (void)! write(STDERR_FILENO, message, strlen(message));
       #elif defined(HTOP_LINUX)
          execlp("strace", "strace", "-T", "-tt", "-s", "512", "-p", buffer, NULL);
 
          // Should never reach here, unless execlp fails ...
          const char* message = "Could not execute 'strace'. Please make sure it is available in your $PATH.";
          (void)! write(STDERR_FILENO, message, strlen(message));
-      #else // HTOP_DARWIN, HTOP_PCP == HTOP_UNSUPPORTED
+      #else // HTOP_PCP == HTOP_UNSUPPORTED
          const char* message = "Tracing unavailable on not supported system.";
          (void)! write(STDERR_FILENO, message, strlen(message));
       #endif

Beware, it will likely hang your system in different way …

Not applying support for MacOS.

BenBE avatar Dec 29 '23 13:12 BenBE

Superseeded by #1357

BenBE avatar Dec 29 '23 14:12 BenBE