Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

info: Add utc_offset info for external usage #1923

Merged
merged 1 commit into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmds/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ static void dump_raw_header(struct uftrace_dump_ops *ops, struct uftrace_data *h
const char *info_str[] = { "EXE_NAME", "EXE_BUILD_ID", "EXIT_STATUS", "CMDLINE",
"CPUINFO", "MEMINFO", "OSINFO", "TASKINFO",
"USAGEINFO", "LOADINFO", "ARG_SPEC", "RECORD_DATE",
"PATTERN_TYPE", "VERSION" };
"PATTERN_TYPE", "VERSION", "UTC_OFFSET" };

pr_out("uftrace file header: magic = ");
for (i = 0; i < UFTRACE_MAGIC_LEN; i++)
Expand Down
38 changes: 38 additions & 0 deletions cmds/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,41 @@ static int read_uftrace_version(void *arg)
return 0;
}

static int fill_utc_offset(void *arg)
{
struct fill_handler_arg *fha = arg;
time_t current_time;
struct timespec ts;
long offset;

time(&current_time);
clock_gettime(clock_source, &ts);

/* calculate time offset between UTC and clock_source. */
offset = (long)difftime(current_time, ts.tv_sec);

dprintf(fha->fd, "utc_offset:%ld\n", offset);
return 0;
}

static int read_utc_offset(void *arg)
{
struct read_handler_arg *rha = arg;
struct uftrace_data *handle = rha->handle;
struct uftrace_info *info = &handle->info;
char *buf = rha->buf;

if (fgets(buf, sizeof(rha->buf), handle->fp) == NULL)
return -1;

if (strncmp(buf, "utc_offset:", 11))
return -1;

info->utc_offset = copy_info_str(&buf[11]);

return 0;
}

struct uftrace_info_handler {
enum uftrace_info_bits bit;
int (*handler)(void *arg);
Expand Down Expand Up @@ -883,6 +918,7 @@ void fill_uftrace_info(uint64_t *info_mask, int fd, struct uftrace_opts *opts, i
{ RECORD_DATE, fill_record_date },
{ PATTERN_TYPE, fill_pattern_type },
{ VERSION, fill_uftrace_version },
{ UTC_OFFSET, fill_utc_offset },
};

for (i = 0; i < ARRAY_SIZE(fill_handlers); i++) {
Expand Down Expand Up @@ -926,6 +962,7 @@ int read_uftrace_info(uint64_t info_mask, struct uftrace_data *handle)
{ RECORD_DATE, read_record_date },
{ PATTERN_TYPE, read_pattern_type },
{ VERSION, read_uftrace_version },
{ UTC_OFFSET, read_utc_offset },
};

memset(&handle->info, 0, sizeof(handle->info));
Expand Down Expand Up @@ -955,6 +992,7 @@ void clear_uftrace_info(struct uftrace_info *info)
free(info->argspec);
free(info->record_date);
free(info->elapsed_time);
free(info->utc_offset);
free(info->uftrace_version);
free(info->retspec);
free(info->autoarg);
Expand Down
3 changes: 3 additions & 0 deletions uftrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ enum uftrace_info_bits {
RECORD_DATE_BIT,
PATTERN_TYPE_BIT,
VERSION_BIT,
UTC_OFFSET_BIT,

INFO_BIT_MAX,

Expand All @@ -116,6 +117,7 @@ enum uftrace_info_bits {
RECORD_DATE = (1U << RECORD_DATE_BIT),
PATTERN_TYPE = (1U << PATTERN_TYPE_BIT),
VERSION = (1U << VERSION_BIT),
UTC_OFFSET = (1U << UTC_OFFSET_BIT),
};

struct uftrace_info {
Expand All @@ -142,6 +144,7 @@ struct uftrace_info {
double utime;
char *record_date;
char *elapsed_time;
char *utc_offset;
long vctxsw;
long ictxsw;
long maxrss;
Expand Down