summaryrefslogtreecommitdiff
path: root/cachegrind
diff options
context:
space:
mode:
authornjn <njn@a5019735-40e9-0310-863c-91ae7b9d1cf9>2008-05-29 23:09:52 +0000
committernjn <njn@a5019735-40e9-0310-863c-91ae7b9d1cf9>2008-05-29 23:09:52 +0000
commit7064fb280267d51e3f7f398f22d0e4800ec969e4 (patch)
tree835649cd6ab608cbc80d31b64756175a45fba1ec /cachegrind
parent89230cace4f5acad8037e4cb4b3e49e83d3a275b (diff)
Fix a bug in Massif and Cachegrind, whereby if program's forked, the child
wrote into the parent's output file even if %p was specified. Josef, I think Callgrind does not have this bug, but you might want to say something about forking in the manual, as I have done for Massif and Cachegrind. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8154 a5019735-40e9-0310-863c-91ae7b9d1cf9
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>