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

Add --save-as param to record #3787

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

theIDinside
Copy link
Contributor

This is a resend of PR ##3576 because I messed that one up @GitMensch || @rocallahan

This PR is rebased onto master and also added test cases for the feature.

--save-as specifies the trace dir name (basename?), not the full path.

Merged output_trace_dir in RecordFlags with name into new type TraceOutputPath.

Changed all usage of output_trace_dir string to use this type instead.

This PR is backwards compatible, in the sense that the old usage of the -o flag remains the same, if --save-as is not provided, i.e., will error out, if dir exists etc. If --save-as is provided together with -o the new behavior will happen instead, where the output dir will be the "root dir", thus, the user can save many traces there.

If only --save-as is provided, record uses normal behavior, of setting the trace root dir to $RR_TRACE_DIR (or it's user provided env var).

Naming of user provided dirs, follows old behavior, i.e. appending -0, -1, -2 etc to the trace dir. I think this is preferable - if some automated thing is recording something with a specific name provided, this makes it so the end user don't have to manage the file system (i.e. checking if that name is "taken" and having to do clean up before recording, etc.)

Added test cases

@@ -663,6 +663,12 @@ void replace_in_buffer(MemoryRange src, const uint8_t* src_data,

// Strip any directory part from the filename `s`
void base_name(std::string& s);
struct TraceOutputPath {
std::string output_trace_dir;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please carefully document these fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See new comments added to the type - are they enough?

@GitMensch
Copy link
Contributor

@theIDinside can you please debug the new elements in util.h as requested and rebase, so that we may see that be integrated?

`--save-as` specifies the trace dir name (basename?), not the full path.

Merged `output_trace_dir` in RecordFlags with `name` into new type `TraceOutputPath`.

Changed all usage of `output_trace_dir` string to use this type instead.

This PR is backwards compatible, in the sense that the old usage
of the `-o` flag remains the same, if `--save-as` is not provided, i.e.,
will error out, if dir exists etc. If `--save-as` is provided together
with `-o` the new behavior will happen instead, where the output dir
will be the "root dir", thus, the user can save many traces there.

If only `--save-as` is provided, record uses normal behavior, of setting
the trace root dir to $RR_TRACE_DIR (or it's user provided env var).

Naming of user provided dirs, follows old behavior, i.e. appending -0,
-1, -2 etc to the trace dir. I think this is preferable - if some
automated thing is recording something with a specific name provided,
this makes it so the end user don't have to manage the file system (i.e.
checking if that name is "taken" and having to do clean up before
recording, etc.)

Added test cases
@theIDinside
Copy link
Contributor Author

@theIDinside can you please debug the new elements in util.h as requested and rebase, so that we may see that be integrated?

Rebased it and added documentation to the fields

@rocallahan
Copy link
Collaborator

Under what circumstances would someone want to use this feature?

@GitMensch
Copy link
Contributor

Under what circumstances would someone want to use this feature?

currently the default name is derived from the binary name; with --save-as we can make this specific, in my scenario there's a single binary which loads different programs - and those are the relevant ones which can now be named easily.

@rocallahan
Copy link
Collaborator

I think the behaviour implemented in this PR is confusing. Currently the setup is relatively simple: you can override the default trace base directory (where new traces are added with their default names) with _RR_TRACE_DIR, or you can specify a full trace directory including its trace name with -o, which means _RR_TRACE_DIR is ignored. As I understand it, this PR intends to add an option to override just the trace name, using the normal trace base directory (possibly overridden by _RR_TRACE_DIR). But I think that is fundamentally incompatible with using -o. I don't understand why you want to make this work with -o.

Note that you can get the effect of this PR by creating a symbolic link to the binary to record with the desired name.

@GitMensch
Copy link
Contributor

I think the following solution would work, but think something is missing:

  • -o as a (relative or absolute) path (= ending with a slash or pointing to an ISDIR) -> specifies the path (instead of _RR_TRACE_DIR), name is derived from the binary
  • -o as a (relative or absolute) path (= not ending with a slash or pointing to an !ISDIR) -> specifies the path (instead of _RR_TRACE_DIR)
  • -o as a simple name (no slash included) uses the default place / _RR_TRACE_DIR

Ideally, in each of those cases the "number suffix" is only done as a replacement (like !! or !n) with possibly more replacements (like !p for the process id under trace, if this is possible).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants