80 #include <sys/types.h> 86 #include <include/hpctoolkit-config.h> 100 #define LD_LIBRARY_PATH "LD_LIBRARY_PATH" 101 #define LD_PRELOAD "LD_PRELOAD" 141 catch (
const std::bad_alloc& x) {
142 DIAG_EMsg(
"[std::bad_alloc] " << x.what());
145 catch (
const std::exception& x) {
146 DIAG_EMsg(
"[std::exception] " << x.what());
150 DIAG_EMsg(
"Unknown exception encountered!");
171 DIAG_Assert(installpath,
"Cannot locate installation path for '"HPCRUN_NAME"'");
196 char** profArgV =
new char*[args.
profArgV.size() + 1];
198 profArgV[i] = (
char*)args.
profArgV[i].c_str();
207 if ((pid = fork()) == 0) {
209 const char* cmd = profArgV[0];
210 if (execvp(cmd, profArgV) == -1) {
211 DIAG_Throw(
"Error exec'ing '" << cmd <<
"': " << strerror(errno));
218 return WEXITSTATUS(status);
225 char buf[PATH_MAX] =
"";
238 #if defined(HAVE_OS_MULTILIB) 239 snprintf(buf, PATH_MAX,
"%s/lib64/hpctoolkit", installpath);
241 snprintf(buf, PATH_MAX,
"%s/lib32/hpctoolkit", installpath);
244 snprintf(buf, PATH_MAX,
"%s/lib/hpctoolkit", installpath);
249 const char* MON = HPC_MONITOR;
252 #if defined(HAVE_OS_MULTILIB) 259 #if defined(HAVE_OS_MULTILIB) 260 snprintf(buf, PATH_MAX,
"%s/lib64/" HPC_MONITOR, installpath);
262 snprintf(buf, PATH_MAX,
"%s/lib32/" HPC_MONITOR, installpath);
265 snprintf(buf, PATH_MAX,
"%s/lib/" HPC_MONITOR, installpath);
286 setenv(
"HPCRUN_RECURSIVE", val, 1);
293 setenv(
"HPCRUN_THREAD", val, 1);
296 setenv(
"HPCRUN_EVENT_LIST", args.
profEvents.c_str(), 1);
299 setenv(
"HPCRUN_OUTPUT", args.
profOutput.c_str(), 1);
300 setenv(
"HPCRUN_OPTIONS",
"DIR", 1);
303 setenv(
"HPCRUN_EVENT_FLAG", args.
profPAPIFlag.c_str(), 1);
307 setenv(
"HPCRUN_DEBUG", val.c_str(), 1);
308 setenv(
"MONITOR_DEBUG", val.c_str(), 1);
339 static const char* HPCRUN_TAG =
"HPCRUN_SUPER_SECRET_TAG";
348 envtag = getenv(HPCRUN_TAG);
352 status |= setenv(HPCRUN_TAG,
"1", 1);
354 DIAG_Throw(
"Error preparing environment.");
358 if ((pid = fork()) == 0) {
360 const char* cmd = argv[0];
361 if (execvp(cmd, argv) == -1) {
362 DIAG_Throw(
"Error exec'ing myself: " << strerror(errno));
369 return WEXITSTATUS(status);
392 #define SEPARATOR_MAJOR setfill('=') << setw(77) << "" << "\n\n" 393 #define SEPARATOR_MINOR setfill('-') << setw(77) << "" << "\n" 395 ostream& os = std::cout;
409 const PAPI_hw_info_t* hwinfo =
NULL;
411 DIAG_Throw(
"PAPI_get_hardware_info failed");
413 os <<
"*** Hardware information ***\n";
415 os <<
"Vendor string and code : " 416 << hwinfo->vendor_string <<
" (" << hwinfo->vendor <<
")\n";
417 os <<
"Model string and code : " 418 << hwinfo->model_string <<
" (" << hwinfo->model <<
")\n";
419 os <<
"CPU Revision : " << hwinfo->revision <<
"\n";
420 os <<
"CPU Megahertz : " << hwinfo->mhz <<
"\n";
421 os <<
"CPU's in this Node : " << hwinfo->ncpu <<
"\n";
422 os <<
"Nodes in this System : " << hwinfo->nnodes <<
"\n";
423 os <<
"Total CPU's : " << hwinfo->totalcpus <<
"\n";
431 os <<
"*** Wall clock time ***\n";
439 os <<
"*** Available PAPI preset events ***\n";
442 os <<
"Name\t\tDescription\n";
445 os <<
"Name\t Profilable\tDescription (Implementation Note)\n";
452 int i = PAPI_PRESET_MASK;
455 PAPI_event_info_t info;
461 const char* profilable =
"Yes";
462 if ((info.count > 1) && strcmp(info.derived,
"DERIVED_CMPD") != 0) {
467 os << info.symbol <<
"\t" << info.long_descr <<
"\n";
470 os << info.symbol <<
"\t" << profilable <<
"\t" << info.long_descr
471 <<
" (" << info.note <<
")\n";
479 os <<
"Total PAPI events reported: " << count <<
"\n";
487 os <<
"*** Available native events ***\n";
490 os <<
"Name\t\t\t\tDescription\n";
493 os <<
"Name\t\t\t\tDescription\n";
499 os << std::left << setfill(
' ');
501 i = PAPI_NATIVE_MASK;
504 PAPI_event_info_t info;
506 const char* desc = (info.long_descr) ? info.long_descr :
"";
509 if (strncmp(info.symbol, desc, strlen(info.symbol)) == 0) {
510 desc += strlen(info.symbol);
512 os << setw(31) << info.symbol <<
" " << desc <<
"\n";
521 os <<
"Total native events reported: " << count <<
"\n";
550 #if defined(HAVE_OS_MULTILIB) 560 DIAG_Msg(0,
"Using PAPI installation: '"HPC_PAPI
"'");
561 const char* MON = HPC_MONITOR;
563 DIAG_Msg(0,
"Using MONITOR installation: '"HPC_MONITOR
"'\n");
588 char newval[PATH_MAX] =
"";
592 strncpy(newval, str, PATH_MAX);
593 oldval = getenv(env_var);
595 sz = PATH_MAX - (strlen(newval) + 1);
596 snprintf(newval + strlen(newval), sz,
"%c%s", sep, oldval);
598 newval[PATH_MAX-1] =
'\0';
599 setenv(env_var, newval, 1);
dl_PAPI_is_initialized_t dl_PAPI_is_initialized
#define HPCRUN_EVENT_WALLCLK_STR
int hpc_init_papi(int(*is_init)(void), int(*init)(int))
string toStr(const int x, int base)
dl_PAPI_get_hardware_info_t dl_PAPI_get_hardware_info
const char * DIAG_Unimplemented
static int real_main(int argc, char *argv[])
static int prepend_to_env_var(const char *env_var, const char *str, char sep)
dl_PAPI_get_opt_t dl_PAPI_get_opt
int Diagnostics_GetDiagnosticFilterLevel()
dl_PAPI_library_init_t dl_PAPI_library_init
#define HPCRUN_THREADPROF_ALL_STR
static int prepend_to_ld_preload(const char *str)
static void print_external_lib_paths()
static int prepare_ld_lib_path_for_papi()
virtual std::string message() const
std::vector< std::string > profArgV
dl_PAPI_enum_event_t dl_PAPI_enum_event
dl_PAPI_query_event_t dl_PAPI_query_event
std::string profRecursive
#define DIAG_Msg(level,...)
char * findinstall(const char *cmd, const char *base_cmd)
static int check_and_prepare_env_for_eventlisting()
int main(int argc, char *argv[])
static int prepend_to_ld_lib_path(const char *str)
dl_PAPI_get_event_info_t dl_PAPI_get_event_info
static void list_available_events_helper(Args::EventList_t listType)
static int list_available_events(char *argv[], Args::EventList_t listType)
#define HPCRUN_THREADPROF_EACH_STR
static int launch_with_profiling(const char *installpath, const Args &args)
static int prepare_env_for_profiling(const char *installpath, const Args &args)