aboutsummaryrefslogtreecommitdiff
path: root/gprofng
diff options
context:
space:
mode:
authorVladimir Mezentsev <vladimir.mezentsev@oracle.com>2024-05-20 19:08:39 -0700
committerVladimir Mezentsev <vladimir.mezentsev@oracle.com>2024-05-21 19:54:59 -0700
commit559f8726e8d2e2eb054163b8f6f8b0bc5e4f400d (patch)
tree2be107faca98aa64db2e062281b8e63f8b584626 /gprofng
parentaea1188a2579b4fcb296f62528b0685173e4cdc5 (diff)
downloadgdb-559f8726e8d2e2eb054163b8f6f8b0bc5e4f400d.zip
gdb-559f8726e8d2e2eb054163b8f6f8b0bc5e4f400d.tar.gz
gdb-559f8726e8d2e2eb054163b8f6f8b0bc5e4f400d.tar.bz2
gprofng: use StringBuilder to create long messages
ChangeLog 2024-05-20 Vladimir Mezentsev <vladimir.mezentsev@oracle.com> * src/collctrl.cc: Use StringBuilder to create messages. Remove unused variables and arrays. * src/collctrl.h: Remove unused variables.
Diffstat (limited to 'gprofng')
-rw-r--r--gprofng/src/collctrl.cc460
-rw-r--r--gprofng/src/collctrl.h2
2 files changed, 179 insertions, 283 deletions
diff --git a/gprofng/src/collctrl.cc b/gprofng/src/collctrl.cc
index 28fdb0b..7c0219b 100644
--- a/gprofng/src/collctrl.cc
+++ b/gprofng/src/collctrl.cc
@@ -42,7 +42,6 @@
#include "StringBuilder.h"
#define SP_GROUP_HEADER "#analyzer experiment group"
-#define DD_MAXPATHLEN (MAXPATHLEN * 4) /* large, to build up data descriptor */
/* If the system doesn't provide strsignal, we get it defined in
libiberty but no declaration is supplied. */
@@ -50,11 +49,6 @@
extern const char *strsignal (int);
#endif
-// _SC_CPUID_MAX is not available on 2.6/2.7
-#ifndef _SC_CPUID_MAX
-#define _SC_CPUID_MAX 517
-#endif
-
static const char *get_fstype (char *);
static cpu_info_t cpu_info;
@@ -70,7 +64,7 @@ read_str (char *from, char **to)
{
if (s[i] != '\n' && s[i] != ' ' && s[i] != '\t')
{
- *to = strndup(s, i + 1);
+ *to = strndup (s, i + 1);
return;
}
}
@@ -88,7 +82,7 @@ read_int (char *from)
}
cpu_info_t *
-read_cpuinfo()
+read_cpuinfo ()
{
static int inited = 0;
if (inited)
@@ -141,7 +135,6 @@ read_cpuinfo()
Coll_Ctrl::Coll_Ctrl (int _interactive, bool _defHWC, bool _kernelHWC)
{
char hostname[MAXPATHLEN];
- long ncpumax;
interactive = _interactive;
defHWC = _defHWC;
kernelHWC = _kernelHWC;
@@ -154,24 +147,12 @@ Coll_Ctrl::Coll_Ctrl (int _interactive, bool _defHWC, bool _kernelHWC)
*p = 0;
default_stem = strdup ("test");
- /* get CPU count and processor clock rate */
- ncpumax = sysconf (_SC_CPUID_MAX);
- if (ncpumax == -1)
- {
- ncpus = sysconf (_SC_NPROCESSORS_CONF);
- /* add 2048 to count, since on some systems CPUID does not start at zero */
- ncpumax = ncpus + 2048;
- }
- cpu_info_t *cpu_p = read_cpuinfo();
+ cpu_info_t *cpu_p = read_cpuinfo ();
ncpus = cpu_p->cpu_cnt;
cpu_clk_freq = cpu_p->cpu_clk_freq;
/* check resolution of system clock */
sys_resolution = sysconf (_SC_CLK_TCK);
- if (sys_resolution == 0)
- sys_period = 10000;
- else
- sys_period = MICROSEC / (int) sys_resolution;
/* determine memory page size and number of pages */
npages = sysconf (_SC_PHYS_PAGES);
@@ -238,7 +219,7 @@ Coll_Ctrl::Coll_Ctrl (int _interactive, bool _defHWC, bool _kernelHWC)
setup_hwc ();
hwcprof_default = 1;
}
- else // disable the default, and reset the counters
+ else // disable the default, and reset the counters
hwcprof_enabled_cnt = 0;
synctrace_enabled = 0;
synctrace_thresh = -1;
@@ -358,7 +339,6 @@ Coll_Ctrl::Coll_Ctrl (Coll_Ctrl * cc)
opened = 0;
nofswarn = cc->nofswarn;
sys_resolution = cc->sys_resolution;
- sys_period = cc->sys_period;
// ensure that the default name is updated
(void) preprocess_names ();
@@ -457,6 +437,7 @@ Coll_Ctrl::delete_expt ()
// Check the experiment settings for consistency. Returns NULL if OK,
// or an error message if there are invalid combinations of settings
+
char *
Coll_Ctrl::check_consistency ()
{
@@ -491,7 +472,7 @@ Coll_Ctrl::check_expt (char **warn)
char *ret;
*warn = NULL;
ret = check_consistency ();
- if (ret != NULL) /* something is wrong, return the error */
+ if (ret != NULL) /* something is wrong, return the error */
return ret;
/* check for heaptrace and java -- warn that it covers native allocations only */
if (heaptrace_enabled == 1 && java_mode == 1 && java_default == 0)
@@ -510,7 +491,7 @@ Coll_Ctrl::check_expt (char **warn)
store_dir, strerror (errno));
if (access (store_dir, W_OK) != 0)
return dbe_sprintf (GTXT ("Store directory %s is not writeable: %s\n"),
- store_dir, strerror (errno));
+ store_dir, strerror (errno));
/* if an experiment-group, verify that it can be written */
ret = check_group ();
@@ -522,218 +503,172 @@ Coll_Ctrl::check_expt (char **warn)
char *
Coll_Ctrl::show (int i)
{
- char UEbuf[4096];
- UEbuf[0] = 0;
+ StringBuilder sb;
if (i == 0)
{
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("Collection parameters:\n"));
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT (" experiment enabled\n"));
+ sb.append (GTXT ("Collection parameters:\n"));
+ sb.append (GTXT (" experiment enabled\n"));
}
if (target_name != NULL)
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\ttarget = %s\n"), target_name);
+ sb.appendf (GTXT ("\ttarget = %s\n"), target_name);
if (uexpt_name != NULL)
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tuser_expt_name = %s\n"), uexpt_name);
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\texpt_name = %s\n"),
- ((expt_name != NULL) ? expt_name : NTXT ("<NULL>")));
+ sb.appendf (GTXT ("\tuser_expt_name = %s\n"), uexpt_name);
+ sb.appendf (GTXT ("\texpt_name = %s\n"),
+ ((expt_name != NULL) ? expt_name : "<NULL>"));
if (udir_name != NULL)
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tdir_name = %s\n"), udir_name);
+ sb.appendf (GTXT ("\tdir_name = %s\n"), udir_name);
if (expt_group != NULL)
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\texpt_group = %s\n"), expt_group);
+ sb.appendf (GTXT ("\texpt_group = %s\n"), expt_group);
if (debug_mode == 1)
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tdebug_mode enabled\n"));
+ sb.append (GTXT ("\tdebug_mode enabled\n"));
if (clkprof_enabled != 0)
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tclock profiling enabled, %.3f millisec.\n"),
+ sb.appendf (GTXT ("\tclock profiling enabled, %.3f millisec.\n"),
(double) (clkprof_timer) / 1000.);
if (synctrace_enabled != 0)
{
if (synctrace_thresh < 0)
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tsynchronization tracing enabled, threshold: calibrate; "));
+ sb.append (GTXT ("\tsynchronization tracing enabled, threshold: calibrate; "));
else if (synctrace_thresh == 0)
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tsynchronization tracing enabled, threshold: all; "));
+ sb.append (GTXT ("\tsynchronization tracing enabled, threshold: all; "));
else
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tsynchronization tracing enabled, threshold: %d micros.; "), synctrace_thresh);
+ sb.appendf (GTXT ("\tsynchronization tracing enabled, threshold: %d micros.; "),
+ synctrace_thresh);
switch (synctrace_scope)
{
case SYNCSCOPE_NATIVE:
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("Native-APIs\n"));
+ sb.append (GTXT ("Native-APIs\n"));
break;
case SYNCSCOPE_JAVA:
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("Java-APIs\n"));
+ sb.append (GTXT ("Java-APIs\n"));
break;
case SYNCSCOPE_NATIVE | SYNCSCOPE_JAVA:
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("Native- and Java-APIs\n"));
+ sb.append (GTXT ("Native- and Java-APIs\n"));
break;
default:
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("ERR -- unexpected synctrace_scope %d\n"), synctrace_scope);
+ sb.appendf (GTXT ("ERR -- unexpected synctrace_scope %d\n"),
+ synctrace_scope);
break;
}
}
if (hwcprof_enabled_cnt != 0)
{
char ctrbuf[MAXPATHLEN];
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\thardware counter profiling%s enabled:\n"),
- (hwcprof_default == 1 ? GTXT (" (default)") : ""));
+ if (hwcprof_default == 1)
+ sb.append (GTXT ("\thardware counter profiling (default) enabled:\n"));
+ else
+ sb.append (GTXT ("\thardware counter profiling enabled:\n"));
for (int ii = 0; ii < hwcprof_enabled_cnt; ii++)
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\t %u. %s\n"), ii + 1,
- hwc_hwcentry_specd_string (ctrbuf, MAXPATHLEN, &hwctr[ii]));
+ sb.appendf ("\t %u. %s\n", ii + 1,
+ hwc_hwcentry_specd_string (ctrbuf, sizeof (ctrbuf), &hwctr[ii]));
}
if (heaptrace_enabled != 0)
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\theap tracing enabled, %s\n"),
- (heaptrace_checkenabled == 0 ? GTXT ("no checking") :
- (heaptrace_checkenabled == 1 ? GTXT ("over/underrun checking") :
- GTXT ("over/underrun checking and pattern storing"))));
+ {
+ if (heaptrace_checkenabled == 0)
+ sb.append (GTXT ("\theap tracing enabled, no checking\n"));
+ else if (heaptrace_checkenabled == 1)
+ sb.append (GTXT ("\theap tracing enabled, over/underrun checking\n"));
+ else
+ sb.append (GTXT ("\theap tracing enabled, over/underrun checking and pattern storing\n"));
+ }
if (iotrace_enabled != 0)
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tI/O tracing enabled\n"));
+ sb.append (GTXT ("\tI/O tracing enabled\n"));
switch (count_enabled)
{
case 0:
break;
case 1:
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tcount data enabled\n"));
+ sb.append (GTXT ("\tcount data enabled\n"));
break;
case -1:
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tstatic count data will be generated (for a.out only)\n"));
+ sb.append (GTXT ("\tstatic count data will be generated (for a.out only)\n"));
break;
}
switch (follow_mode)
{
case FOLLOW_ON:
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tdescendant processes will be followed\n"));
+ sb.append (GTXT ("\tdescendant processes will be followed\n"));
break;
case FOLLOW_ALL:
if (follow_spec_usr && follow_spec_cmp)
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\texperiments will be recorded for descendant processes that match pattern '%s'\n"),
- follow_spec_usr);
+ sb.appendf (GTXT ("\texperiments will be recorded for descendant processes that match pattern '%s'\n"),
+ follow_spec_usr);
else
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tdescendant processes will all be followed\n"));
+ sb.append (GTXT ("\tdescendant processes will all be followed\n"));
break;
case FOLLOW_NONE:
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tdescendant processes will not be followed\n"));
+ sb.append (GTXT ("\tdescendant processes will not be followed\n"));
break;
default:
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tfollowing descendant processes: <UNKNOWN>\n"));
+ sb.append (GTXT ("\tfollowing descendant processes: <UNKNOWN>\n"));
break;
}
if (java_mode == 0)
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tjava profiling disabled\n"));
+ sb.append (GTXT ("\tjava profiling disabled\n"));
if (pauseresume_sig != 0)
{
const char *buf = strsignal (pauseresume_sig);
if (buf != NULL)
{
if (pauseresume_pause == 1)
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tpause-resume (delayed initialization) signal %s (%d) -- paused\n"), buf, pauseresume_sig);
+ sb.appendf (GTXT ("\tpause-resume (delayed initialization) signal %s (%d) -- paused\n"),
+ buf, pauseresume_sig);
else
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tpause-resume (delayed initialization) signal %s (%d)\n"), buf, pauseresume_sig);
+ sb.appendf (GTXT ("\tpause-resume (delayed initialization) signal %s (%d)\n"),
+ buf, pauseresume_sig);
}
else
{
if (pauseresume_pause == 1)
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tpause-resume (delayed initialization) signal %d -- paused\n"), pauseresume_sig);
+ sb.appendf (GTXT ("\tpause-resume (delayed initialization) signal %d -- paused\n"),
+ pauseresume_sig);
else
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tpause-resume (delayed initialization) signal %d\n"), pauseresume_sig);
+ sb.appendf (GTXT ("\tpause-resume (delayed initialization) signal %d\n"),
+ pauseresume_sig);
}
}
if (sample_sig != 0)
{
const char *buf = strsignal (sample_sig);
if (buf != NULL)
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tsample signal %s (%d)\n"), buf, sample_sig);
+ sb.appendf (GTXT ("\tsample signal %s (%d)\n"), buf, sample_sig);
else
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tsample signal %d\n"), sample_sig);
+ sb.appendf (GTXT ("\tsample signal %d\n"), sample_sig);
}
if (time_run != 0 || start_delay != 0)
{
if (start_delay != 0)
{
if (time_run != 0)
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tdata-collection duration, %d-%d secs.\n"), start_delay, time_run);
+ sb.appendf (GTXT ("\tdata-collection duration, %d-%d secs.\n"),
+ start_delay, time_run);
else
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tdata-collection duration, %d- secs.\n"), start_delay);
+ sb.appendf (GTXT ("\tdata-collection duration, %d- secs.\n"),
+ start_delay);
}
else
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tdata-collection duration, %d secs.\n"), time_run);
+ sb.appendf (GTXT ("\tdata-collection duration, %d secs.\n"), time_run);
}
if (sample_period != 0)
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tperiodic sampling, %d secs.\n"), sample_period);
+ sb.appendf (GTXT ("\tperiodic sampling, %d secs.\n"), sample_period);
else
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tno periodic sampling\n"));
+ sb.append (GTXT ("\tno periodic sampling\n"));
if (size_limit != 0)
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\texperiment size limit %d MB.\n"), size_limit);
+ sb.appendf (GTXT ("\texperiment size limit %d MB.\n"), size_limit);
else
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tno experiment size limit set\n"));
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\texperiment archiving: -a %s\n"), archive_mode);
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\tdata descriptor: \"%s\"\n"),
+ sb.append (GTXT ("\tno experiment size limit set\n"));
+ sb.appendf (GTXT ("\texperiment archiving: -a %s\n"), archive_mode);
+ sb.appendf (GTXT ("\tdata descriptor: \"%s\"\n"),
((data_desc != NULL) ? data_desc : NTXT ("<NULL>")));
-#if 0
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\t expt_dir: %s\n"),
- ((expt_dir != NULL) ? expt_dir : NTXT ("<NULL>")));
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\t base_name: %s\n"),
- ((base_name != NULL) ? base_name : NTXT ("<NULL>")));
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\t store_dir: %s\n"),
- ((store_dir != NULL) ? store_dir : NTXT ("<NULL>")));
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\t store_ptr: %s\n"),
- ((store_ptr != NULL) ? store_ptr : NTXT ("<NULL>")));
-#endif
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\t\thost: `%s', ncpus = %d, clock frequency %d MHz.\n"),
+ sb.appendf (GTXT ("\t\thost: `%s', ncpus = %d, clock frequency %d MHz.\n"),
((node_name != NULL) ? node_name : NTXT ("<NULL>")),
(int) ncpus, (int) cpu_clk_freq);
if (npages > 0)
{
long long memsize = ((long long) npages * (long long) page_size) / (1024 * 1024);
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("\t\tmemory: %ld pages @ %ld bytes = %lld MB.\n"),
+ sb.appendf (GTXT ("\t\tmemory: %ld pages @ %ld bytes = %lld MB.\n"),
npages, page_size, memsize);
}
- return strdup (UEbuf);
+ return sb.toString ();
}
#define MAX_COLLECT_ARGS 100
@@ -741,10 +676,9 @@ Coll_Ctrl::show (int i)
char **
Coll_Ctrl::get_collect_args ()
{
- char buf[DD_MAXPATHLEN];
char **p;
char **argv = (char **) calloc (MAX_COLLECT_ARGS, sizeof (char *));
- if (argv == NULL) // poor way of dealing with calloc failure
+ if (argv == NULL) // poor way of dealing with calloc failure
abort ();
p = argv;
*p++ = strdup ("collect");
@@ -753,25 +687,27 @@ Coll_Ctrl::get_collect_args ()
if (clkprof_enabled != 0)
{
*p++ = strdup ("-p");
- snprintf (buf, sizeof (buf), "%du", clkprof_timer);
- *p++ = strdup (buf);
+ *p++ = dbe_sprintf ("%du", clkprof_timer);
}
if (hwcprof_enabled_cnt > 0)
{
- *buf = 0;
+ StringBuilder sb;
*p++ = strdup ("-h");
for (int ii = 0; ii < hwcprof_enabled_cnt; ii++)
{
char*rateString = hwc_rate_string (&hwctr[ii], 1); //"1" is for temporary goldfile compatibility. TBR YXXX!!
- snprintf (buf + strlen (buf), sizeof (buf) - strlen (buf),
- "%s%s,%s%s", ii ? "," : "", hwctr[ii].name,
- rateString ? rateString : "",
- (ii + 1 < hwcprof_enabled_cnt) ? "," : "");
- free (rateString);
+ if (ii > 0)
+ sb.append (',');
+ sb.append (hwctr[ii].name);
+ if (rateString)
+ {
+ sb.append (rateString);
+ free (rateString);
+ }
+ if (ii + 1 < hwcprof_enabled_cnt)
+ sb.append (',');
}
- if (strlen (buf) + 1 >= sizeof (buf))
- abort ();
- *p++ = strdup (buf);
+ *p++ = sb.toString ();
}
if (heaptrace_enabled != 0)
{
@@ -870,28 +806,14 @@ Coll_Ctrl::show_expt ()
{
if (enabled == 0)
return NULL;
- char UEbuf[4096];
- UEbuf[0] = 0;
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("Creating experiment directory %s (Process ID: %ld) ...\n"),
- ((store_ptr != NULL) ? store_ptr : NTXT ("<NULL>")), (long) getpid ());
+ StringBuilder sb;
+ sb.appendf (GTXT ("Creating experiment directory %s (Process ID: %ld) ...\n"),
+ store_ptr != NULL ? store_ptr : "<NULL>", (long) getpid ());
char *caller = getenv ("SP_COLLECTOR_FROM_GUI"); // Collector from GUI
- if (caller != NULL) // Print non-localized message
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- NTXT ("\nCreating experiment directory %s (Process ID: %ld) ...\n"),
- ((store_ptr != NULL) ? store_ptr : NTXT ("<NULL>")), (long) getpid ());
-#if 0
- char *fstype = get_fstype (store_dir);
- if ((fstype != NULL) && (nofswarn == 0))
- {
- // only warn if clock or hwc profiling is turned on
- if (clkprof_enabled || hwcprof_enabled_cnt != 0)
- snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf),
- GTXT ("this experiment is being recorded to a file system \nof type \"%s\", which may distort the measured performance."),
- fstype);
- }
-#endif
- return strdup (UEbuf);
+ if (caller != NULL) // Print non-localized message
+ sb.appendf ("\nCreating experiment directory %s (Process ID: %ld) ...\n",
+ store_ptr != NULL ? store_ptr : "<NULL>", (long) getpid ());
+ return sb.toString ();
}
void
@@ -913,8 +835,8 @@ Coll_Ctrl::reset_clkprof (int val)
{
// profiler has had to reset to a different value; warn user
char *msg = dbe_sprintf (
- GTXT ("Warning: Clock profiling timer reset from %.3f millisec. to %.3f millisec. as required by profiling driver\n\n"),
- (double) (clkprof_timer) / 1000., (double) (val) / 1000.);
+ GTXT ("Warning: Clock profiling timer reset from %.3f millisec. to %.3f millisec. as required by profiling driver\n\n"),
+ (double) (clkprof_timer) / 1000., (double) (val) / 1000.);
adjust_clkprof_timer (val);
return msg;
}
@@ -954,7 +876,7 @@ Coll_Ctrl::set_clkprof (const char *string, char** warn)
double dval = strtod (string, &endchar);
if (*endchar == 'm' || *endchar == 0) /* user specified milliseconds */
dval = dval * 1000.;
- else if (*endchar == 'u') /* user specified microseconds */
+ else if (*endchar == 'u') /* user specified microseconds */
dval = dval;
else
return dbe_sprintf (GTXT ("Unrecognized clock-profiling interval `%s'\n"), string);
@@ -983,8 +905,8 @@ Coll_Ctrl::set_clkprof (const char *string, char** warn)
{
/* value too small, use minimum value, with warning */
*warn = dbe_sprintf (
- GTXT ("Warning: Clock profiling at %.3f millisec. interval is not supported on this system; minimum %.3f millisec. used\n"),
- (double) (nclkprof_timer) / 1000., (double) (clk_params.min) / 1000.);
+ GTXT ("Warning: Clock profiling at %.3f millisec. interval is not supported on this system; minimum %.3f millisec. used\n"),
+ (double) (nclkprof_timer) / 1000., (double) (clk_params.min) / 1000.);
nclkprof_timer = clk_params.min;
}
@@ -992,8 +914,8 @@ Coll_Ctrl::set_clkprof (const char *string, char** warn)
if (nclkprof_timer > clk_params.max)
{
*warn = dbe_sprintf (
- GTXT ("Clock profiling at %.3f millisec. interval is not supported on this system; maximum %.3f millisec. used\n"),
- (double) (nclkprof_timer) / 1000., (double) (clk_params.max) / 1000.);
+ GTXT ("Clock profiling at %.3f millisec. interval is not supported on this system; maximum %.3f millisec. used\n"),
+ (double) (nclkprof_timer) / 1000., (double) (clk_params.max) / 1000.);
nclkprof_timer = clk_params.max;
}
@@ -1005,9 +927,9 @@ Coll_Ctrl::set_clkprof (const char *string, char** warn)
{
/* no, we need to reset to a multiple */
*warn = dbe_sprintf (
- GTXT ("Clock profile interval rounded from %.3f to %.3f (system resolution = %.3f) millisec."),
- (double) (nclkprof_timer) / 1000., (double) (ticks) / 1000.,
- (double) (clk_params.res) / 1000.);
+ GTXT ("Clock profile interval rounded from %.3f to %.3f (system resolution = %.3f) millisec."),
+ (double) (nclkprof_timer) / 1000., (double) (ticks) / 1000.,
+ (double) (clk_params.res) / 1000.);
nclkprof_timer = ticks;
}
}
@@ -1068,7 +990,7 @@ Coll_Ctrl::set_synctrace (const char *string)
/* clear the comma for the threshold determination */
*comma_p = 0;
}
- else /* no ",<scope>" -- default to native and Java */
+ else /* no ",<scope>" -- default to native and Java */
synctrace_scope = SYNCSCOPE_NATIVE | SYNCSCOPE_JAVA;
if (!strlen (val) || !strcmp (val, "calibrate") || !strcmp (val, "on"))
{
@@ -1241,7 +1163,7 @@ Coll_Ctrl::set_time_run (const char *valarg)
{
if (opened == 1)
return strdup (GTXT ("Experiment is active; command ignored.\n"));
- if (valarg == NULL) /* invalid setting */
+ if (valarg == NULL) /* invalid setting */
return strdup (GTXT ("time parameter can not be NULL\n"));
/* the string should be a number >= 0 */
int prev_start_delay = start_delay;
@@ -1260,7 +1182,7 @@ Coll_Ctrl::set_time_run (const char *valarg)
val = val * 60; /* convert to seconds */
endchar++;
}
- else if (*endchar == 's') /* no conversion needed */
+ else if (*endchar == 's') /* no conversion needed */
endchar++;
if (*endchar == 0)
{
@@ -1285,7 +1207,7 @@ Coll_Ctrl::set_time_run (const char *valarg)
val = val * 60; /* convert to seconds */
endchar++;
}
- else if (*endchar == 's') /* no conversion needed */
+ else if (*endchar == 's') /* no conversion needed */
endchar++;
if (*endchar != 0)
{
@@ -1366,6 +1288,7 @@ Coll_Ctrl::hwcentry_dup (Hwcentry *hnew, Hwcentry *_hwc)
}
// Routine to initialize the HWC tables, set up the default experiment, etc.
+
void
Coll_Ctrl::setup_hwc ()
{
@@ -1451,15 +1374,10 @@ Coll_Ctrl::add_hwcstring (const char *string, char **warnmsg)
int rc = 0;
int old_cnt = hwcprof_enabled_cnt;
int prev_cnt = hwcprof_enabled_cnt;
- // int old_hwcprof_default = hwcprof_default;
- char UEbuf[MAXPATHLEN * 5];
- int UEsz;
Hwcentry tmpctr[MAX_PICS];
Hwcentry * ctrtable[MAX_PICS];
char *emsg;
char *wmsg;
- UEbuf[0] = 0;
- UEsz = sizeof (UEbuf);
if (opened == 1)
return strdup (GTXT ("Experiment is active; command ignored.\n"));
if (hwcprof_default == 0)
@@ -1468,7 +1386,7 @@ Coll_Ctrl::add_hwcstring (const char *string, char **warnmsg)
for (int ii = 0; ii < prev_cnt; ii++)
tmpctr[ii] = hwctr[ii];
}
- else /* the previously-defined counters were defaulted; don't copy them */
+ else /* the previously-defined counters were defaulted; don't copy them */
prev_cnt = 0;
/* look up the CPU version */
@@ -1509,22 +1427,28 @@ Coll_Ctrl::add_hwcstring (const char *string, char **warnmsg)
hwcprof_default = 0;
hwcprof_enabled_cnt = rc;
free (hwc_string);
+ StringBuilder sb;
for (int ii = 0; ii < hwcprof_enabled_cnt; ii++)
{
/* shallow copy of new counters */
hwctr[ii] = tmpctr[ii];
char *rateString = hwc_rate_string (&hwctr[ii], 0);
- snprintf (UEbuf + strlen (UEbuf), UEsz - strlen (UEbuf),
- NTXT (",%s,%s"), hwctr[ii].name,
- rateString ? rateString : "");
- free (rateString);
+ if (ii > 0)
+ sb.append (',');
+ sb.append (hwctr[ii].name);
+ sb.append (',');
+ if (rateString)
+ {
+ sb.append (rateString);
+ free (rateString);
+ }
}
- /* now duplicate that string, skipping the leading comma */
- hwc_string = strdup (&UEbuf[1]);
+ hwc_string = sb.toString ();
return NULL;
}
/* add default HWC counters to counter set with resolution (on, hi, or lo) */
+
/* Note that the resultion will also be used to set the clock-profiling default */
char * /* return an error string */
Coll_Ctrl::add_default_hwcstring (const char *resolution, char **warnmsg, bool add, bool forKernel)
@@ -1591,7 +1515,7 @@ Coll_Ctrl::add_default_hwcstring (const char *resolution, char **warnmsg, bool a
strncat (retp, stringp, (retsize - strlen (retp) - 1));
strncat (retp, ",", (retsize - strlen (retp) - 1));
strncat (retp, resolution, (retsize - strlen (retp) - 1));
- if (nextc == 0) /* string ended in comma; we're done */
+ if (nextc == 0) /* string ended in comma; we're done */
break;
}
else
@@ -1606,7 +1530,7 @@ Coll_Ctrl::add_default_hwcstring (const char *resolution, char **warnmsg, bool a
}
/* string had ,, between fields; move to next field */
stringp = next + 1;
- if (* (stringp + 1) == 0) /* name ended in ,, -- we're done */
+ if (* (stringp + 1) == 0) /* name ended in ,, -- we're done */
break;
continue;
}
@@ -1765,10 +1689,10 @@ Coll_Ctrl::build_data_desc ()
if (ii > 0)
sb.append (',');
sb.appendf ("%d:%d:%lld:%s:%s:%lld:%d:m%lld:%d:%d:0x%x",
- h->use_perf_event_type, h->type, (long long) h->config,
- strcmp (h->name, h->int_name) ? h->name : "",
- h->int_name, (long long) h->reg_num, h->val,
- (long long) min_time, ii, /*tag*/ h->timecvt, h->memop);
+ h->use_perf_event_type, h->type, (long long) h->config,
+ strcmp (h->name, h->int_name) ? h->name : "",
+ h->int_name, (long long) h->reg_num, h->val,
+ (long long) min_time, ii, /*tag*/ h->timecvt, h->memop);
}
sb.append (";");
}
@@ -1801,7 +1725,7 @@ Coll_Ctrl::check_group ()
// Is the group an relative path, with a store directory set?
if ((expt_group[0] == '/') || ((udir_name == NULL) || (udir_name[0] == '0')))
snprintf (group_file, sizeof (group_file), "%s", expt_group);
- else // relative path, store directory; make group_file in that directory
+ else // relative path, store directory; make group_file in that directory
snprintf (group_file, sizeof (group_file), "%s/%s", udir_name, expt_group);
// See if we can write the group file
int ret = access (group_file, W_OK);
@@ -1814,11 +1738,11 @@ Coll_Ctrl::check_group ()
ret = access (dir, W_OK);
if (ret != 0) // group file does not exist;
return dbe_sprintf (GTXT ("Directory (%s) for group file %s is not writeable: %s\n"),
- dir, group_file, strerror (errno));
+ dir, group_file, strerror (errno));
}
else
return dbe_sprintf (GTXT ("Group file %s is not writeable: %s\n"),
- group_file, strerror (errno));
+ group_file, strerror (errno));
}
return NULL;
}
@@ -1841,8 +1765,8 @@ Coll_Ctrl::join_group ()
// Is the group an relative path, with a store directory set?
if (expt_group[0] == '/' || udir_name == NULL || udir_name[0] == '0')
snprintf (group_file, sizeof (group_file), "%s", expt_group);
- else // relative path, store directory; make group_file in that directory
- snprintf (group_file, sizeof (group_file), "%s/%s", udir_name, expt_group);
+ else // relative path, store directory; make group_file in that directory
+ snprintf (group_file, sizeof (group_file), "%s/%s", udir_name, expt_group);
for (;;)
{
tries++;
@@ -1910,7 +1834,7 @@ Coll_Ctrl::join_group ()
// If the error was not that the file did not exist, report it
if (errno != ENOENT)
return dbe_sprintf (GTXT ("Can't open group file %s: %s\n"),
- group_file, strerror (errno));
+ group_file, strerror (errno));
// the file did not exist, try to create it
groupfd = open (group_file, O_CREAT | O_EXCL | O_RDWR, 0666);
if (groupfd < 0)
@@ -1919,7 +1843,7 @@ Coll_Ctrl::join_group ()
if (errno == EEXIST)
continue;
return dbe_sprintf (GTXT ("Can't create group file %s: %s\n"),
- group_file, strerror (errno));
+ group_file, strerror (errno));
}
// we created the group file, now lock it, waiting for the lock
while (fcntl (groupfd, F_SETLKW, &flockbuf) == -1)
@@ -1989,7 +1913,7 @@ Coll_Ctrl::set_directory (char *dir, char **warn)
}
else
(void) update_expt_name (false, false);
- return NULL; // All is OK
+ return NULL; // All is OK
}
int
@@ -2020,7 +1944,7 @@ Coll_Ctrl::set_expt (const char *ename, char **warn, bool overwriteExp)
uexpt_name = NULL;
return NULL;
}
- char *exptname = canonical_path(strdup(ename));
+ char *exptname = canonical_path (strdup (ename));
size_t i = strlen (exptname);
if (i < 4 || strcmp (&exptname[i - 3], ".er") != 0)
{
@@ -2116,7 +2040,7 @@ Coll_Ctrl::set_java_mode (const char *string)
java_default = prev_java_default;
return ret;
}
- free (java_path);
+ free (java_path);
java_path = NULL;
return NULL;
}
@@ -2240,11 +2164,6 @@ Coll_Ctrl::set_follow_mode (const char *string)
return NULL;
}
// syntax error in parsing string
-#if 0
- char errbuf[256];
- regerror (ercode, &regex_desc, errbuf, sizeof (errbuf));
- fprintf (stderr, "Coll_Ctrl::set_follow_mode: regerror()=%s\n", errbuf);
-#endif
free (str);
}
return dbe_sprintf (GTXT ("Unrecognized follow-mode parameter `%s'\n"), string);
@@ -2397,23 +2316,23 @@ Coll_Ctrl::create_exp_dir ()
int err = errno;
if (err == EACCES)
return dbe_sprintf (GTXT ("Store directory %s is not writeable: %s\n"),
- store_dir, strerror (err));
+ store_dir, strerror (err));
if (i + 1 >= max) // no more attempts
return dbe_sprintf (GTXT ("Unable to create directory `%s' -- %s\n%s: %d\n"),
- store_ptr, strerror (err),
- GTXT ("collect: Internal error: loop count achieved"),
- max);
+ store_ptr, strerror (err),
+ GTXT ("collect: Internal error: loop count achieved"),
+ max);
char *ermsg = update_expt_name (false, false, true);
if (ermsg != NULL)
{
char *msg = dbe_sprintf (GTXT ("Unable to create directory `%s' -- %s\n"),
- store_ptr, ermsg);
+ store_ptr, ermsg);
free (ermsg);
return msg;
}
continue;
}
- return NULL; // All is OK
+ return NULL; // All is OK
}
return dbe_sprintf (GTXT ("Unable to create directory `%s'\n"), store_ptr);
}
@@ -2428,9 +2347,7 @@ Coll_Ctrl::get_exp_name (const char *stembase)
char *
Coll_Ctrl::preprocess_names ()
{
- char buf[MAXPATHLEN];
- char msgbuf[MAXPATHLEN];
- char *ret = NULL;
+ StringBuilder sb;
/* convert the experiment name and directory into store name/dir */
/* free the old strings */
@@ -2492,34 +2409,23 @@ Coll_Ctrl::preprocess_names ()
expt_name = c;
free (stem);
}
- snprintf (buf, sizeof (buf), NTXT ("%s"), expt_name);
- if (buf[0] == '/')
- {
- // it's a full path name
- if (udir_name != NULL)
- {
- snprintf (msgbuf, sizeof (msgbuf),
- GTXT ("Warning: Experiment name is an absolute path; directory name %s ignored.\n"),
- udir_name);
- ret = strdup (msgbuf);
- }
- }
+ if (*expt_name == '/' && udir_name != NULL)
+ sb.appendf (GTXT ("Warning: Experiment name is an absolute path; directory name %s ignored.\n"),
+ udir_name);
// now extract the directory and basename
- int lastslash = 0;
- for (int i = 0;; i++)
+ char *s = strrchr (expt_name, '/');
+ if (s == NULL)
{
- if (buf[i] == 0)
- break;
- if (buf[i] == '/')
- lastslash = i;
+ expt_dir = strdup (".");
+ base_name = strdup (expt_name);
}
- expt_dir = strdup (buf);
- if (lastslash != 0)
- base_name = strdup (&buf[lastslash + 1]);
else
- base_name = strdup (buf);
- expt_dir[lastslash] = 0;
+ {
+ expt_dir = dbe_strndup (expt_name, s - expt_name - 1);
+ base_name = strdup (s + 1);
+ }
+
if (expt_dir[0] == '/')
store_dir = strdup (expt_dir);
else if ((udir_name == NULL) || (udir_name[0] == 0))
@@ -2535,19 +2441,13 @@ Coll_Ctrl::preprocess_names ()
if (expt_dir[0] == 0)
store_dir = strdup (udir_name);
else
- {
- snprintf (buf, sizeof (buf), "%s/%s", udir_name, expt_dir);
- store_dir = strdup (buf);
- }
+ store_dir = dbe_sprintf ("%s/%s", udir_name, expt_dir);
}
free (store_ptr);
if (strcmp (store_dir, ".") == 0)
store_ptr = strdup (base_name);
else
- {
- snprintf (buf, sizeof (buf), "%s/%s", store_dir, base_name);
- store_ptr = strdup (buf);
- }
+ store_ptr = dbe_sprintf ("%s/%s", store_dir, base_name);
// determine the file system type
if (strcmp (store_dir, prev_store_dir) != 0)
@@ -2556,15 +2456,13 @@ Coll_Ctrl::preprocess_names ()
prev_store_dir = strdup (store_dir);
const char *fstype = get_fstype (store_dir);
if (interactive && enabled && (fstype != NULL) && (nofswarn == 0))
- {
- snprintf (msgbuf, sizeof (msgbuf),
- GTXT ("%sExperiment directory is set to a file system of type \"%s\",\n which may distort the measured performance;\n it is preferable to record to a local disk.\n"),
- (ret == NULL ? "" : ret), fstype);
- free (ret);
- ret = strdup (msgbuf);
- }
+ sb.appendf (GTXT ("Experiment directory is set to a file system of type \"%s\",\n"
+ " which may distort the measured performance;\n"
+ " it is preferable to record to a local disk.\n"), fstype);
}
- return ret;
+ if (sb.length () == 0)
+ return NULL;
+ return sb.toString ();
}
char *
@@ -2600,15 +2498,15 @@ Coll_Ctrl::update_expt_name (bool chgmsg, bool chkonly, bool newname)
while (isdigit ((int) (base_name[pcount])) != 0)
{
pcount--;
- if (pcount == 0) // name is of the form 12345.er; don't update it
+ if (pcount == 0) // name is of the form 12345.er; don't update it
return dbe_sprintf (GTXT ("name %s is in use and cannot be updated\n"),
- base_name);
+ base_name);
digits++;
}
- if (digits == 0) // name is of form xyz.er (or xyz..er); don't update it
+ if (digits == 0) // name is of form xyz.er (or xyz..er); don't update it
return dbe_sprintf (GTXT ("name %s is in use and cannot be updated\n"),
base_name);
- if (base_name[pcount] != '.') // name is of form xyz123.er; don't update it
+ if (base_name[pcount] != '.') // name is of form xyz123.er; don't update it
return dbe_sprintf (GTXT ("name %s is in use and cannot be updated\n"),
base_name);
if (chkonly)
@@ -2619,7 +2517,7 @@ Coll_Ctrl::update_expt_name (bool chgmsg, bool chkonly, bool newname)
// the name is of the from prefix.nnn.er; extract the value of nnn
int version = atoi (&base_name[pcount + 1]);
- if (newname) // do not try to use old name
+ if (newname) // do not try to use old name
version++;
int max_version = version - 1;
@@ -2664,7 +2562,7 @@ Coll_Ctrl::update_expt_name (bool chgmsg, bool chkonly, bool newname)
if ((strcmp (oldbase, newbase) != 0) && chgmsg)
{
ret = dbe_sprintf (GTXT ("name %s is in use; changed to %s\n"),
- oldbase, newbase);
+ oldbase, newbase);
free (oldbase);
}
else
@@ -2730,17 +2628,17 @@ Coll_Ctrl::determine_profile_params ()
// now reset the timer to turn it off
itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = 0;
- if (setitimer (ITIMER_REALPROF, &itimer, &otimer) == -1) // call failed
+ if (setitimer (ITIMER_REALPROF, &itimer, &otimer) == -1) // call failed
nperiod = -1;
else
nperiod = otimer.it_interval.tv_sec * MICROSEC + otimer.it_interval.tv_usec;
// check the returned value: is the what we asked for?
- if (period == nperiod) // arbitrary precision is OK
+ if (period == nperiod) // arbitrary precision is OK
set_clk_params (PROFINT_MIN, 1, PROFINT_MAX, PROFINT_HIGH, PROFINT_NORM, PROFINT_LOW);
else if (nperiod < 10000) // hi resolution allowed, but not arbitrary precision
set_clk_params ((int) nperiod, 1000, PROFINT_MAX, 1000, 10000, 100000);
- else // low resolution only allowed
+ else // low resolution only allowed
set_clk_params (10000, 10000, PROFINT_MAX, 1000, 10000, 100000);
// If old handler was default, ignore it; otherwise restore it
@@ -2791,7 +2689,7 @@ const char *ipc_str_synctrace = "synctrace";
const char *ipc_str_heaptrace = "heaptrace";
const char *ipc_str_iotrace = "iotrace";
const char *ipc_str_count = "count";
-const char *ipc_str_prof_idle = "prof_idle"; // -x option
+const char *ipc_str_prof_idle = "prof_idle"; // -x option
// Standard answers
const char *ipc_str_empty = "";
const char *ipc_str_on = "on";
@@ -2870,7 +2768,7 @@ Coll_Ctrl::get (char * control)
}
if (!strncmp (control, ipc_str_clkprof, len))
{
- if (clkprof_default == 1 && clkprof_enabled == 1) // Default value
+ if (clkprof_default == 1 && clkprof_enabled == 1) // Default value
return strdup (ipc_str_empty);
if (clkprof_enabled == 0)
return strdup (ipc_str_off);
@@ -2894,7 +2792,7 @@ Coll_Ctrl::get (char * control)
}
if (!strncmp (control, ipc_str_sample, len))
{
- if (sample_default == 1 && sample_period == 1) // Default value
+ if (sample_default == 1 && sample_period == 1) // Default value
return strdup (ipc_str_empty);
if (sample_period == 0)
return strdup (ipc_str_off);
diff --git a/gprofng/src/collctrl.h b/gprofng/src/collctrl.h
index 5f1ee26..a416474 100644
--- a/gprofng/src/collctrl.h
+++ b/gprofng/src/collctrl.h
@@ -87,7 +87,6 @@ public:
void set_clk_params(int min, int res, int max, int hi, int norm, int lo);
char *set_clkprof(const char *valptr, char **warn);
char *reset_clkprof(int val); /* called if profiler must reset value */
- int get_sys_period() { return clk_params.min; };
int get_clk_min() { return clk_params.min; };
int get_clk_max() { return clk_params.max; };
int get_clk_res() { return clk_params.res; };
@@ -275,7 +274,6 @@ private:
int cpu_clk_freq; /* chip clock (MHz.), as reported from processor_info */
int cpc_cpuver; /* chip version, as reported from libcpc */
long sys_resolution; /* system clock resolution */
- int sys_period; /* profiling clock resolution on the system */
int sample_period; /* period for sampling, seconds */
int sample_default; /* if period for sampling set by default */
int size_limit; /* experiment size limit, MB */