Message ID | 166318850459.3087953.851045527272435004.stgit@djiang5-desk3.ch.intel.com |
---|---|
State | Superseded |
Delegated to: | Vishal Verma |
Headers | show |
Series | ndctl: cxl: add monitor support for trace events | expand |
On 9/14/22 15:48, Dave Jiang wrote: > Duplicate log functions from ndctl/monitor to use for stdout and file > logging. > > Signed-off-by: Dave Jiang <dave.jiang@gmail.com> > --- > cxl/monitor.c | 26 ++++++++++++++++++++++++++ > 1 file changed, 26 insertions(+) > > diff --git a/cxl/monitor.c b/cxl/monitor.c > index 2ab2e249f575..e030542a3fe8 100644 > --- a/cxl/monitor.c > +++ b/cxl/monitor.c > @@ -39,6 +39,32 @@ static struct monitor { > bool human; > } monitor; > > +static void log_standard(struct log_ctx *ctx, int priority, const char *file, > + int line, const char *fn, const char *format, va_list args) > +{ > + if (priority == 6) > + vfprintf(stdout, format, args); > + else > + vfprintf(stderr, format, args); > +} > + > +static void log_file(struct log_ctx *ctx, int priority, const char *file, > + int line, const char *fn, const char *format, va_list args) > +{ > + FILE *f = monitor.log_file; > + > + if (priority != LOG_NOTICE) { > + struct timespec ts; > + > + clock_gettime(CLOCK_REALTIME, &ts); > + fprintf(f, "[%10ld.%09ld] [%d] ", ts.tv_sec, ts.tv_nsec, getpid()); > + vfprintf(f, format, args); > + } else > + vfprintf(f, format, args); The vfprintf() is always done here, you could just move it outside the if/else block. -Nathan > + > + fflush(f); > +} > + > static int monitor_event(struct cxl_ctx *ctx) > { > int fd, epollfd, rc = 0, timeout = -1; > >
On 9/15/2022 8:55 AM, Nathan Fontenot wrote: > On 9/14/22 15:48, Dave Jiang wrote: >> Duplicate log functions from ndctl/monitor to use for stdout and file >> logging. >> >> Signed-off-by: Dave Jiang <dave.jiang@gmail.com> >> --- >> cxl/monitor.c | 26 ++++++++++++++++++++++++++ >> 1 file changed, 26 insertions(+) >> >> diff --git a/cxl/monitor.c b/cxl/monitor.c >> index 2ab2e249f575..e030542a3fe8 100644 >> --- a/cxl/monitor.c >> +++ b/cxl/monitor.c >> @@ -39,6 +39,32 @@ static struct monitor { >> bool human; >> } monitor; >> >> +static void log_standard(struct log_ctx *ctx, int priority, const char *file, >> + int line, const char *fn, const char *format, va_list args) >> +{ >> + if (priority == 6) >> + vfprintf(stdout, format, args); >> + else >> + vfprintf(stderr, format, args); >> +} >> + >> +static void log_file(struct log_ctx *ctx, int priority, const char *file, >> + int line, const char *fn, const char *format, va_list args) >> +{ >> + FILE *f = monitor.log_file; >> + >> + if (priority != LOG_NOTICE) { >> + struct timespec ts; >> + >> + clock_gettime(CLOCK_REALTIME, &ts); >> + fprintf(f, "[%10ld.%09ld] [%d] ", ts.tv_sec, ts.tv_nsec, getpid()); >> + vfprintf(f, format, args); >> + } else >> + vfprintf(f, format, args); > The vfprintf() is always done here, you could just move it outside the if/else block. Thanks! Will move. I just blindly copied the code from ndctl/monitor.c. > > -Nathan > >> + >> + fflush(f); >> +} >> + >> static int monitor_event(struct cxl_ctx *ctx) >> { >> int fd, epollfd, rc = 0, timeout = -1; >> >>
diff --git a/cxl/monitor.c b/cxl/monitor.c index 2ab2e249f575..e030542a3fe8 100644 --- a/cxl/monitor.c +++ b/cxl/monitor.c @@ -39,6 +39,32 @@ static struct monitor { bool human; } monitor; +static void log_standard(struct log_ctx *ctx, int priority, const char *file, + int line, const char *fn, const char *format, va_list args) +{ + if (priority == 6) + vfprintf(stdout, format, args); + else + vfprintf(stderr, format, args); +} + +static void log_file(struct log_ctx *ctx, int priority, const char *file, + int line, const char *fn, const char *format, va_list args) +{ + FILE *f = monitor.log_file; + + if (priority != LOG_NOTICE) { + struct timespec ts; + + clock_gettime(CLOCK_REALTIME, &ts); + fprintf(f, "[%10ld.%09ld] [%d] ", ts.tv_sec, ts.tv_nsec, getpid()); + vfprintf(f, format, args); + } else + vfprintf(f, format, args); + + fflush(f); +} + static int monitor_event(struct cxl_ctx *ctx) { int fd, epollfd, rc = 0, timeout = -1;
Duplicate log functions from ndctl/monitor to use for stdout and file logging. Signed-off-by: Dave Jiang <dave.jiang@gmail.com> --- cxl/monitor.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)