Skip to content

Commit e508fec

Browse files
committed
logger: do not use get_time_in_ns for timestamp
use `timespec_get(... TIME_UTC)` instead directly This is more clear and also slightly more efficient (avoiding convs). The rationale was to decouple time_ns_t from wall-clock time. The time_ns_t may be set later to CLOCK_MONOTONIC instead of CLOCK_REALTIME (which corresponds to TIME_UTC). As for now, these timestamps in the logger are in time from epoch. (Other variants like time from UG start can be also considered later but REALITME /likely the time from marchine boot/ doesn't seem much useful).
1 parent 3aff872 commit e508fec

5 files changed

Lines changed: 30 additions & 21 deletions

File tree

src/debug.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@
4040

4141
#ifdef __cplusplus
4242
#include <cstdint>
43-
#include <cstdio> // FILE
43+
#include <ctime> // timespec_get
4444
#else
4545
#include <stdbool.h>
4646
#include <stdint.h>
47-
#include <stdio.h> // FILE
4847
#endif // defined __cplusplus
4948

50-
#include "tv.h"
5149

5250
#define UNUSED(x) (x=x)
5351

@@ -252,9 +250,11 @@ inline void Log_output::submit(){
252250
if (show_timestamps == LOG_TIMESTAMP_ENABLED
253251
|| (show_timestamps == LOG_TIMESTAMP_AUTO && log_level >= LOG_LEVEL_VERBOSE))
254252
{
255-
const time_ns_t time_ns = get_time_in_ns();
256-
snprintf(ts_str, ts_bufsize, "[%.3f] ",
257-
(double) time_ns / NS_IN_SEC_DBL);
253+
std::timespec ts{};
254+
std::timespec_get(&ts, TIME_UTC);
255+
snprintf(ts_str, ts_bufsize, "[%lld.%3d] ",
256+
(long long) ts.tv_sec,
257+
(int) (ts.tv_nsec / 1000 / 1000));
258258
}
259259

260260
const char *start_newline = "";

src/tfrc.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,16 @@
4444
*
4545
*/
4646

47-
#include <stdbool.h>
48-
#include <stdlib.h>
49-
#include <stdint.h>
50-
#include <assert.h>
51-
52-
#include "config.h"
53-
#include "debug.h"
54-
#include "rtp/rtp.h"
55-
#include "tv.h"
5647
#include "tfrc.h"
5748

49+
#include <assert.h> // for assert
50+
#include <stdint.h> // for uint32_t, uint16_t
51+
#include <stdio.h> // for printf, NULL
52+
#include <stdlib.h> // for abort, free, malloc
53+
54+
#include "debug.h" // for LOG_LEVEL_DEBUG, log_level
55+
#include "tv.h" // for time_ns_t, NS_IN_SEC, get_time_in_ns
56+
5857
#define TFRC_MAGIC 0xbaef03b7 /* For debugging */
5958

6059
#define MAX_HISTORY 1000

src/tfrc.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
*
4444
*/
4545

46+
#ifdef __cplusplus
47+
#include <cstdint> // for uint16_t, uint32_t
48+
#else
49+
#include <stdint.h> // for uint16_t, uint32_t
50+
#endif
51+
4652
#ifdef __cplusplus
4753
extern "C" {
4854
#endif

test/test_des.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@
3838
* SUCH DAMAGE.
3939
*/
4040

41+
#include "test_des.h"
42+
4143
#include <string.h>
42-
#include "debug.h"
44+
#include <stdio.h>
45+
4346
#include "crypto/crypt_des.h"
44-
#include "test_des.h"
4547

4648
#define NUM_TESTS 36
4749

test/test_net_udp.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,19 @@
3434
* SUCH DAMAGE.
3535
*/
3636

37+
#include "test_net_udp.h"
38+
3739
#include <stdio.h>
3840
#include <stdlib.h>
41+
#include <string.h>
42+
#include <sys/time.h> // for timeval
3943
#ifndef WIN32
4044
#include <sys/wait.h>
4145
#endif
46+
#include <time.h>
4247

43-
#include "debug.h"
48+
#include "compat/net.h" // for HAVE_IPv6, fork
4449
#include "rtp/net_udp.h"
45-
#include "test_net_udp.h"
46-
47-
#include <string.h>
4850

4951
#define BUFSIZE 1024
5052

0 commit comments

Comments
 (0)