Cleaning up the tracing.h mechanism to enable alternative implementations. (#14044)

Future changes will add compile-time configuration and user config
overrides for the tracing implementation to allow for multiple in-tree
and out-of-tree implementations.
diff --git a/runtime/bindings/python/CMakeLists.txt b/runtime/bindings/python/CMakeLists.txt
index 714aa53..1f8b5aa 100644
--- a/runtime/bindings/python/CMakeLists.txt
+++ b/runtime/bindings/python/CMakeLists.txt
@@ -49,7 +49,6 @@
   DEPS
     iree::base
     iree::base::internal::flags
-    iree::base::tracing
     iree::hal
     iree::hal::drivers
     iree::hal::utils::allocators
diff --git a/runtime/bindings/python/hal.cc b/runtime/bindings/python/hal.cc
index 6f51450..accae92 100644
--- a/runtime/bindings/python/hal.cc
+++ b/runtime/bindings/python/hal.cc
@@ -8,7 +8,6 @@
 
 #include "./vm.h"
 #include "iree/base/internal/path.h"
-#include "iree/base/tracing.h"
 #include "iree/hal/api.h"
 #include "iree/hal/utils/allocators.h"
 #include "iree/modules/hal/module.h"
@@ -84,7 +83,7 @@
 py::object HalAllocator::AllocateBufferCopy(
     int memory_type, int allowed_usage, py::object buffer,
     std::optional<iree_hal_element_types_t> element_type) {
-  IREE_TRACE_SCOPE0("HalAllocator::AllocateBufferCopy");
+  IREE_TRACE_SCOPE_NAMED("HalAllocator::AllocateBufferCopy");
   // Request a view of the buffer (use the raw python C API to avoid
   // some allocation and copying at the pybind level).
   Py_buffer py_view;
diff --git a/runtime/bindings/python/invoke.cc b/runtime/bindings/python/invoke.cc
index eb11c4d..c3b5df1 100644
--- a/runtime/bindings/python/invoke.cc
+++ b/runtime/bindings/python/invoke.cc
@@ -9,7 +9,6 @@
 #include "./hal.h"
 #include "./vm.h"
 #include "iree/base/api.h"
-#include "iree/base/tracing.h"
 #include "iree/hal/api.h"
 #include "iree/modules/hal/module.h"
 #include "iree/vm/api.h"
@@ -163,22 +162,22 @@
                 abi_shape = std::move(abi_shape)](InvokeContext &c,
                                                   iree_vm_list_t *list,
                                                   py::handle py_value) {
-          IREE_TRACE_SCOPE0("ArgumentPacker::ReflectionNdarray");
+          IREE_TRACE_SCOPE_NAMED("ArgumentPacker::ReflectionNdarray");
           HalBufferView *bv = nullptr;
           py::object retained_bv;
           if (py::isinstance(py_value, device_array_type())) {
             // Short-circuit: If a DeviceArray is provided, assume it is
             // correct.
-            IREE_TRACE_SCOPE0("PackDeviceArray");
+            IREE_TRACE_SCOPE_NAMED("PackDeviceArray");
             bv = py::cast<HalBufferView *>(py_value.attr(kAttrBufferView));
           } else if (py::isinstance(py_value, hal_buffer_view_type())) {
             // Short-circuit: If a HalBufferView is provided directly.
-            IREE_TRACE_SCOPE0("PackBufferView");
+            IREE_TRACE_SCOPE_NAMED("PackBufferView");
             bv = py::cast<HalBufferView *>(py_value);
           } else {
             // Fall back to the array protocol to generate a host side
             // array and then convert that.
-            IREE_TRACE_SCOPE0("PackHostArray");
+            IREE_TRACE_SCOPE_NAMED("PackHostArray");
             py::object host_array;
             try {
               host_array = numpy_module().attr(kAsArray)(py_value, target_dtype,
@@ -380,7 +379,7 @@
  private:
   PackCallback GetGenericPackCallbackForNdarray() {
     return [this](InvokeContext &c, iree_vm_list_t *list, py::handle py_value) {
-      IREE_TRACE_SCOPE0("ArgumentPacker::GenericNdarray");
+      IREE_TRACE_SCOPE_NAMED("ArgumentPacker::GenericNdarray");
       py::object host_array;
       try {
         host_array = numpy_module().attr(kAsArray)(
@@ -550,7 +549,7 @@
  public:
   ArgumentPacker(InvokeStatics &statics, std::optional<py::list> arg_descs)
       : statics_(statics) {
-    IREE_TRACE_SCOPE0("ArgumentPacker::Init");
+    IREE_TRACE_SCOPE_NAMED("ArgumentPacker::Init");
     if (!arg_descs) {
       dynamic_dispatch_ = true;
     } else {
@@ -594,7 +593,7 @@
                      py::dict kw_args) {
     // Dynamic dispatch.
     if (dynamic_dispatch_) {
-      IREE_TRACE_SCOPE0("ArgumentPacker::PackDynamic");
+      IREE_TRACE_SCOPE_NAMED("ArgumentPacker::PackDynamic");
       if (!kw_args.empty()) {
         throw std::invalid_argument(
             "kwargs not supported for dynamic dispatch functions");
@@ -614,7 +613,7 @@
       }
       return arg_list;
     } else {
-      IREE_TRACE_SCOPE0("ArgumentPacker::PackReflection");
+      IREE_TRACE_SCOPE_NAMED("ArgumentPacker::PackReflection");
 
       // Reflection based dispatch.
       std::vector<py::handle> py_args(flat_arg_packers_.size());
diff --git a/runtime/bindings/python/vm.cc b/runtime/bindings/python/vm.cc
index 455bd3f..b72ecde 100644
--- a/runtime/bindings/python/vm.cc
+++ b/runtime/bindings/python/vm.cc
@@ -8,7 +8,6 @@
 
 #include "./status_utils.h"
 #include "iree/base/api.h"
-#include "iree/base/tracing.h"
 // TODO: We shouldn't need the HAL API but it is used for direct printing
 // summaries of HAL objects in lists. We should have a better way of doing this
 // dynamically vs hard depending on a type switch here.
@@ -57,7 +56,7 @@
 //------------------------------------------------------------------------------
 
 VmInstance VmInstance::Create() {
-  IREE_TRACE_SCOPE0("VmInstance::Create");
+  IREE_TRACE_SCOPE_NAMED("VmInstance::Create");
 
   iree_vm_instance_t* instance = NULL;
   auto status = iree_vm_instance_create(IREE_VM_TYPE_CAPACITY_DEFAULT,
@@ -79,7 +78,7 @@
 
 VmContext VmContext::Create(VmInstance* instance,
                             std::optional<std::vector<VmModule*>> modules) {
-  IREE_TRACE_SCOPE0("VmContext::Create");
+  IREE_TRACE_SCOPE_NAMED("VmContext::Create");
   iree_vm_context_t* context;
   if (!modules) {
     // Simple create with open allowed modules.
@@ -134,7 +133,7 @@
 VmModule VmModule::ResolveModuleDependency(VmInstance* instance,
                                            const std::string& name,
                                            uint32_t minimum_version) {
-  IREE_TRACE_SCOPE0("VmModule::ResolveModuleDependency");
+  IREE_TRACE_SCOPE_NAMED("VmModule::ResolveModuleDependency");
   iree_vm_module_t* module = nullptr;
 
   iree_vm_module_dependency_t dependency = {
@@ -153,7 +152,7 @@
 
 VmModule VmModule::FromFlatbufferBlob(VmInstance* instance,
                                       py::object flatbuffer_blob_object) {
-  IREE_TRACE_SCOPE0("VmModule::FromFlatbufferBlob");
+  IREE_TRACE_SCOPE_NAMED("VmModule::FromFlatbufferBlob");
   auto flatbuffer_blob = py::cast<py::buffer>(flatbuffer_blob_object);
   auto buffer_info = flatbuffer_blob.request();
   iree_vm_module_t* module = nullptr;