|
From: <sv...@va...> - 2007-02-07 19:55:39
|
Author: sewardj
Date: 2007-02-07 19:55:30 +0000 (Wed, 07 Feb 2007)
New Revision: 6572
Log:
* Add new flag --cachegrind-out-file to specify the output file
basename to be something other than "cachegrind.out".
* Observe the core-supplied --log-file-qualifier, if specified,
in creation of output file names.
* To make the above work, move most of the stuff in cg_pre_clo_init
into cg_post_clo_init, so that the core's determination of the
log file qualifier, if any, is done by the time cachegrind comes
to process its arguments.
Modified:
trunk/cachegrind/cg_main.c
trunk/cachegrind/docs/cg-manual.xml
Modified: trunk/cachegrind/cg_main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/cachegrind/cg_main.c 2007-02-07 19:50:55 UTC (rev 6571)
+++ trunk/cachegrind/cg_main.c 2007-02-07 19:55:30 UTC (rev 6572)
@@ -977,8 +977,17 @@
static CC Dr_total;
static CC Dw_total;
=20
-static Char* cachegrind_out_file;
+// The output file base name specified by the user using the
+// --cachegrind-out-file switch. This is combined with the
+// process ID and optional user-supplied qualifier (from=20
+// --log-file-qualifier) to produce the name stored in=20
+// cachegrind_out_file.
+static Char* cachegrind_out_file_basename =3D "cachegrind.out";
=20
+// The final, completed name for the output file.
+static Char* cachegrind_out_file =3D NULL;
+
+
static void fprint_CC_table_and_calc_totals(void)
{
Int i, fd;
@@ -1296,6 +1305,9 @@
parse_cache_opt(&clo_D1_cache, &arg[5]);
else if (VG_CLO_STREQN(5, arg, "--L2=3D"))
parse_cache_opt(&clo_L2_cache, &arg[5]);
+ else if (VG_CLO_STREQN(22, arg, "--cachegrind-out-file=3D")) {
+ cachegrind_out_file_basename =3D &arg[22];
+ }
else
return False;
=20
@@ -1308,6 +1320,8 @@
" --I1=3D<size>,<assoc>,<line_size> set I1 cache manually\n"
" --D1=3D<size>,<assoc>,<line_size> set D1 cache manually\n"
" --L2=3D<size>,<assoc>,<line_size> set L2 cache manually\n"
+" --cachegrind-out-file=3D<file> write profile data to <file>.<pi=
d>\n"
+" [cachegrind.out.<pid>]\n"
);
}
=20
@@ -1322,19 +1336,10 @@
/*--- Setup ---*/
/*--------------------------------------------------------------------*/
=20
-static void cg_post_clo_init(void)
-{
- cache_t I1c, D1c, L2c;=20
+static Char base_dir[VKI_PATH_MAX];
=20
- configure_caches(&I1c, &D1c, &L2c);
+static void cg_post_clo_init(void); /* just below */
=20
- cachesim_I1_initcache(I1c);
- cachesim_D1_initcache(D1c);
- cachesim_L2_initcache(L2c);
-}
-
-static Char base_dir[VKI_PATH_MAX];
-
static void cg_pre_clo_init(void)
{
VG_(details_name) ("Cachegrind");
@@ -1353,15 +1358,50 @@
VG_(needs_command_line_options)(cg_process_cmd_line_option,
cg_print_usage,
cg_print_debug_usage);
+}
=20
+static void cg_post_clo_init(void)
+{
+ HChar* qual =3D NULL;
+ cache_t I1c, D1c, L2c;=20
+ Int filename_szB;
+
/* Get working directory */
tl_assert( VG_(getcwd)(base_dir, VKI_PATH_MAX) );
=20
- /* Block is big enough for dir name + cachegrind.out.<pid> */
- cachegrind_out_file =3D VG_(malloc)((VG_(strlen)(base_dir) + 32)*size=
of(Char));
- VG_(sprintf)(cachegrind_out_file, "%s/cachegrind.out.%d",
- base_dir, VG_(getpid)());
+ /* Do we have a --log-file-qualifier=3D to consider? */
+ if (VG_(clo_log_file_qualifier)) {
+ qual =3D VG_(getenv)(VG_(clo_log_file_qualifier));
+ }
=20
+ /* Block is big enough for=20
+ dir name ++ cachegrind_out_file_basename
+ ++ ".<pid>"=20
+ ++ the log file qualifier, if in use */
+ filename_szB=20
+ =3D VG_(strlen)(base_dir)=20
+ + 1 /* "/" */
+ + VG_(strlen)(cachegrind_out_file_basename)
+ + 11 /* "." <pid>, assuming sizeof(pid) <=3D 4 */
+ + (qual ? (10 + VG_(strlen)(qual)) : 0)
+ + 1; /* to guarantee checkable zero at the end */
+
+ tl_assert(filename_szB > 0);
+ cachegrind_out_file=20
+ =3D VG_(calloc)( sizeof(Char), filename_szB );
+
+ if (qual) {
+ VG_(sprintf)(cachegrind_out_file, "%s/%s.%d.lfq.%s",
+ base_dir, cachegrind_out_file_basename,=20
+ VG_(getpid)(), qual);
+ } else {
+ VG_(sprintf)(cachegrind_out_file, "%s/%s.%d",
+ base_dir, cachegrind_out_file_basename,=20
+ VG_(getpid)());
+ }
+
+ tl_assert( cachegrind_out_file[filename_szB-1] =3D=3D 0 );
+
CC_table =3D VG_(OSet_Create)(offsetof(LineCC, loc),
cmp_CodeLoc_LineCC,
VG_(malloc), VG_(free));
@@ -1371,6 +1411,12 @@
stringTable =3D VG_(OSet_Create)(/*keyOff*/0,
stringCmp,
VG_(malloc), VG_(free));
+
+ configure_caches(&I1c, &D1c, &L2c);
+
+ cachesim_I1_initcache(I1c);
+ cachesim_D1_initcache(D1c);
+ cachesim_L2_initcache(L2c);
}
=20
VG_DETERMINE_INTERFACE_VERSION(cg_pre_clo_init)
Modified: trunk/cachegrind/docs/cg-manual.xml
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/cachegrind/docs/cg-manual.xml 2007-02-07 19:50:55 UTC (rev 6571=
)
+++ trunk/cachegrind/docs/cg-manual.xml 2007-02-07 19:55:30 UTC (rev 6572=
)
@@ -257,9 +257,10 @@
<title>Output file</title>
=20
<para>As well as printing summary information, Cachegrind also
-writes line-by-line cache profiling information to a file named
+writes line-by-line cache profiling information to a user-specified
+file. By default this file is named
<computeroutput>cachegrind.out.pid</computeroutput>. This file
-is human-readable, but is best interpreted by the accompanying
+is human-readable, but is intended to be interpreted by the accompanying
program <computeroutput>cg_annotate</computeroutput>, described
in the next section.</para>
=20
@@ -275,6 +276,15 @@
in the current directory (but that won't happen very often
because it takes some time for process ids to be
recycled).</para>
+ <para>
+ To use a basename other than the default
+ <computeroutput>cachegrind.out.</computeroutput>,
+ use the <computeroutput>--cachegrind-out-file</computeroutput>
+ switch.</para>
+ <para>
+ To add further qualifiers to the output filename you can use=20
+ the core's <computeroutput>--log-file-qualifier</computeroutput>
+ flag.</para>
</listitem>
<listitem>
<para>It can be huge: <computeroutput>ls -l</computeroutput>
@@ -344,6 +354,18 @@
</listitem>
</varlistentry>
=20
+ <varlistentry id=3D"opt.cachegrind-out-file" xreflabel=3D"--cachegrind=
-out-file">
+ <term>
+ <option><![CDATA[--cachegrind-out-file=3D<basename> ]]></option>
+ </term>
+ <listitem>
+ <para>Write the profile data to <![CDATA[<basename>.<pid>]]>
+ rather than to the default output file,=20
+ <![CDATA[cachegrind.out.<pid>]]>.
+ </para>
+ </listitem>
+ </varlistentry>
+
</variablelist>
<!-- end of xi:include in the manpage -->
=20
|