Commit 55794637 authored by spiiroin's avatar spiiroin

[logging] Use timestamps relative to usb-moded start for stderr logging

Use of wall clock timestamps with microsecond accuracy makes it difficult
to see where usb-moded is spending time during startup.

Use timestamps that use millisecond accuracy and are relative to usb-moded
startup time.
Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
parent bae87438
...@@ -2,9 +2,12 @@ ...@@ -2,9 +2,12 @@
@file usb_moded-log.c @file usb_moded-log.c
Copyright (C) 2010 Nokia Corporation. All rights reserved. Copyright (C) 2010 Nokia Corporation. All rights reserved.
Copyright (C) 2016 Jolla Ltd.
@author: Philippe De Swert <philippe.de-swert@nokia.com> @author: Philippe De Swert <philippe.de-swert@nokia.com>
@author: Simo Piiroinen <simo.piiroinen@nokia.com> @author: Simo Piiroinen <simo.piiroinen@nokia.com>
@author: Simo Piiroinen <simo.piiroinen@jollamobile.com>
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the Lesser GNU General Public License modify it under the terms of the Lesser GNU General Public License
...@@ -53,6 +56,14 @@ static char *strip(char *str) ...@@ -53,6 +56,14 @@ static char *strip(char *str)
return str; return str;
} }
static struct timeval log_begtime = { 0, 0 };
static void log_gettime(struct timeval *tv)
{
gettimeofday(tv, 0);
timersub(tv, &log_begtime, tv);
}
/** /**
* Print the logged messages to the selected output * Print the logged messages to the selected output
* *
...@@ -79,10 +90,10 @@ void log_emit_va(int lev, const char *fmt, va_list va) ...@@ -79,10 +90,10 @@ void log_emit_va(int lev, const char *fmt, va_list va)
#if LOG_ENABLE_TIMESTAMPS #if LOG_ENABLE_TIMESTAMPS
{ {
struct timeval tv; struct timeval tv;
gettimeofday(&tv, 0); log_gettime(&tv);
fprintf(stderr, "%ld.%06ld ", fprintf(stderr, "%3ld.%03ld ",
(long)tv.tv_sec, (long)tv.tv_sec,
(long)tv.tv_usec); (long)tv.tv_usec/1000);
} }
#endif #endif
...@@ -156,3 +167,10 @@ inline void log_set_level(int lev) ...@@ -156,3 +167,10 @@ inline void log_set_level(int lev)
log_level = lev; log_level = lev;
} }
/** Initialize logging */
void log_init(void)
{
/* Get reference time used for verbose logging */
if( !timerisset(&log_begtime) )
gettimeofday(&log_begtime, 0);
}
/* /*
Copyright (C) 2010 Nokia Corporation. All rights reserved. Copyright (C) 2010 Nokia Corporation. All rights reserved.
Copyright (C) 2016 Jolla Ltd.
Author: Philippe De Swert <philippe.de-swert@nokia.com> Author: Philippe De Swert <philippe.de-swert@nokia.com>
Author: Simo Piiroinen <simo.piiroinen@jollamobile.com>
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the Lesser GNU General Public License modify it under the terms of the Lesser GNU General Public License
...@@ -44,6 +46,7 @@ enum ...@@ -44,6 +46,7 @@ enum
void log_set_level(int lev); void log_set_level(int lev);
int log_get_level(void); int log_get_level(void);
void log_init(void);
void log_emit_va(int lev, const char *fmt, va_list va); void log_emit_va(int lev, const char *fmt, va_list va);
void log_emit(int lev, const char *fmt, ...) __attribute__((format(printf,2,3))); void log_emit(int lev, const char *fmt, ...) __attribute__((format(printf,2,3)));
void log_debugf(const char *fmt, ...) __attribute__((format(printf,1,2))); void log_debugf(const char *fmt, ...) __attribute__((format(printf,1,2)));
......
...@@ -1103,6 +1103,7 @@ int main(int argc, char* argv[]) ...@@ -1103,6 +1103,7 @@ int main(int argc, char* argv[])
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
log_init();
log_name = basename(*argv); log_name = basename(*argv);
/* Parse the command-line options */ /* Parse the command-line options */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment