Skip to content

Commit cfa2803

Browse files
committed
Follow up addition of --pack-dir
This follows up the recently merged rr-debugger#3735 by: 1. Adding --pack-dir to the help 2. Allowing `pack` to take multiple directories to pack to make the argument useful. 3. Adding a test for the option.
1 parent 04c5add commit cfa2803

File tree

4 files changed

+77
-38
lines changed

4 files changed

+77
-38
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,7 @@ set(TESTS_WITHOUT_PROGRAM
17191719
nested_detach_kill
17201720
nested_detach_stop
17211721
nested_release
1722+
pack_dir
17221723
parent_no_break_child_bkpt
17231724
parent_no_stop_child_crash
17241725
post_exec_fpu_regs

src/PackCommand.cc

+41-36
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,13 @@ class PackCommand : public Command {
5252

5353
PackCommand PackCommand::singleton(
5454
"pack",
55-
" rr pack [OPTION]... [<trace-dir>]\n"
55+
" rr pack [OPTION]... [<trace-dirs>...]\n"
5656
" --symlink Create symlinks to all mmapped files\n"
5757
" instead of copying them.\n"
58+
" --pack-dir=<path> Specify a directory in which to pack common files.\n"
59+
" This helps conserve space when packing multiple traces\n"
60+
" with common files. Both the trace dir and pack dir\n"
61+
" (at the same relative path) are required for replay\n"
5862
"\n"
5963
"Eliminates duplicate files in the trace directory, and copies files into\n"
6064
"the trace directory as necessary to ensure that all needed files are in\n"
@@ -671,36 +675,38 @@ static void delete_unnecessary_files(const map<string, string>& file_map,
671675
}
672676
}
673677

674-
static int pack(const string& trace_dir, const PackFlags& flags) {
675-
string dir;
676-
{
677-
// validate trace and produce default trace directory if trace_dir is empty
678-
TraceReader reader(trace_dir);
679-
dir = reader.dir();
680-
}
678+
static int pack(const vector<string>& trace_dirs, const PackFlags& flags) {
679+
for (const string &trace_dir : trace_dirs) {
680+
string dir;
681+
{
682+
// validate trace and produce default trace directory if trace_dir is empty
683+
TraceReader reader(trace_dir);
684+
dir = reader.dir();
685+
}
681686

682-
PackDir pack_dir(flags.pack_dir);
683-
char buf[PATH_MAX];
684-
char* ret = realpath(dir.c_str(), buf);
685-
if (!ret) {
686-
FATAL() << "realpath failed on " << dir;
687-
}
688-
string abspath(buf);
687+
PackDir pack_dir(flags.pack_dir);
688+
char buf[PATH_MAX];
689+
char* ret = realpath(dir.c_str(), buf);
690+
if (!ret) {
691+
FATAL() << "realpath failed on " << dir;
692+
}
693+
string abspath(buf);
689694

690-
if (flags.symlink) {
691-
map<string, string> canonical_symlink_map =
692-
compute_canonical_symlink_map(abspath);
693-
rewrite_mmaps(canonical_symlink_map, abspath);
694-
delete_unnecessary_files(canonical_symlink_map, abspath);
695-
} else {
696-
map<string, string> canonical_mmapped_files =
697-
compute_canonical_mmapped_files(abspath, pack_dir);
698-
rewrite_mmaps(canonical_mmapped_files, abspath);
699-
delete_unnecessary_files(canonical_mmapped_files, abspath);
700-
}
695+
if (flags.symlink) {
696+
map<string, string> canonical_symlink_map =
697+
compute_canonical_symlink_map(abspath);
698+
rewrite_mmaps(canonical_symlink_map, abspath);
699+
delete_unnecessary_files(canonical_symlink_map, abspath);
700+
} else {
701+
map<string, string> canonical_mmapped_files =
702+
compute_canonical_mmapped_files(abspath, pack_dir);
703+
rewrite_mmaps(canonical_mmapped_files, abspath);
704+
delete_unnecessary_files(canonical_mmapped_files, abspath);
705+
}
701706

702-
if (!probably_not_interactive(STDOUT_FILENO)) {
703-
printf("rr: Packed trace directory `%s'.\n", dir.c_str());
707+
if (!probably_not_interactive(STDOUT_FILENO)) {
708+
printf("rr: Packed trace directory `%s'.\n", dir.c_str());
709+
}
704710
}
705711

706712
return 0;
@@ -733,23 +739,22 @@ static bool parse_pack_arg(vector<string>& args, PackFlags& flags) {
733739
}
734740

735741
int PackCommand::run(vector<string>& args) {
736-
bool found_dir = false;
737-
string trace_dir;
738742
PackFlags flags;
739743

740744
while (parse_pack_arg(args, flags)) {
741745
}
742746

747+
vector<string> trace_dirs;
743748
while (!args.empty()) {
744-
if (!found_dir && parse_optional_trace_dir(args, &trace_dir)) {
745-
found_dir = true;
746-
continue;
749+
string trace_dir;
750+
if (!parse_optional_trace_dir(args, &trace_dir)) {
751+
print_help(stderr);
752+
return 1;
747753
}
748-
print_help(stderr);
749-
return 1;
754+
trace_dirs.push_back(trace_dir);
750755
}
751756

752-
return pack(trace_dir, flags);
757+
return pack(trace_dirs, flags);
753758
}
754759

755760
} // namespace rr

src/test/pack_dir.run

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
source `dirname $0`/util.sh
2+
3+
record simple$bitness
4+
record simple$bitness
5+
6+
mkdir the_pack_dir
7+
8+
# Pack both directories with a common pack directory
9+
pack --pack-dir the_pack_dir simple$bitness-$nonce-0 simple$bitness-$nonce-1
10+
11+
# Test that we can still replay both traces
12+
replay simple$bitness-$nonce-0
13+
check EXIT-SUCCESS
14+
rm replay.err replay.out
15+
16+
replay simple$bitness-$nonce-1
17+
check EXIT-SUCCESS
18+
rm replay.err replay.out
19+
20+
# Check that we can move all three directories somewhere else and replay
21+
# still works.
22+
mkdir a_subdirectory
23+
mv the_pack_dir simple$bitness-$nonce-0 simple$bitness-$nonce-1 a_subdirectory
24+
25+
replay a_subdirectory/simple$bitness-$nonce-0
26+
check EXIT-SUCCESS
27+
rm replay.err replay.out
28+
29+
replay a_subdirectory/simple$bitness-$nonce-1
30+
check EXIT-SUCCESS
31+
rm replay.err replay.out

src/test/util.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,11 @@ function rerun { rerunflags=$1
327327
$RR_EXE $GLOBAL_OPTIONS rerun $rerunflags 1> rerun.out 2> rerun.err
328328
}
329329

330-
function pack { packflags=$1
330+
function pack {
331+
_RR_TRACE_DIR="$workdir" echo test-monitor $TIMEOUT pack.err \
332+
$RR_EXE $GLOBAL_OPTIONS pack $@
331333
_RR_TRACE_DIR="$workdir" test-monitor $TIMEOUT pack.err \
332-
$RR_EXE $GLOBAL_OPTIONS pack $packflags 1> pack.out 2> pack.err
334+
$RR_EXE $GLOBAL_OPTIONS pack $@ 1> pack.out 2> pack.err
333335
}
334336

335337
function do_ps { psflags=$1

0 commit comments

Comments
 (0)