Index: openmp/runtime/src/ompt-general.cpp =================================================================== --- openmp/runtime/src/ompt-general.cpp +++ openmp/runtime/src/ompt-general.cpp @@ -45,6 +45,9 @@ #define OMPT_STR_MATCH(haystack, needle) (!strcasecmp(haystack, needle)) #endif +static FILE *verbose_file; +static int verbose_init; + /***************************************************************************** * types ****************************************************************************/ @@ -230,6 +233,10 @@ const char *sep = ":"; #endif + if (verbose_init) + fprintf(verbose_file, + "----- START LOGGING OF TOOL REGISTRATION -----\nSearch for OMP " + "tool in current address space... "); #if KMP_OS_DARWIN // Try in the current address space ret = ompt_tool_darwin(omp_version, runtime_version); @@ -240,50 +247,129 @@ #else #error Activation of OMPT is not supported on this platform. #endif - if (ret) + if (ret) { + if (verbose_init) + fprintf(verbose_file, + "Sucess.\nTool was started and is using the OMPT " + "interface.\n----- END LOGGING OF TOOL REGISTRATION -----\n"); return ret; + } // Try tool-libraries-var ICV + if (verbose_init) + fprintf(verbose_file, "Failed.\nSearching tool libraries...\n"); const char *tool_libs = getenv("OMP_TOOL_LIBRARIES"); if (tool_libs) { char *libs = __kmp_str_format("%s", tool_libs); char *buf; char *fname = __kmp_str_token(libs, sep, &buf); + // Reset dl-error + dlerror(); + while (fname) { #if KMP_OS_UNIX + if (verbose_init) + fprintf(verbose_file, "Opening %s... ", fname); void *h = dlopen(fname, RTLD_LAZY); - if (h) { + if (!h) { + if (verbose_init) + fprintf(verbose_file, "Failed: %s\n", dlerror()); + } else { + if (verbose_init) { + fprintf(verbose_file, "Success. \n"); + fprintf(verbose_file, "Searching for ompt_start_tool in %s... ", + fname); + } start_tool = (ompt_start_tool_t)dlsym(h, "ompt_start_tool"); + if (!start_tool) { + if (verbose_init) + fprintf(verbose_file, "Failed: %s\n", dlerror()); + } else #elif KMP_OS_WINDOWS + if (verbose_init) + fprintf(verbose_file, "Opening %s... ", fname); HMODULE h = LoadLibrary(fname); - if (h) { + if (!h) { + if (verbose_init) + fprintf(verbose_file, "Failed: Error %u\n", GetLastError()); + } else { + if (verbose_init) { + fprintf(verbose_file, "Success. \n"); + fprintf(verbose_file, "Searching for ompt_start_tool in %s... ", + fname); + } start_tool = (ompt_start_tool_t)GetProcAddress(h, "ompt_start_tool"); + if (!start_tool) { + if (verbose_init) + fprintf(verbose_file, "Failed: Error %s\n", GetLastError()); + } else #else #error Activation of OMPT is not supported on this platform. #endif - if (start_tool && (ret = (*start_tool)(omp_version, runtime_version))) - break; + {// if (start_tool) + ret = (*start_tool)(omp_version, runtime_version); + if (ret) { + if (verbose_init) + fprintf(verbose_file, "Success.\nTool was started and is using " + "the OMPT interface.\n"); + break; + } + if (verbose_init) + fprintf(verbose_file, "Found but not using the OMPT interface.\n" + "Continuing search...\n"); + } + // dlsym failed, start_tool not found } fname = __kmp_str_token(NULL, sep, &buf); } __kmp_str_free(&libs); } - if (ret) + + // usable tool found in tool-libraries + if (ret) { + if (verbose_init) + fprintf(verbose_file, "----- END LOGGING OF TOOL REGISTRATION -----\n"); return ret; + } #if KMP_OS_UNIX { // Non-standard: load archer tool if application is built with TSan const char *fname = "libarcher.so"; + if (verbose_init) + fprintf(verbose_file, + "...searching tool libraries failed. Using archer tool.\nOpening " + "%s... ", + fname); void *h = dlopen(fname, RTLD_LAZY); if (h) { + if (verbose_init) { + fprintf(verbose_file, "Success. \n"); + fprintf(verbose_file, "Searching for ompt_start_tool in %s... ", fname); + } start_tool = (ompt_start_tool_t)dlsym(h, "ompt_start_tool"); - if (start_tool) + if (start_tool) { ret = (*start_tool)(omp_version, runtime_version); - if (ret) - return ret; + if (ret) { + if (verbose_init) + fprintf( + verbose_file, + "Success.\nTool was started and is using the OMPT " + "interface.\n----- END LOGGING OF TOOL REGISTRATION -----\n"); + return ret; + } + if (verbose_init) + fprintf(verbose_file, "Found but not using the OMPT interface.\n"); + } else { + if (verbose_init) + fprintf(verbose_file, "Failed: %s\n", dlerror()); + } } } #endif + if (verbose_init) + fprintf( + verbose_file, + "No OMP tool loaded.\n----- END LOGGING OF TOOL REGISTRATION -----\n"); return ret; } @@ -311,11 +397,28 @@ else if (OMPT_STR_MATCH(ompt_env_var, "enabled")) tool_setting = omp_tool_enabled; + const char *ompt_env_verbose_init = getenv("OMP_TOOL_VERBOSE_INIT"); + // possible options: disabled | stdout | stderr | + // if set, not empty and not disabled -> prepare for logging + if (ompt_env_verbose_init && strcmp(ompt_env_verbose_init, "") && + !OMPT_STR_MATCH(ompt_env_verbose_init, "disabled")) { + verbose_init = 1; + if (OMPT_STR_MATCH(ompt_env_verbose_init, "STDERR")) + verbose_file = stderr; + else if (OMPT_STR_MATCH(ompt_env_verbose_init, "STDOUT")) + verbose_file = stdout; + else + verbose_file = fopen(ompt_env_verbose_init, "w"); + } else + verbose_init = 0; + #if OMPT_DEBUG printf("ompt_pre_init(): tool_setting = %d\n", tool_setting); #endif switch (tool_setting) { case omp_tool_disabled: + if (verbose_init) + fprintf(verbose_file, "OMP tool disabled. \n"); break; case omp_tool_unset: @@ -337,6 +440,8 @@ ompt_env_var); break; } + if (verbose_init && verbose_file != stderr && verbose_file != stdout) + fclose(verbose_file); #if OMPT_DEBUG printf("ompt_pre_init(): ompt_enabled = %d\n", ompt_enabled); #endif Index: openmp/runtime/test/ompt/loadtool/tool_available/tool_available.c =================================================================== --- openmp/runtime/test/ompt/loadtool/tool_available/tool_available.c +++ openmp/runtime/test/ompt/loadtool/tool_available/tool_available.c @@ -1,20 +1,75 @@ // The OpenMP standard defines 3 ways of providing ompt_start_tool: -// 1. "statically-linking the tool’s definition of ompt_start_tool into an OpenMP application" -// RUN: %libomp-compile -DCODE -DTOOL && %libomp-run | FileCheck %s + +// 1. "statically-linking the tool’s definition of ompt_start_tool into an +// OpenMP application" + +// RUN: %libomp-compile -DCODE -DTOOL && env OMP_TOOL_VERBOSE_INIT=stdout \ +// RUN: %libomp-run | FileCheck %s --check-prefixes CHECK,ADDRSPACE // Note: We should compile the tool without -fopenmp as other tools developer -// would do. Otherwise this test may pass for the wrong reasons on Darwin. +// would do. Otherwise this test may pass for the wrong reasons on Darwin. + // RUN: %clang %flags -DTOOL -shared -fPIC %s -o %T/tool.so -// 2. "introducing a dynamically-linked library that includes the tool’s definition of ompt_start_tool into the application’s address space" + +// 2. "introducing a dynamically-linked library that includes the tool’s +// definition of ompt_start_tool into the application’s address space" + // 2.1 Link with tool during compilation -// RUN: %libomp-compile -DCODE %no-as-needed-flag %T/tool.so && %libomp-run | FileCheck %s + +// RUN: %libomp-compile -DCODE %no-as-needed-flag %T/tool.so && \ +// RUN: env OMP_TOOL_VERBOSE_INIT=stdout %libomp-run | FileCheck %s \ +// RUN: --check-prefixes CHECK,ADDRSPACE + // 2.2 Link with tool during compilation, but AFTER the runtime -// RUN: %libomp-compile -DCODE -lomp %no-as-needed-flag %T/tool.so && %libomp-run | FileCheck %s + +// RUN: %libomp-compile -DCODE -lomp %no-as-needed-flag %T/tool.so && \ +// RUN: env OMP_TOOL_VERBOSE_INIT=stdout %libomp-run | FileCheck %s \ +// RUN: --check-prefixes CHECK,ADDRSPACE + // 2.3 Inject tool via the dynamic loader -// RUN: %libomp-compile -DCODE && %preload-tool %libomp-run | FileCheck %s -// 3. "providing the name of a dynamically-linked library appropriate for the architecture and operating system used by the application in the tool-libraries-var ICV" -// RUN: %libomp-compile -DCODE && env OMP_TOOL_LIBRARIES=%T/tool.so %libomp-run | FileCheck %s +// RUN: %libomp-compile -DCODE && env OMP_TOOL_VERBOSE_INIT=stdout \ +// RUN: %preload-tool %libomp-run | FileCheck %s \ +// RUN: --check-prefixes CHECK,ADDRSPACE + +// 3. "providing the name of a dynamically-linked library appropriate for the +// architecture and operating system used by the application in the +// tool-libraries-var ICV" + +// 3.1 OMP_TOOL_VERBOSE_INIT not set + +// RUN: %libomp-compile -DCODE && \ +// RUN: env OMP_TOOL_LIBRARIES=%T/tool.so %libomp-run | FileCheck %s + +// 3.2 OMP_TOOL_VERBOSE_INIT disabled + +// RUN: env OMP_TOOL_LIBRARIES=%T/tool.so OMP_TOOL_VERBOSE_INIT=disabled \ +// RUN: %libomp-run | FileCheck %s + +// 3.3 OMP_TOOL_VERBOSE_INIT to stdout + +// RUN: %libomp-compile -DCODE && env OMP_TOOL_LIBRARIES=%T/tool.so \ +// RUN: OMP_TOOL_VERBOSE_INIT=stdout %libomp-run | \ +// RUN: FileCheck %s -DPARENTPATH=%T --check-prefixes CHECK,TOOLLIB + +// 3.4 OMP_TOOL_VERBOSE_INIT to stderr, check merged stdout and stderr + +// RUN: env OMP_TOOL_LIBRARIES=%T/tool.so OMP_TOOL_VERBOSE_INIT=stderr \ +// RUN: %libomp-run 2>&1 | \ +// RUN: FileCheck %s -DPARENTPATH=%T --check-prefixes CHECK,TOOLLIB + +// 3.5 OMP_TOOL_VERBOSE_INIT to stderr, check just stderr + +// RUN: env OMP_TOOL_LIBRARIES=%T/tool.so OMP_TOOL_VERBOSE_INIT=stderr \ +// RUN: %libomp-run 2>&1 >/dev/null | \ +// RUN: FileCheck %s -DPARENTPATH=%T --check-prefixes TOOLLIB + +// 3.6 OMP_TOOL_VERBOSE_INIT to file "init.log" + +// RUN: env OMP_TOOL_LIBRARIES=%T/tool.so OMP_TOOL_VERBOSE_INIT=%T/init.log \ +// RUN: %libomp-run && cat %T/init.log | \ +// RUN: FileCheck %s -DPARENTPATH=%T --check-prefixes TOOLLIB + // REQUIRES: ompt @@ -25,6 +80,24 @@ * -DCODE enables the code for the executable during compilation */ +// Check if libomp supports the callbacks for this test. +// CHECK-NOT: {{^}}0: Could not register callback + +// ADDRSPACE: {{^}}----- START LOGGING OF TOOL REGISTRATION ----- +// ADDRSPACE-NEXT: {{^}}Search for OMP tool in current address space... Sucess. +// ADDRSPACE-NEXT: {{^}}Tool was started and is using the OMPT interface. +// ADDRSPACE-NEXT: {{^}}----- END LOGGING OF TOOL REGISTRATION ----- + +// TOOLLIB: {{^}}----- START LOGGING OF TOOL REGISTRATION ----- +// TOOLLIB-NEXT: {{^}}Search for OMP tool in current address space... Failed. +// TOOLLIB-NEXT: {{^}}Searching tool libraries... +// TOOLLIB-NEXT: {{^}}Opening [[PARENTPATH]]/tool.so... Success. +// TOOLLIB-NEXT: {{^}}Searching for ompt_start_tool in +// TOOLLIB-SOME: [[PARENTPATH]]/tool.so... Success. +// TOOLLIB-NEXT: {{^}}Tool was started and is using the OMPT interface. +// TOOLLIB-NEXT: {{^}}----- END LOGGING OF TOOL REGISTRATION ----- + + #ifdef CODE #include "omp.h" @@ -34,9 +107,8 @@ { } - - // Check if libomp supports the callbacks for this test. - // CHECK-NOT: {{^}}0: Could not register callback + // CHECK-NOT: {{^}}----- START LOGGING OF TOOL REGISTRATION ----- + // CHECK-NOT: {{^}}----- END LOGGING OF TOOL REGISTRATION ----- // CHECK: {{^}}0: NULL_POINTER=[[NULL:.*$]] // CHECK: {{^}}0: ompt_event_runtime_shutdown Index: openmp/runtime/test/ompt/loadtool/tool_available_search/tool_available_search.c =================================================================== --- openmp/runtime/test/ompt/loadtool/tool_available_search/tool_available_search.c +++ openmp/runtime/test/ompt/loadtool/tool_available_search/tool_available_search.c @@ -1,7 +1,9 @@ // RUN: %clang %flags -shared -fPIC %s -o %T/first_tool.so // RUN: %clang %flags -DTOOL -DSECOND_TOOL -shared -fPIC %s -o %T/second_tool.so // RUN: %clang %flags -DTOOL -DTHIRD_TOOL -shared -fPIC %s -o %T/third_tool.so -// RUN: %libomp-compile -DCODE && env OMP_TOOL_LIBRARIES=%T/non_existing_file.so:%T/first_tool.so:%T/second_tool.so:%T/third_tool.so %libomp-run | FileCheck %s +// RUN: %libomp-compile -DCODE +// RUN: env OMP_TOOL_LIBRARIES=%T/non_existing_file.so:%T/first_tool.so:%T/second_tool.so:%T/third_tool.so \ +// RUN: OMP_TOOL_VERBOSE_INIT=stdout %libomp-run | FileCheck %s -DPARENTPATH=%T // REQUIRES: ompt @@ -15,6 +17,38 @@ * -DCODE enables the code for the executable during compilation */ +// CHECK: {{^}}----- START LOGGING OF TOOL REGISTRATION ----- +// CHECK-NEXT: {{^}}Search for OMP tool in current address space... Failed. +// CHECK-NEXT: {{^}}Searching tool libraries... +// CHECK-NEXT: {{^}}Opening [[PARENTPATH]]/non_existing_file.so... Failed: +// CHECK-SAME: [[PARENTPATH]]/non_existing_file.so: cannot open shared object +// CHECK-SAME: file: No such file or directory +// CHECK-NEXT: {{^}}Opening [[PARENTPATH]]/first_tool.so... Success. +// CHECK-NEXT: {{^}}Searching for ompt_start_tool in +// CHECK-SAME: [[PARENTPATH]]/first_tool.so... Failed: +// CHECK-SAME: [[PARENTPATH]]/first_tool.so: undefined symbol: ompt_start_tool +// CHECK-NEXT: {{^}}Opening [[PARENTPATH]]/second_tool.so... Success. +// CHECK-NEXT: {{^}}Searching for ompt_start_tool in +// CHECK-SAME: [[PARENTPATH]]/second_tool.so... 0: Do not initialize tool +// CHECK-NEXT: {{^}}Found but not using the OMPT interface. +// CHECK-NEXT: {{^}}Continuing search... +// CHECK-NEXT: {{^}}Opening [[PARENTPATH]]/third_tool.so... Success. +// CHECK-NEXT: {{^}}Searching for ompt_start_tool in +// CHECK-SAME: [[PARENTPATH]]/third_tool.so... 0: Do initialize tool +// CHECK-NEXT: {{^}}Success. +// CHECK-NEXT: {{^}}Tool was started and is using the OMPT interface. +// CHECK-NEXT: {{^}}----- END LOGGING OF TOOL REGISTRATION ----- + +// Check if libomp supports the callbacks for this test. + +// CHECK-NOT: {{^}}0: Could not register callback +// CHECK: {{^}}0: Tool initialized +// CHECK: {{^}}0: ompt_event_thread_begin +// CHECK-DAG: {{^}}0: ompt_event_thread_begin +// CHECK-DAG: {{^}}0: control_tool()=-1 +// CHECK: {{^}}0: Tool finalized + + #ifdef CODE #include "stdio.h" #include "omp.h" @@ -32,19 +66,6 @@ } - // Check if libomp supports the callbacks for this test. - // CHECK-NOT: {{^}}0: Could not register callback - - // CHECK: {{^}}0: Do not initialize tool - - // CHECK: {{^}}0: Do initialize tool - // CHECK: {{^}}0: Tool initialized - // CHECK: {{^}}0: ompt_event_thread_begin - // CHECK-DAG: {{^}}0: ompt_event_thread_begin - // CHECK-DAG: {{^}}0: control_tool()=-1 - // CHECK: {{^}}0: Tool finalized - - return 0; } Index: openmp/runtime/test/ompt/loadtool/tool_not_available/tool_not_available.c =================================================================== --- openmp/runtime/test/ompt/loadtool/tool_not_available/tool_not_available.c +++ openmp/runtime/test/ompt/loadtool/tool_not_available/tool_not_available.c @@ -1,20 +1,45 @@ // The OpenMP standard defines 3 ways of providing ompt_start_tool: -// 1. "statically-linking the tool’s definition of ompt_start_tool into an OpenMP application" -// RUN: %libomp-compile -DCODE -DTOOL && %libomp-run | FileCheck %s + +// 1. "statically-linking the tool’s definition of ompt_start_tool into an +// OpenMP application" + +// RUN: %libomp-compile -DCODE -DTOOL && \ +// RUN: env OMP_TOOL_VERBOSE_INIT=stdout %libomp-run | \ +// RUN: FileCheck %s --check-prefixes CHECK,ADDRSPACE // Note: We should compile the tool without -fopenmp as other tools developer -// would do. Otherwise this test may pass for the wrong reasons on Darwin. +// would do. Otherwise this test may pass for the wrong reasons on Darwin. + // RUN: %clang %flags -DTOOL -shared -fPIC %s -o %T/tool.so -// 2. "introducing a dynamically-linked library that includes the tool’s definition of ompt_start_tool into the application’s address space" + +// 2. "introducing a dynamically-linked library that includes the tool’s +// definition of ompt_start_tool into the application’s address space" + // 2.1 Link with tool during compilation -// RUN: %libomp-compile -DCODE %no-as-needed-flag %T/tool.so && %libomp-run | FileCheck %s + +// RUN: %libomp-compile -DCODE %no-as-needed-flag %T/tool.so && \ +// RUN: env OMP_TOOL_VERBOSE_INIT=stdout %libomp-run | \ +// RUN: FileCheck %s --check-prefixes CHECK,ADDRSPACE + // 2.2 Link with tool during compilation, but AFTER the runtime -// RUN: %libomp-compile -DCODE -lomp %no-as-needed-flag %T/tool.so && %libomp-run | FileCheck %s + +// RUN: %libomp-compile -DCODE -lomp %no-as-needed-flag %T/tool.so && \ +// RUN: env OMP_TOOL_VERBOSE_INIT=stdout %libomp-run | \ +// RUN: FileCheck %s --check-prefixes CHECK,ADDRSPACE + // 2.3 Inject tool via the dynamic loader -// RUN: %libomp-compile -DCODE && %preload-tool %libomp-run | FileCheck %s -// 3. "providing the name of a dynamically-linked library appropriate for the architecture and operating system used by the application in the tool-libraries-var ICV" -// RUN: %libomp-compile -DCODE && env OMP_TOOL_LIBRARIES=%T/tool.so %libomp-run | FileCheck %s +// RUN: %libomp-compile -DCODE && \ +// RUN: env OMP_TOOL_VERBOSE_INIT=stdout %preload-tool %libomp-run | \ +// RUN: FileCheck %s --check-prefixes CHECK,ADDRSPACE + +// 3. "providing the name of a dynamically-linked library appropriate for the +// architecture and operating system used by the application in the +// tool-libraries-var ICV" + +// RUN: %libomp-compile -DCODE && env OMP_TOOL_LIBRARIES=%T/tool.so \ +// RUN: OMP_TOOL_VERBOSE_INIT=stdout %libomp-run | \ +// RUN: FileCheck %s -DPARENTPATH=%T --check-prefixes CHECK,TOOLLIB // REQUIRES: ompt @@ -45,7 +70,30 @@ // Check if libomp supports the callbacks for this test. // CHECK-NOT: {{^}}0: Could not register callback - // CHECK: {{^}}0: Do not initialize tool + // ADDRSPACE: {{^}}----- START LOGGING OF TOOL REGISTRATION ----- + // ADDRSPACE-NEXT: {{^}}Search for OMP tool in current address space... + + // TOOLLIB: {{^}}----- START LOGGING OF TOOL REGISTRATION ----- + // TOOLLIB-NEXT: {{^}}Search for OMP tool in current address space... Failed. + // TOOLLIB-NEXT: {{^}}Searching tool libraries... + // TOOLLIB-NEXT: {{^}}Opening [[PARENTPATH]]/tool.so... Success. + // TOOLLIB-NEXT: {{^}}Searching for ompt_start_tool in + // TOOLLIB-SAME: [[PARENTPATH]]/tool.so... + + // CHECK: 0: Do not initialize tool + + // ADDRSPACE-NEXT: {{^}}Failed. + // ADDRSPACE-NEXT: {{^}}Searching tool libraries... + // ADDRSPACE-NEXT: {{^}}...searching tool libraries failed. + // ADDRSPACE: {{^}}No OMP tool loaded. + // ADDRSPACE-NEXT: {{^}}----- END LOGGING OF TOOL REGISTRATION ----- + + // TOOLLIB-NEXT: {{^}}Found but not using the OMPT interface. + // TOOLLIB-NEXT: {{^}}Continuing search... + // TOOLLIB-NEXT: {{^}}...searching tool libraries failed. + // TOOLLIB: {{^}}No OMP tool loaded. + // TOOLLIB-NEXT: {{^}}----- END LOGGING OF TOOL REGISTRATION ----- + // CHECK: {{^}}0: control_tool()=-2