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

uftrace: Improve logfile creation location #1971

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 8 additions & 5 deletions cmds/record.c
Original file line number Diff line number Diff line change
Expand Up @@ -1423,12 +1423,15 @@ static void send_event_file(int sock, const char *dirname)
send_trace_metadata(sock, dirname, "events.txt");
}

static void send_log_file(int sock, const char *logfile)
static void send_log_file(int sock, const char *dirname, const char *logfile)
{
if (access(logfile, F_OK) != 0)
char *logfile_path = NULL;
xasprintf(&logfile_path, "%s/%s", dirname, logfile);

if (access(logfile_path, F_OK) != 0)
return;

send_trace_metadata(sock, NULL, (char *)logfile);
send_trace_metadata(sock, dirname, (char *)logfile);
}

static void update_session_maps(struct uftrace_opts *opts)
Expand Down Expand Up @@ -2070,7 +2073,7 @@ static void write_symbol_files(struct writer_data *wd, struct uftrace_opts *opts
if (opts->event)
send_event_file(sock, opts->dirname);
if (opts->logfile)
send_log_file(sock, opts->logfile);
send_log_file(sock, opts->dirname, opts->logfile);

send_trace_end(sock);
close(sock);
Expand Down Expand Up @@ -2275,7 +2278,7 @@ int command_record(int argc, char *argv[], struct uftrace_opts *opts)
check_perf_event(opts);

if (!opts->nop) {
if (create_directory(opts->dirname) < 0)
if (!opts->logfile && (create_directory(opts->dirname) < 0))
return -1;

xasprintf(&channel, "%s/%s", opts->dirname, ".channel");
Expand Down
19 changes: 17 additions & 2 deletions uftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,16 @@ int main(int argc, char *argv[])
debug = 1;

if (opts.logfile) {
logfp = fopen(opts.logfile, "a");
char *logfile_path = NULL;
if (create_directory(opts.dirname) < 0) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this. Creating directory includes renaming the existing directory. This can be a problem either you create a new one for record or dealing with an existing one for replay.

ret = -1;
goto cleanup;
}

xasprintf(&logfile_path, "%s/%s", opts.dirname, opts.logfile);
logfp = fopen(logfile_path, "a");
free(logfile_path);

if (logfp == NULL) {
logfp = stderr;
pr_err("cannot open log file");
Expand Down Expand Up @@ -1583,9 +1592,15 @@ int main(int argc, char *argv[])
wait_for_pager();

cleanup:
if (opts.logfile)
if (opts.logfile) {
char *logfile_path = NULL;
fclose(logfp);

xasprintf(&logfile_path, "%s/%s", opts.dirname, opts.logfile);
copy_file(opts.logfile, logfile_path);

free(logfile_path);
}
if (opts.opt_file)
free_parsed_cmdline(argv - opts.idx);

Expand Down