Skip to content
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

fix: make monitor more readable #3702

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

anoushk1234
Copy link
Contributor

@anoushk1234 anoushk1234 commented Dec 14, 2024

Fixes #3676

@anoushk1234 anoushk1234 force-pushed the anoushk1234/sep-monitor-panes branch from 2c11519 to b1bc7f1 Compare December 17, 2024 13:21
@anoushk1234
Copy link
Contributor Author

Hey @ripatel-fd did you get a chance to review this yet?

@anoushk1234
Copy link
Contributor Author

Also the sandbox prevents reading STDIN preventing tab switching in the monitor, is there a way to allow that for non dev builds without disabling the sandbox?

Signed-off-by: Anoushk Kharangate <[email protected]>
@anoushk1234 anoushk1234 force-pushed the anoushk1234/sep-monitor-panes branch from b1bc7f1 to 84fd7c0 Compare December 17, 2024 13:52
@ripatel-fd
Copy link
Contributor

Hey @ripatel-fd did you get a chance to review this yet?

@anoushk1234 Thank you for the contribution! I tagged @mmcgee-jump for review.

Also the sandbox prevents reading STDIN preventing tab switching in the monitor, is there a way to allow that for non dev builds without disabling the sandbox?

Yes, the syscall policy for the monitor is defined in src/app/fdctl/monitor/monitor.seccomppolicy.
You'd probably want to amend the expression for the read syscall to allow file descriptor 0 (stdin).

@anoushk1234
Copy link
Contributor Author

Hey @ripatel-fd did you get a chance to review this yet?

@anoushk1234 Thank you for the contribution! I tagged @mmcgee-jump for review.

Also the sandbox prevents reading STDIN preventing tab switching in the monitor, is there a way to allow that for non dev builds without disabling the sandbox?

Yes, the syscall policy for the monitor is defined in src/app/fdctl/monitor/monitor.seccomppolicy. You'd probably want to amend the expression for the read syscall to allow file descriptor 0 (stdin).

Thanks! @ripatel-fd Let me push the updated policy

@ripatel-fd
Copy link
Contributor

Thanks! @ripatel-fd Let me push the updated policy

Great, thanks! I forgot to mention, could you please also run make seccomp-policies to regenerate the C header files created from those seccomp policy files?

Comment on lines 180 to 203
int
fd_getch()
{
struct termios oldt, newt;
int ch;
int oldf;
/* Disables character echo and canonical mode since we want the input to be processes immediately.
* Terminal also set to non blocking in case the user doesn't send any input.
* */
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= (tcflag_t)~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);

ch = getchar();

/*Restore the terminal back to it's original configuration*/
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
fcntl(STDIN_FILENO, F_SETFL, oldf);

return ch;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple code style suggestions, some of which are in https://github.com/firedancer-io/firedancer/blob/main/CONTRIBUTING.md

  • We follow the C strict prototypes rule where we use void to signal a blank argument list.
  • The curly goes on the same line as the method definition
int
fd_getch( void ) {
  • Comment style looks like this:
  /* Disables character echo and canonical mode since we want the input to be processes immediately.
     Terminal also set to non blocking in case the user doesn't send any input. */
  • Variable declarations go as close as possible to the definition
  • libc library functions should do error handling
  • Spaces inside brackets when doing control flow statements and function calls
  struct termios oldt;
  if( FD_UNLIKELY( 0!=tcgetattr( STDIN_FILENO, &oldt ) ) ) {
    ... handle error ...
  }
  struct termios newt = oldt;
  newt.c_lflag &= (tcflag_t)~(ICANON | ECHO);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ripatel-fd thanks for the points regarding the style, I'll be more careful to stick to it next time. Given we are not resetting the terminal back to it's old state now, there isn't a good reason to have a separate function for this and I can just move the tcsetattr code into monitor.c before the rendering loop starts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sidenote: in your example if( FD_UNLIKELY( 0!=tcgetattr( STDIN_FILENO, &oldt ) ) ) tcgetattr has spaces within the brackets but in the style it doesn't:

memcpy( dst, src, sizeof(fd_rng_t) );  /* good */

memcpy( dst, src, sizeof( fd_rng_t ) );  /* WRONG! */

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. sizeof is an operator, not a function call. So we usually don't use spaces there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. sizeof is an operator, not a function call. So we usually don't use spaces there

Makes sense, this example needs to be updated then.

Copy link
Contributor

@ripatel-fd ripatel-fd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution. It looks good overall. I posted a couple nits above.

src/app/fdctl/monitor/monitor.c Outdated Show resolved Hide resolved
src/app/fdctl/monitor/monitor.c Outdated Show resolved Hide resolved
@anoushk1234
Copy link
Contributor Author

anoushk1234 commented Jan 7, 2025

Hey @ripatel-fd made the changes, apologies for the delay, I was out of office. Would appreciate another review ( Don't mind the multiple commits, I'll rebase it all into one once the PR is approved )

Regarding the seccomp policy I add getc: (eq (arg 0) 0) to the file and ran make seccomp-policies but while compiling I get this error, am I doing something wrong?
Screenshot 2025-01-07 at 4 58 05 PM

@anoushk1234 anoushk1234 force-pushed the anoushk1234/sep-monitor-panes branch 2 times, most recently from 4e41a01 to 7a06199 Compare January 7, 2025 11:54
@anoushk1234 anoushk1234 force-pushed the anoushk1234/sep-monitor-panes branch from 7a06199 to f88cf8d Compare January 7, 2025 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better metrics rendering in monitor
2 participants