Flowgrind
Advanced TCP traffic generator
debug.c File Reference

Debugging routines for Flowgrind controller and daemon. More...

#include "debug.h"
#include "config.h"
#include <stdio.h>
#include <time.h>
#include <string.h>
#include "fg_time.h"
#include "fg_string.h"

Go to the source code of this file.

Functions

int debug_timestamp (char **strp)
 Helper function for DEBUG_MSG macro. More...
 
void decrease_debuglevel ()
 Decrease debug level. More...
 
void increase_debuglevel ()
 Decrease debug level. More...
 

Detailed Description

Debugging routines for Flowgrind controller and daemon.

Definition in file debug.c.

Function Documentation

int debug_timestamp ( char **  resultp)

Helper function for DEBUG_MSG macro.

Write string with the current time in seconds and nanoseconds since the Epoch together with the delta in time since the last and first call the function.

Parameters
[in,out]resultpdestination string to write to
Returns
return 0 for success, or -1 for failure

Definition at line 56 of file debug.c.

57 {
58  struct timespec now = {.tv_sec = 0, .tv_nsec = 0};
59  static struct timespec first = {.tv_sec = 0, .tv_nsec = 0};
60  static struct timespec last = {.tv_sec = 0, .tv_nsec = 0};
61 
62  gettime(&now);
63 
64  /* Save time of first call */
65  if (!first.tv_sec && !first.tv_nsec)
66  first = last = now;
67 
68  char timestamp[30] = "";
69  ctimespec_r(&now, timestamp, sizeof(timestamp), true);
70 
71  if (asprintf(strp, "%s [+%8.6lf] (%8.6lf)", timestamp,
72  time_diff(&last, &now), time_diff(&first, &now)) == -1)
73  return -1;
74 
75  last = now;
76  return 0;
77 }
const char * ctimespec_r(const struct timespec *tp, char *buf, size_t size, bool ns)
Converts timespec struct tp into a null-terminated string.
Definition: fg_time.c:66
int gettime(struct timespec *tp)
Returns the current wall-clock time with nanosecond precision.
Definition: fg_time.c:145
double time_diff(const struct timespec *tp1, const struct timespec *tp2)
Returns the time difference between two the specific points in time tp1 and tp2.
Definition: fg_time.c:95
void decrease_debuglevel ( void  )
inline

Decrease debug level.

Definition at line 44 of file debug.c.

45 {
46  debug_level--;
47  printf("DEBUG_LEVEL=%u", debug_level);
48 }
unsigned debug_level
Global debug level for flowgrind controller and daemon.
Definition: debug.h:60
void increase_debuglevel ( void  )
inline

Decrease debug level.

Definition at line 50 of file debug.c.

51 {
52  debug_level++;
53  printf("DEBUG_LEVEL=%u\n", debug_level);
54 }
unsigned debug_level
Global debug level for flowgrind controller and daemon.
Definition: debug.h:60