@@ -52,9 +52,13 @@ class PackCommand : public Command {
52
52
53
53
PackCommand PackCommand::singleton (
54
54
" pack" ,
55
- " rr pack [OPTION]... [<trace-dir> ]\n "
55
+ " rr pack [OPTION]... [<trace-dirs>... ]\n "
56
56
" --symlink Create symlinks to all mmapped files\n "
57
57
" 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 "
58
62
" \n "
59
63
" Eliminates duplicate files in the trace directory, and copies files into\n "
60
64
" 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,
671
675
}
672
676
}
673
677
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
+ }
681
686
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);
689
694
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
+ }
701
706
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
+ }
704
710
}
705
711
706
712
return 0 ;
@@ -733,23 +739,22 @@ static bool parse_pack_arg(vector<string>& args, PackFlags& flags) {
733
739
}
734
740
735
741
int PackCommand::run (vector<string>& args) {
736
- bool found_dir = false ;
737
- string trace_dir;
738
742
PackFlags flags;
739
743
740
744
while (parse_pack_arg (args, flags)) {
741
745
}
742
746
747
+ vector<string> trace_dirs;
743
748
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 ;
747
753
}
748
- print_help (stderr);
749
- return 1 ;
754
+ trace_dirs.push_back (trace_dir);
750
755
}
751
756
752
- return pack (trace_dir , flags);
757
+ return pack (trace_dirs , flags);
753
758
}
754
759
755
760
} // namespace rr
0 commit comments