#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
-#define NSEC_PER_SEC 1000000000ULL
+#define NSEC_PER_SEC 1000000000LL
#define INDEX_PATH "./index/%s.idx"
opt_clock_date,
opt_clock_gmt;
-uint64_t opt_clock_offset;
-uint64_t opt_clock_offset_ns;
+int64_t opt_clock_offset;
+int64_t opt_clock_offset_ns;
extern int yydebug;
static
int ctf_close_trace(struct bt_trace_descriptor *descriptor);
static
-uint64_t ctf_timestamp_begin(struct bt_trace_descriptor *descriptor,
- struct bt_trace_handle *handle, enum bt_clock_type type);
+int ctf_timestamp_begin(struct bt_trace_descriptor *descriptor,
+ struct bt_trace_handle *handle, enum bt_clock_type type,
+ int64_t *timestamp);
static
-uint64_t ctf_timestamp_end(struct bt_trace_descriptor *descriptor,
- struct bt_trace_handle *handle, enum bt_clock_type type);
+int ctf_timestamp_end(struct bt_trace_descriptor *descriptor,
+ struct bt_trace_handle *handle, enum bt_clock_type type,
+ int64_t *timestamp);
static
int ctf_convert_index_timestamp(struct bt_trace_descriptor *tdp);
static
rw_dispatch read_dispatch_table[] = {
- [ CTF_TYPE_INTEGER ] = ctf_integer_read,
- [ CTF_TYPE_FLOAT ] = ctf_float_read,
- [ CTF_TYPE_ENUM ] = ctf_enum_read,
- [ CTF_TYPE_STRING ] = ctf_string_read,
- [ CTF_TYPE_STRUCT ] = ctf_struct_rw,
- [ CTF_TYPE_VARIANT ] = ctf_variant_rw,
- [ CTF_TYPE_ARRAY ] = ctf_array_read,
- [ CTF_TYPE_SEQUENCE ] = ctf_sequence_read,
+ [ BT_CTF_TYPE_ID_INTEGER ] = ctf_integer_read,
+ [ BT_CTF_TYPE_ID_FLOAT ] = ctf_float_read,
+ [ BT_CTF_TYPE_ID_ENUM ] = ctf_enum_read,
+ [ BT_CTF_TYPE_ID_STRING ] = ctf_string_read,
+ [ BT_CTF_TYPE_ID_STRUCT ] = ctf_struct_rw,
+ [ BT_CTF_TYPE_ID_VARIANT ] = ctf_variant_rw,
+ [ BT_CTF_TYPE_ID_ARRAY ] = ctf_array_read,
+ [ BT_CTF_TYPE_ID_SEQUENCE ] = ctf_sequence_read,
};
static
rw_dispatch write_dispatch_table[] = {
- [ CTF_TYPE_INTEGER ] = ctf_integer_write,
- [ CTF_TYPE_FLOAT ] = ctf_float_write,
- [ CTF_TYPE_ENUM ] = ctf_enum_write,
- [ CTF_TYPE_STRING ] = ctf_string_write,
- [ CTF_TYPE_STRUCT ] = ctf_struct_rw,
- [ CTF_TYPE_VARIANT ] = ctf_variant_rw,
- [ CTF_TYPE_ARRAY ] = ctf_array_write,
- [ CTF_TYPE_SEQUENCE ] = ctf_sequence_write,
+ [ BT_CTF_TYPE_ID_INTEGER ] = ctf_integer_write,
+ [ BT_CTF_TYPE_ID_FLOAT ] = ctf_float_write,
+ [ BT_CTF_TYPE_ID_ENUM ] = ctf_enum_write,
+ [ BT_CTF_TYPE_ID_STRING ] = ctf_string_write,
+ [ BT_CTF_TYPE_ID_STRUCT ] = ctf_struct_rw,
+ [ BT_CTF_TYPE_ID_VARIANT ] = ctf_variant_rw,
+ [ BT_CTF_TYPE_ID_ARRAY ] = ctf_array_write,
+ [ BT_CTF_TYPE_ID_SEQUENCE ] = ctf_sequence_write,
};
static
};
static
-uint64_t ctf_timestamp_begin(struct bt_trace_descriptor *descriptor,
- struct bt_trace_handle *handle, enum bt_clock_type type)
+int ctf_timestamp_begin(struct bt_trace_descriptor *descriptor,
+ struct bt_trace_handle *handle, enum bt_clock_type type,
+ int64_t *timestamp)
{
struct ctf_trace *tin;
- uint64_t begin = ULLONG_MAX;
- int i, j;
+ int64_t begin = LLONG_MAX;
+ int i, j, ret;
tin = container_of(descriptor, struct ctf_trace, parent);
- if (!tin)
+ if (!tin || !timestamp) {
+ ret = -EINVAL;
goto error;
+ }
/* for each stream_class */
for (i = 0; i < tin->streams->len; i++) {
parent);
stream_pos = &cfs->pos;
- if (!stream_pos->packet_index)
+ if (!stream_pos->packet_index) {
+ ret = -EINVAL;
goto error;
+ }
if (stream_pos->packet_index->len <= 0)
continue;
if (index->ts_cycles.timestamp_begin < begin)
begin = index->ts_cycles.timestamp_begin;
} else {
+ ret = -EINVAL;
goto error;
}
}
}
-
- return begin;
+ if (begin == LLONG_MAX) {
+ ret = -ENOENT;
+ goto error;
+ }
+ *timestamp = begin;
+ return 0;
error:
- return -1ULL;
+ return ret;
}
static
-uint64_t ctf_timestamp_end(struct bt_trace_descriptor *descriptor,
- struct bt_trace_handle *handle, enum bt_clock_type type)
+int ctf_timestamp_end(struct bt_trace_descriptor *descriptor,
+ struct bt_trace_handle *handle, enum bt_clock_type type,
+ int64_t *timestamp)
{
struct ctf_trace *tin;
- uint64_t end = 0;
- int i, j;
+ int64_t end = LLONG_MIN;
+ int i, j, ret;
tin = container_of(descriptor, struct ctf_trace, parent);
- if (!tin)
+ if (!tin || !timestamp) {
+ ret = -EINVAL;
goto error;
+ }
/* for each stream_class */
for (i = 0; i < tin->streams->len; i++) {
parent);
stream_pos = &cfs->pos;
- if (!stream_pos->packet_index)
+ if (!stream_pos->packet_index) {
+ ret = -EINVAL;
goto error;
+ }
if (stream_pos->packet_index->len <= 0)
continue;
if (index->ts_cycles.timestamp_end > end)
end = index->ts_cycles.timestamp_end;
} else {
+ ret = -EINVAL;
goto error;
}
}
}
-
- return end;
+ if (end == LLONG_MIN) {
+ ret = -ENOENT;
+ goto error;
+ }
+ *timestamp = end;
+ return 0;
error:
- return -1ULL;
+ return ret;
}
/*
static
void ctf_print_timestamp_real(FILE *fp,
struct ctf_stream_definition *stream,
- uint64_t timestamp)
+ int64_t timestamp)
{
- uint64_t ts_sec = 0, ts_nsec;
+ int64_t ts_sec = 0, ts_nsec;
+ uint64_t ts_sec_abs, ts_nsec_abs;
+ bool is_negative;
ts_nsec = timestamp;
- /* Add command-line offset in ns*/
+ /* Add command-line offset in ns */
ts_nsec += opt_clock_offset_ns;
/* Add command-line offset */
ts_sec += ts_nsec / NSEC_PER_SEC;
ts_nsec = ts_nsec % NSEC_PER_SEC;
+ if (ts_sec >= 0 && ts_nsec >= 0) {
+ is_negative = false;
+ ts_sec_abs = ts_sec;
+ ts_nsec_abs = ts_nsec;
+ } else if (ts_sec > 0 && ts_nsec < 0) {
+ is_negative = false;
+ ts_sec_abs = ts_sec - 1;
+ ts_nsec_abs = NSEC_PER_SEC + ts_nsec;
+ } else if (ts_sec == 0 && ts_nsec < 0) {
+ is_negative = true;
+ ts_sec_abs = ts_sec;
+ ts_nsec_abs = -ts_nsec;
+ } else if (ts_sec < 0 && ts_nsec > 0) {
+ is_negative = true;
+ ts_sec_abs = -(ts_sec + 1);
+ ts_nsec_abs = NSEC_PER_SEC - ts_nsec;
+ } else if (ts_sec < 0 && ts_nsec == 0) {
+ is_negative = true;
+ ts_sec_abs = -ts_sec;
+ ts_nsec_abs = ts_nsec;
+ } else { /* (ts_sec < 0 && ts_nsec < 0) */
+ is_negative = true;
+ ts_sec_abs = -ts_sec;
+ ts_nsec_abs = -ts_nsec;
+ }
if (!opt_clock_seconds) {
struct tm tm;
- time_t time_s = (time_t) ts_sec;
+ time_t time_s = (time_t) ts_sec_abs;
+
+ if (is_negative) {
+ fprintf(stderr, "[warning] Fallback to [sec.ns] for printing negative time value. Use --clock-seconds.\n");
+ goto seconds;
+ }
if (!opt_clock_gmt) {
struct tm *res;
}
/* Print time in HH:MM:SS.ns */
fprintf(fp, "%02d:%02d:%02d.%09" PRIu64,
- tm.tm_hour, tm.tm_min, tm.tm_sec, ts_nsec);
+ tm.tm_hour, tm.tm_min, tm.tm_sec, ts_nsec_abs);
goto end;
}
seconds:
- fprintf(fp, "%3" PRIu64 ".%09" PRIu64,
- ts_sec, ts_nsec);
+ fprintf(fp, "%s%" PRId64 ".%09" PRIu64,
+ is_negative ? "-" : "", ts_sec_abs, ts_nsec_abs);
end:
return;
void ctf_print_timestamp(FILE *fp,
struct ctf_stream_definition *stream,
- uint64_t timestamp)
+ int64_t timestamp)
{
if (opt_clock_cycles) {
ctf_print_timestamp_cycles(fp, stream, timestamp);
assert(0);
}
+ if (pos->cur_index >= pos->packet_index->len) {
+ pos->offset = EOF;
+ return;
+ }
+
packet_index = &g_array_index(pos->packet_index,
struct packet_index, pos->cur_index);
if (pos->cur_index > 0) {
ctf_update_current_packet_index(&file_stream->parent,
prev_index, packet_index);
- if (pos->cur_index >= pos->packet_index->len) {
- pos->offset = EOF;
- return;
- }
-
/*
* We need to check if we are in trace read or called
* from packet indexing. In this last case, the
}
default:
goto warning;
-
+
}
/* eventually return an error instead of warning */
uint8_t uuidval[BABELTRACE_UUID_LEN];
field = bt_struct_definition_get_field_from_index(file_stream->parent.trace_packet_header, len_index);
- assert(field->declaration->id == CTF_TYPE_ARRAY);
+ assert(field->declaration->id == BT_CTF_TYPE_ID_ARRAY);
defarray = container_of(field, struct definition_array, p);
assert(bt_array_len(defarray) == BABELTRACE_UUID_LEN);
ret = -EINVAL;
goto error;
}
- stream->trace_packet_header =
+ stream->trace_packet_header =
container_of(definition, struct definition_struct, p);
stream->parent_def_scope = stream->trace_packet_header->p.scope;
}
struct dirent *dirent;
struct dirent *diriter;
size_t dirent_len;
+ int pc_name_max;
char *ext;
td->flags = flags;
* the stream array.
*/
- dirent_len = offsetof(struct dirent, d_name) +
- fpathconf(td->dirfd, _PC_NAME_MAX) + 1;
+ pc_name_max = fpathconf(td->dirfd, _PC_NAME_MAX);
+ if (pc_name_max < 0) {
+ perror("Error on fpathconf");
+ fprintf(stderr, "[error] Failed to get _PC_NAME_MAX for path \"%s\".\n", path);
+ ret = -1;
+ goto error_metadata;
+ }
+
+ dirent_len = offsetof(struct dirent, d_name) + pc_name_max + 1;
dirent = malloc(dirent_len);