mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Added timestamp format "epoch-usec"
This timestamp format will print the seconds since epoch along with subdivision in microseconds. Example: [1748009585.087083] tio v3.9-8-g2fb788f-dirty [1748009585.087156] Press ctrl-t q to quit [1748009585.087683] Connected to /dev/ttyUSB0
This commit is contained in:
parent
2fb788f817
commit
7e61a34df3
8 changed files with 28 additions and 5 deletions
|
|
@ -150,6 +150,8 @@ Set timestamp format to any of the following timestamp formats:
|
|||
ISO8601 format ("YYYY-MM-DDThh:mm:ss.sss")
|
||||
.IP "\fBepoch"
|
||||
Seconds since Unix epoch (1970-01-01)
|
||||
.IP "\fBepoch-usec"
|
||||
Seconds since Unix epoch (1970-01-01) with subdivision in microseconds
|
||||
.PP
|
||||
Default format is \fB24hour\fR
|
||||
.RE
|
||||
|
|
|
|||
|
|
@ -116,6 +116,8 @@ OPTIONS
|
|||
|
||||
epoch Seconds since Unix epoch (1970-01-01)
|
||||
|
||||
epoch-usec Seconds since Unix epoch (1970-01-01) with subdivision microseconds
|
||||
|
||||
Default format is 24hour
|
||||
|
||||
--timestamp-timeout <ms>
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ _tio()
|
|||
return 0
|
||||
;;
|
||||
--timestamp-format)
|
||||
COMPREPLY=( $(compgen -W "24hour 24hour-start 24hour-delta iso8601" -- ${cur}) )
|
||||
COMPREPLY=( $(compgen -W "24hour 24hour-start 24hour-delta iso8601 epoch epoch-usec" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
-c | --color)
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ static void config_parse_keys(GKeyFile *key_file, char *group)
|
|||
config_get_bool(key_file, group, "timestamp", (bool*) &option.timestamp);
|
||||
if (option.timestamp != TIMESTAMP_NONE)
|
||||
{
|
||||
config_get_string(key_file, group, "timestamp-format", &string, "24hour", "24hour-start", "24hour-delta", "iso8601", "epoch", NULL);
|
||||
config_get_string(key_file, group, "timestamp-format", &string, "24hour", "24hour-start", "24hour-delta", "iso8601", "epoch", "epoch-usec", NULL);
|
||||
if (string != NULL)
|
||||
{
|
||||
option_parse_timestamp(string, &option.timestamp);
|
||||
|
|
|
|||
|
|
@ -400,6 +400,10 @@ const char* option_timestamp_format_to_string(timestamp_t timestamp)
|
|||
return "epoch";
|
||||
break;
|
||||
|
||||
case TIMESTAMP_EPOCH_USEC:
|
||||
return "epoch-usec";
|
||||
break;
|
||||
|
||||
default:
|
||||
return "unknown";
|
||||
break;
|
||||
|
|
@ -430,6 +434,10 @@ void option_parse_timestamp(const char *arg, timestamp_t *timestamp)
|
|||
{
|
||||
*timestamp = TIMESTAMP_EPOCH;
|
||||
}
|
||||
else if (strcmp(arg, "epoch-usec") == 0)
|
||||
{
|
||||
*timestamp = TIMESTAMP_EPOCH_USEC;
|
||||
}
|
||||
else
|
||||
{
|
||||
tio_error_print("Invalid timestamp '%s'", arg);
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ char *timestamp_current_time(void)
|
|||
len = strftime(time_string, sizeof(time_string), "%Y-%m-%dT%H:%M:%S", tm);
|
||||
break;
|
||||
case TIMESTAMP_EPOCH:
|
||||
case TIMESTAMP_EPOCH_USEC:
|
||||
// "N.sss" (seconds since Unix epoch, 1970-01-01 00:00:00Z)
|
||||
tv = tv_now;
|
||||
tm = localtime(&tv.tv_sec);
|
||||
|
|
@ -84,12 +85,18 @@ char *timestamp_current_time(void)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
// Append milliseconds to all timestamps
|
||||
// Append millis-/microseconds to all timestamps
|
||||
if (len)
|
||||
{
|
||||
len = snprintf(time_string + len, TIME_STRING_SIZE_MAX - len, ".%03ld", (long)tv.tv_usec / 1000);
|
||||
if ( option.timestamp == TIMESTAMP_EPOCH_USEC )
|
||||
{
|
||||
len = snprintf(time_string + len, TIME_STRING_SIZE_MAX - len, ".%06ld", (long)tv.tv_usec);
|
||||
}
|
||||
else
|
||||
{
|
||||
len = snprintf(time_string + len, TIME_STRING_SIZE_MAX - len, ".%03ld", (long)tv.tv_usec / 1000);
|
||||
}
|
||||
}
|
||||
|
||||
// Save previous time value for next run
|
||||
tv_previous = tv_now;
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ typedef enum
|
|||
TIMESTAMP_24HOUR_DELTA,
|
||||
TIMESTAMP_ISO8601,
|
||||
TIMESTAMP_EPOCH,
|
||||
TIMESTAMP_EPOCH_USEC,
|
||||
TIMESTAMP_END,
|
||||
} timestamp_t;
|
||||
|
||||
|
|
|
|||
|
|
@ -1100,6 +1100,9 @@ void handle_command_sequence(char input_char, char *output_char, bool *forward)
|
|||
case TIMESTAMP_EPOCH:
|
||||
tio_printf("Switched timestamp mode to epoch");
|
||||
break;
|
||||
case TIMESTAMP_EPOCH_USEC:
|
||||
tio_printf("Switched timestamp mode to epoch with subdivision in microseconds");
|
||||
break;
|
||||
case TIMESTAMP_END:
|
||||
option.timestamp = TIMESTAMP_NONE;
|
||||
tio_printf("Switched timestamp mode off");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue