[OpenMP][NFC] Improve profiling for the offload runtime

GitOrigin-RevId: 5dd1fc700857eb46882c7e27cd8835ef4fee1f22
diff --git a/libomptarget/include/Shared/Profile.h b/libomptarget/include/Shared/Profile.h
index 316b0c3..19ca0cf 100644
--- a/libomptarget/include/Shared/Profile.h
+++ b/libomptarget/include/Shared/Profile.h
@@ -75,7 +75,7 @@
 };
 
 /// Time spend in the current scope, assigned to the function name.
-#define TIMESCOPE() llvm::TimeTraceScope TimeScope(__FUNCTION__)
+#define TIMESCOPE() llvm::TimeTraceScope TimeScope(__PRETTY_FUNCTION__)
 
 /// Time spend in the current scope, assigned to the function name and source
 /// info.
diff --git a/libomptarget/src/OffloadRTL.cpp b/libomptarget/src/OffloadRTL.cpp
index 061b053..86ef0d5 100644
--- a/libomptarget/src/OffloadRTL.cpp
+++ b/libomptarget/src/OffloadRTL.cpp
@@ -21,6 +21,9 @@
 #endif
 
 __attribute__((constructor(101))) void init() {
+  Profiler::get();
+  TIMESCOPE();
+
   DP("Init offload library!\n");
 
   PM = new PluginManager();
@@ -32,7 +35,6 @@
 
   PM->init();
 
-  Profiler::get();
   PM->registerDelayedLibraries();
 }
 
diff --git a/libomptarget/src/PluginManager.cpp b/libomptarget/src/PluginManager.cpp
index 16e04dd..1778728 100644
--- a/libomptarget/src/PluginManager.cpp
+++ b/libomptarget/src/PluginManager.cpp
@@ -12,6 +12,7 @@
 
 #include "PluginManager.h"
 #include "Shared/Debug.h"
+#include "Shared/Profile.h"
 
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -28,6 +29,7 @@
 Expected<std::unique_ptr<PluginAdaptorTy>>
 PluginAdaptorTy::create(const std::string &Name) {
   DP("Attempting to load library '%s'...\n", Name.c_str());
+  TIMESCOPE_WITH_NAME_AND_IDENT(Name, (const ident_t *)nullptr);
 
   std::string ErrMsg;
   auto LibraryHandler = std::make_unique<DynamicLibrary>(
@@ -101,6 +103,7 @@
 }
 
 void PluginManager::init() {
+  TIMESCOPE();
   DP("Loading RTLs...\n");
 
   // Attempt to open all the plugins and, if they exist, check if the interface
@@ -123,6 +126,7 @@
 void PluginAdaptorTy::initDevices(PluginManager &PM) {
   if (isUsed())
     return;
+  TIMESCOPE();
 
   // If this RTL is not already in use, initialize it.
   assert(getNumberOfPluginDevices() > 0 &&