On Tue, Mar 26, 2019 at 5:07 PM Tzvetomir Stoyanov <tstoyanov@xxxxxxxxxx> wrote: <snip> > +static int tsync_offset_cmp(const void *a, const void *b) > +{ > + struct ts_offset_sample *ts_a = (struct ts_offset_sample *)a; > + struct ts_offset_sample *ts_b = (struct ts_offset_sample *)b; > + > + if (ts_a->time > ts_b->time) > + return 1; > + if (ts_a->time < ts_b->time) > + return -1; > + return 0; > +} > + > +static void tsync_offset_load(struct tracecmd_input *handle, char *buf) > +{ > + int i, j; > + long long *buf8 = (long long *)buf; > + > + for (i = 0; i < handle->ts_samples_count; i++) { > + handle->ts_samples[i].time = tep_read_number(handle->pevent, > + buf8+i, 8); > + handle->ts_samples[i].offset = tep_read_number(handle->pevent, > + buf8+handle->ts_samples_count+i, 8); > + } > + qsort(handle->ts_samples, > + handle->ts_samples_count, sizeof(struct ts_offset_sample), > + tsync_offset_cmp); > + /* Filter possible samples with equal time */ > + for (i = 0, j = 0; i < handle->ts_samples_count; i++) { > + if (i == 0 || > + handle->ts_samples[i].time != handle->ts_samples[i-1].time) { > + handle->ts_samples[j++] = handle->ts_samples[i]; > + } > + } handle->ts_samples_count is never corrected here in case there are samples with duplicate timestamps. handle->ts_samples_count = j; > +} > + > static int handle_options(struct tracecmd_input *handle) > { > long long offset; > @@ -2111,6 +2213,7 @@ static int handle_options(struct tracecmd_input *handle) > struct input_buffer_instance *buffer; > struct hook_list *hook; > char *buf; > + int tsync; Nit: s/tsync/sampes_size? > int cpus; > > for (;;) { > @@ -2155,6 +2258,25 @@ static int handle_options(struct tracecmd_input *handle) > offset = strtoll(buf, NULL, 0); > handle->ts_offset += offset; > break; > + case TRACECMD_OPTION_TIME_SHIFT: > + /* > + * int (4 bytes) count of timestamp offsets. > + * long long array of size [count] of times, > + * when the offsets were calculated. > + * long long array of size [count] of timestamp offsets. > + */ > + if (handle->flags & TRACECMD_FL_IGNORE_DATE) > + break; > + handle->ts_samples_count = tep_read_number(handle->pevent, > + buf, 4); > + tsync = (sizeof(long long)*handle->ts_samples_count); > + if (size != (4+(2*tsync))) > + break; > + handle->ts_samples = malloc(2*tsync); > + if (!handle->ts_samples) > + return -ENOMEM; > + tsync_offset_load(handle, buf+4); > + break; > case TRACECMD_OPTION_CPUSTAT: > buf[size-1] = '\n'; > cpustats = realloc(cpustats, cpustats_size + size + 1); > -- > 2.20.1 >
![]() |