Commit f55e86f9 authored by Federico Vaga's avatar Federico Vaga

tools: improve printing code

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 45003981
...@@ -29,22 +29,58 @@ char git_version[] = "git_version: " GIT_VERSION; ...@@ -29,22 +29,58 @@ char git_version[] = "git_version: " GIT_VERSION;
struct fmctdc_time ts_prev[FMCTDC_NUM_CHANNELS]; struct fmctdc_time ts_prev[FMCTDC_NUM_CHANNELS];
static unsigned int stop = 0, fmt_wr = 0; static unsigned int stop = 0, fmt_wr = 0;
enum tstamp_print_format {
TSTAMP_FMT_PS = 0,
TSTAMP_FMT_WR,
};
/**
* It prints the given timestamp using the White-Rabit format
* @param[in] ts timestamp
*
* seconds:coarse:frac
*/
static inline void print_ts_wr(struct fmctdc_time ts)
{
fprintf(stdout, "%10"PRIu64":%09u:%04u",
ts.seconds, ts.coarse, ts.frac);
void dump_timestamp(struct fmctdc_time ts) }
/**
* It prints the given timestamp using the picosecond format
* @param[in] ts timestamp
*
* seconds.picoseconds
*/
static inline void print_ts_ps(struct fmctdc_time ts)
{ {
uint64_t picoseconds; uint64_t picoseconds;
if (fmt_wr) { picoseconds = ((uint64_t)ts.coarse) * 8000ULL;
/* White rabbit format */ picoseconds += ((uint64_t)ts.frac) * 8000ULL / 4096ULL;
fprintf(stdout, "%10"PRIu64":%09u:%04u", fprintf(stdout,
ts.seconds, ts.coarse, ts.frac); "%010"PRIu64"s %012"PRIu64"ps",
return; ts.seconds, picoseconds);
} else { }
picoseconds = (uint64_t) ts.coarse * 8000ULL +
(uint64_t) ts.frac * 8000ULL / 4096ULL; /**
fprintf(stdout, * It prints the given timestamp
"%010"PRIu64"s %012"PRIu64"ps", * @param[in] ts timestamp
ts.seconds, picoseconds); * @param[in] fmt timestamp print format
*/
static void print_ts(struct fmctdc_time ts, enum tstamp_print_format fmt)
{
switch (fmt) {
case TSTAMP_FMT_WR:
print_ts_wr(ts);
break;
case TSTAMP_FMT_PS:
print_ts_ps(ts);
break;
default:
fprintf(stdout, "--- invalid format ---\n");
break;
} }
} }
...@@ -57,7 +93,7 @@ void dump(unsigned int ch, struct fmctdc_time *ts, int diff_mode) ...@@ -57,7 +93,7 @@ void dump(unsigned int ch, struct fmctdc_time *ts, int diff_mode)
fprintf(stdout, fprintf(stdout,
"channel %d | channel seq %-12u\n ts ", "channel %d | channel seq %-12u\n ts ",
ch, ts->seq_id); ch, ts->seq_id);
dump_timestamp(*ts); print_ts(*ts, fmt_wr);
fprintf(stdout, "\n"); fprintf(stdout, "\n");
ts_tmp = *ts; ts_tmp = *ts;
...@@ -71,7 +107,7 @@ void dump(unsigned int ch, struct fmctdc_time *ts, int diff_mode) ...@@ -71,7 +107,7 @@ void dump(unsigned int ch, struct fmctdc_time *ts, int diff_mode)
/* We are in normal mode, calculate the difference */ /* We are in normal mode, calculate the difference */
fprintf(stdout, " diff "); fprintf(stdout, " diff ");
dump_timestamp(ts_tmp); print_ts(ts_tmp, fmt_wr);
ns = (uint64_t) ts_tmp.coarse * 8ULL; ns = (uint64_t) ts_tmp.coarse * 8ULL;
ns += (uint64_t) (ts_tmp.frac * 8000ULL / 4096ULL) / 1000ULL; ns += (uint64_t) (ts_tmp.frac * 8000ULL / 4096ULL) / 1000ULL;
......
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