summaryrefslogtreecommitdiff
path: root/cachegrind
diff options
context:
space:
mode:
Diffstat (limited to 'cachegrind')
-rw-r--r--cachegrind/cg_main.c17
-rw-r--r--cachegrind/docs/cg-manual.xml13
2 files changed, 23 insertions, 7 deletions
diff --git a/cachegrind/cg_main.c b/cachegrind/cg_main.c
index dcfa79c0..bd683255 100644
--- a/cachegrind/cg_main.c
+++ b/cachegrind/cg_main.c
@@ -1256,9 +1256,6 @@ static CacheCC Dw_total;
static BranchCC Bc_total;
static BranchCC Bi_total;
-// The output file name. Controlled by --cachegrind-out-file.
-static Char* cachegrind_out_file = NULL;
-
static void fprint_CC_table_and_calc_totals(void)
{
Int i, fd;
@@ -1266,6 +1263,14 @@ static void fprint_CC_table_and_calc_totals(void)
Char buf[512], *currFile = NULL, *currFn = NULL;
LineCC* lineCC;
+ // Setup output filename. Nb: it's important to do this now, ie. as late
+ // as possible. If we do it at start-up and the program forks and the
+ // output file format string contains a %p (pid) specifier, both the
+ // parent and child will incorrectly write to the same file; this
+ // happened in 3.3.0.
+ Char* cachegrind_out_file =
+ VG_(expand_file_name)("--cachegrind-out-file", clo_cachegrind_out_file);
+
sres = VG_(open)(cachegrind_out_file, VKI_O_CREAT|VKI_O_TRUNC|VKI_O_WRONLY,
VKI_S_IRUSR|VKI_S_IWUSR);
if (sres.isError) {
@@ -1276,9 +1281,11 @@ static void fprint_CC_table_and_calc_totals(void)
cachegrind_out_file );
VG_(message)(Vg_UserMsg,
" ... so simulation results will be missing.");
+ VG_(free)(cachegrind_out_file);
return;
} else {
fd = sres.res;
+ VG_(free)(cachegrind_out_file);
}
// "desc:" lines (giving I1/D1/L2 cache configuration). The spaces after
@@ -1752,10 +1759,6 @@ static void cg_post_clo_init(void)
VG_(exit)(2);
}
- // Setup output filename.
- cachegrind_out_file =
- VG_(expand_file_name)("--cachegrind-out-file", clo_cachegrind_out_file);
-
CC_table =
VG_(OSetGen_Create)(offsetof(LineCC, loc),
cmp_CodeLoc_LineCC,
diff --git a/cachegrind/docs/cg-manual.xml b/cachegrind/docs/cg-manual.xml
index 30857fa9..7c1764e0 100644
--- a/cachegrind/docs/cg-manual.xml
+++ b/cachegrind/docs/cg-manual.xml
@@ -820,6 +820,19 @@ way as for C/C++ programs.</para>
</sect2>
+<sect2 id="ms-manual.forkingprograms" xreflabel="Forking Programs">
+<title>Forking Programs</title>
+<para>If your program forks, the child will inherit all the profiling data that
+has been gathered for the parent.</para>
+
+<para>If the output file format string (controlled by
+<option>--cachegrind-out-file</option>) does not contain <option>%p</option>,
+then the outputs from the parent and child will be intermingled in a single
+output file, which will almost certainly make it unreadable by
+cg_annotate.</para>
+</sect2>
+
+
</sect1>