htop icon indicating copy to clipboard operation
htop copied to clipboard

linux: support for monitoring syscall

Open pixclk opened this issue 1 year ago • 13 comments

pixclk avatar May 30 '24 06:05 pixclk

Any chance this kind of information is available on other platforms too?

BenBE avatar May 31 '24 14:05 BenBE

Any chance this kind of information is available on other platforms too?

Theoretically possible, but currently only intended to support Linux.

pixclk avatar May 31 '24 14:05 pixclk

One more thing. We should allow the user to disable this "syscall" monitoring at compile time time. Since the /proc/<pid>/syscall file is only present when the kernel is compiled with CONFIG_HAVE_ARCH_TRACEHOOK, it may be useless for users without such kernel. Another reason for having this compile option is we can save code size by not compiling the syscall number-to-name mapping table into htop binary, in case we implement one in the future.

Explorer09 avatar Jun 01 '24 09:06 Explorer09

@Explorer09 Or disable the column, when the feature is not available at runtime.

BenBE avatar Jun 01 '24 10:06 BenBE

@ Explorer09 Or disable the column, when the feature is not available at runtime.

I wish a compile time option to disable it as well.

Explorer09 avatar Jun 01 '24 11:06 Explorer09

@ Explorer09 Or disable the column, when the feature is not available at runtime.

I wish a compile time option to disable it as well.

Like so?

# Check for syscall feature option
AC_ARG_ENABLE(
   [syscall],
   [
      AS_HELP_STRING(
         [--enable-syscall],
         [Enable 'syscall' feature. Possible values: off, buildtime-check, runtime-check, always-on. Default is 'off'.]
      )
   ],
   [case "${enableval}" in
      off) syscall_feature=0 ;;
      buildtime-check) syscall_feature=1 ;;
      runtime-check) syscall_feature=2 ;;
      always-on) syscall_feature=3 ;;
      *) AC_MSG_ERROR([Invalid value for --enable-syscall]) ;;
   esac],
   [syscall_feature=0]
)

# If buildtime-check is enabled, check if /proc/self/syscall exists and is non-empty
AS_IF(
   [test "x$syscall_feature" = "x1"],
   [
      AC_CHECK_FILE(
         [/proc/self/syscall],
         [syscall_exists=yes],
         [syscall_exists=no]
      )
      AS_IF(
         [test "x$syscall_exists" = "xyes" && test -s /proc/self/syscall],
         [],
         [syscall_feature=0]
      )
   ]
)

# Set the result of the check to a preprocessor directive
AC_DEFINE_UNQUOTED([SYSCALL_FEATURE], [$syscall_feature], [Define to the selected syscall feature state.])

BenBE avatar Jun 01 '24 14:06 BenBE

@BenBE

  • I merged your "runtime-check" and "always-on" into one option, because checking the thing at runtime is trivial.
  • When cross-compiling, checking /proc/self/syscall won't help. It's better just enable it in that case.
AC_ARG_ENABLE([syscall],
   [AS_HELP_STRING([--enable-syscall],
   [enable 'syscall' monitoring. @<:@default=check@:>@])],
   [],
   [enable_syscall=check]
)

if test "x$enable_syscall" = xcheck; then
   if "$cross_compiling" != no; then
      enable_syscall=yes
   elif test -f /proc/self/syscall && test -s /proc/self/syscall; then
      enable_syscall=yes
   else
      enable_syscall=no
   fi
fi
if test "x$enable_syscall" = xyes; then
   AC_DEFINE([HAVE_SYSCALL], [1], [Define to 1 is syscall monitoring is enabled.])
fi

Explorer09 avatar Jun 01 '24 14:06 Explorer09

@BenBE

* I merged your "runtime-check" and "always-on" into one option, because checking the thing at runtime is trivial.

* When cross-compiling, checking `/proc/self/syscall` won't help. It's better just enable it in that case.
AC_ARG_ENABLE([syscall],
   [AS_HELP_STRING([--enable-syscall],
   [enable 'syscall' monitoring. @<:@default=check@:>@])],
   [],
   [enable_syscall=check]
)

if test "x$enable_syscall" = xcheck; then
   if "$cross_compiling" != no; then
      enable_syscall=yes
   elif test -f /proc/self/syscall && test -s /proc/self/syscall; then
      enable_syscall=yes
   else
      enable_syscall=no
   fi
fi
if test "x$enable_syscall" = xyes; then
   AC_DEFINE([HAVE_SYSCALL], [1], [Define to 1 is syscall monitoring is enabled.])
fi

Very good job, I will merge it

pixclk avatar Jun 01 '24 15:06 pixclk

@Explorer09

@JohnSanpe You should handle the running string as special and assign a placeholder number for it. The reason is it allows us to display running string with colors. This status should be special in sorting/collating anyway.

Using special placeholder number may conflict with future syscalls, so storing possible states separately may be a better choice? This is also more convenient for us to use lookup tables in the future.

pixclk avatar Jun 01 '24 16:06 pixclk

You should handle the running string as special and assign a placeholder number for it. The reason is it allows us to display running string with colors. This status should be special in sorting/collating anyway.

Using special placeholder number may conflict with future syscalls, so storing possible states separately may be a better choice? This is also more convenient for us to use lookup tables in the future.

Use a negative number. E.g. -2, or maybe -1000 which has an even less chance to cause conflict.

Explorer09 avatar Jun 01 '24 16:06 Explorer09

You should handle the running string as special and assign a placeholder number for it. The reason is it allows us to display running string with colors. This status should be special in sorting/collating anyway.

Using special placeholder number may conflict with future syscalls, so storing possible states separately may be a better choice? This is also more convenient for us to use lookup tables in the future.

Use a negative number. E.g. -2, or maybe -1000 which has an even less chance to cause conflict.

I have already fixed it 😄

pixclk avatar Jun 01 '24 16:06 pixclk

Does CI seem to have some issues?

pixclk avatar Jul 15 '24 17:07 pixclk

Does CI seem to have some issues?

No. CI is waiting for approval by one of the maintainers as this is your first pull request for this project.

BenBE avatar Jul 15 '24 20:07 BenBE