profiler: base::StringPiece -> std::string_view

Bug: 691162
Change-Id: I7a5493d9c2f392c9492091083ce3e35af2ae329c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5353083
Reviewed-by: Giovanni Ortuno Urquidi <ortuno@chromium.org>
Reviewed-by: Charlie Hu <chenleihu@google.com>
Commit-Queue: Giovanni Ortuno Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1271909}
diff --git a/base/profiler/module_cache.cc b/base/profiler/module_cache.cc
index 7911f89e..41c086f 100644
--- a/base/profiler/module_cache.cc
+++ b/base/profiler/module_cache.cc
@@ -5,6 +5,7 @@
 #include "base/profiler/module_cache.h"
 
 #include <iterator>
+#include <string_view>
 #include <utility>
 
 #include "base/check_op.h"
@@ -32,7 +33,7 @@
 
 }  // namespace
 
-std::string TransformModuleIDToSymbolServerFormat(StringPiece module_id) {
+std::string TransformModuleIDToSymbolServerFormat(std::string_view module_id) {
   std::string mangled_id(module_id);
   // Android and Linux Chrome builds use the "breakpad" format to index their
   // build id, so we transform the build id for these platforms. All other
diff --git a/base/profiler/module_cache.h b/base/profiler/module_cache.h
index 335fd33..0a3ca02 100644
--- a/base/profiler/module_cache.h
+++ b/base/profiler/module_cache.h
@@ -8,13 +8,13 @@
 #include <memory>
 #include <set>
 #include <string>
+#include <string_view>
 #include <vector>
 
 #include "base/base_export.h"
 #include "base/containers/flat_set.h"
 #include "base/files/file_path.h"
 #include "base/memory/raw_ptr.h"
-#include "base/strings/string_piece.h"
 #include "build/build_config.h"
 
 #if BUILDFLAG(IS_WIN)
@@ -26,7 +26,7 @@
 // Converts module id to match the id that the Google-internal symbol server
 // expects.
 BASE_EXPORT std::string TransformModuleIDToSymbolServerFormat(
-    StringPiece module_id);
+    std::string_view module_id);
 
 // Supports cached lookup of modules by address, with caching based on module
 // address ranges.
diff --git a/base/profiler/module_cache_posix.cc b/base/profiler/module_cache_posix.cc
index f0a819b..f150a24 100644
--- a/base/profiler/module_cache_posix.cc
+++ b/base/profiler/module_cache_posix.cc
@@ -8,9 +8,9 @@
 #include <elf.h>
 
 #include <optional>
+#include <string_view>
 
 #include "base/debug/elf_reader.h"
-#include "base/strings/string_piece.h"
 #include "build/build_config.h"
 
 #if BUILDFLAG(IS_ANDROID)
@@ -68,12 +68,12 @@
 }
 
 FilePath GetDebugBasenameForModule(const void* base_address,
-                                   base::StringPiece file) {
+                                   std::string_view file) {
 #if BUILDFLAG(IS_ANDROID)
   // Preferentially identify the library using its soname on Android. Libraries
   // mapped directly from apks have the apk filename in |dl_info.dli_fname|, and
   // this doesn't distinguish the particular library.
-  std::optional<StringPiece> library_name =
+  std::optional<std::string_view> library_name =
       debug::ReadElfLibraryName(base_address);
   if (library_name)
     return FilePath(*library_name);
diff --git a/base/profiler/module_cache_unittest.cc b/base/profiler/module_cache_unittest.cc
index 5728e03..277f52e 100644
--- a/base/profiler/module_cache_unittest.cc
+++ b/base/profiler/module_cache_unittest.cc
@@ -2,18 +2,19 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+#include "base/profiler/module_cache.h"
+
 #include <iomanip>
 #include <map>
 #include <memory>
+#include <string_view>
 #include <utility>
 #include <vector>
 
 #include "base/containers/adapters.h"
 #include "base/functional/callback.h"
 #include "base/functional/callback_helpers.h"
-#include "base/profiler/module_cache.h"
 #include "base/ranges/algorithm.h"
-#include "base/strings/string_piece.h"
 #include "base/test/bind.h"
 #include "build/build_config.h"
 #include "testing/gtest/include/gtest/gtest.h"
@@ -347,7 +348,7 @@
   // Map distinct paths to lists of regions for the path in increasing memory
   // order.
   using RegionVector = std::vector<const debug::MappedMemoryRegion*>;
-  using PathRegionsMap = std::map<StringPiece, RegionVector>;
+  using PathRegionsMap = std::map<std::string_view, RegionVector>;
   PathRegionsMap path_regions;
   for (const debug::MappedMemoryRegion& region : regions)
     path_regions[region.path].push_back(&region);
diff --git a/base/profiler/sample_metadata.cc b/base/profiler/sample_metadata.cc
index e4feaa4..9d3cf5b3 100644
--- a/base/profiler/sample_metadata.cc
+++ b/base/profiler/sample_metadata.cc
@@ -5,6 +5,7 @@
 #include "base/profiler/sample_metadata.h"
 
 #include <optional>
+#include <string_view>
 
 #include "base/metrics/metrics_hashes.h"
 #include "base/no_destructor.h"
@@ -24,7 +25,7 @@
 
 }  // namespace
 
-SampleMetadata::SampleMetadata(StringPiece name, SampleMetadataScope scope)
+SampleMetadata::SampleMetadata(std::string_view name, SampleMetadataScope scope)
     : name_hash_(HashMetricName(name)), scope_(scope) {}
 
 void SampleMetadata::Set(int64_t value) {
@@ -47,7 +48,7 @@
                                       GetPlatformThreadIdForScope(scope_));
 }
 
-ScopedSampleMetadata::ScopedSampleMetadata(StringPiece name,
+ScopedSampleMetadata::ScopedSampleMetadata(std::string_view name,
                                            int64_t value,
                                            SampleMetadataScope scope)
     : name_hash_(HashMetricName(name)),
@@ -55,7 +56,7 @@
   GetSampleMetadataRecorder()->Set(name_hash_, std::nullopt, thread_id_, value);
 }
 
-ScopedSampleMetadata::ScopedSampleMetadata(StringPiece name,
+ScopedSampleMetadata::ScopedSampleMetadata(std::string_view name,
                                            int64_t key,
                                            int64_t value,
                                            SampleMetadataScope scope)
@@ -83,7 +84,7 @@
 
 void ApplyMetadataToPastSamples(TimeTicks period_start,
                                 TimeTicks period_end,
-                                StringPiece name,
+                                std::string_view name,
                                 int64_t value,
                                 SampleMetadataScope scope) {
   return ApplyMetadataToPastSamplesImpl(
@@ -93,7 +94,7 @@
 
 void ApplyMetadataToPastSamples(TimeTicks period_start,
                                 TimeTicks period_end,
-                                StringPiece name,
+                                std::string_view name,
                                 int64_t key,
                                 int64_t value,
                                 SampleMetadataScope scope) {
@@ -109,7 +110,7 @@
   StackSamplingProfiler::AddProfileMetadata(name_hash, key, value, thread_id);
 }
 
-void AddProfileMetadata(StringPiece name,
+void AddProfileMetadata(std::string_view name,
                         int64_t key,
                         int64_t value,
                         SampleMetadataScope scope) {
diff --git a/base/profiler/sample_metadata.h b/base/profiler/sample_metadata.h
index e0a34e0a..a4b233d7 100644
--- a/base/profiler/sample_metadata.h
+++ b/base/profiler/sample_metadata.h
@@ -6,10 +6,10 @@
 #define BASE_PROFILER_SAMPLE_METADATA_H_
 
 #include <optional>
+#include <string_view>
 
 #include "base/base_export.h"
 #include "base/profiler/metadata_recorder.h"
-#include "base/strings/string_piece.h"
 #include "base/threading/platform_thread.h"
 
 // -----------------------------------------------------------------------------
@@ -69,7 +69,7 @@
 class BASE_EXPORT SampleMetadata {
  public:
   // Set the metadata value associated with |name| to be recorded for |scope|.
-  explicit SampleMetadata(StringPiece name, SampleMetadataScope scope);
+  explicit SampleMetadata(std::string_view name, SampleMetadataScope scope);
 
   SampleMetadata(const SampleMetadata&) = default;
   ~SampleMetadata() = default;
@@ -116,7 +116,7 @@
 class BASE_EXPORT ScopedSampleMetadata {
  public:
   // Set the metadata value associated with |name| for |scope|.
-  ScopedSampleMetadata(StringPiece name,
+  ScopedSampleMetadata(std::string_view name,
                        int64_t value,
                        SampleMetadataScope scope);
 
@@ -127,7 +127,7 @@
   // different frames. Prefer the previous constructor if no user-defined
   // metadata is required. Note: values specified for a name and key are stored
   // separately from values specified with only a name.
-  ScopedSampleMetadata(StringPiece name,
+  ScopedSampleMetadata(std::string_view name,
                        int64_t key,
                        int64_t value,
                        SampleMetadataScope scope);
@@ -154,12 +154,12 @@
 // extend before or after it. |period_end| must be <= TimeTicks::Now().
 BASE_EXPORT void ApplyMetadataToPastSamples(TimeTicks period_start,
                                             TimeTicks period_end,
-                                            StringPiece name,
+                                            std::string_view name,
                                             int64_t value,
                                             SampleMetadataScope scope);
 BASE_EXPORT void ApplyMetadataToPastSamples(TimeTicks period_start,
                                             TimeTicks period_end,
-                                            StringPiece name,
+                                            std::string_view name,
                                             int64_t key,
                                             int64_t value,
                                             SampleMetadataScope scope);
@@ -169,7 +169,7 @@
 // earlier in time. This is probably not what you want for most use cases;
 // prefer using SampleMetadata / ScopedSampleMetadata /
 // ApplyMetadataToPastSamples instead.
-BASE_EXPORT void AddProfileMetadata(StringPiece name,
+BASE_EXPORT void AddProfileMetadata(std::string_view name,
                                     int64_t key,
                                     int64_t value,
                                     SampleMetadataScope scope);
diff --git a/base/profiler/stack_sampling_profiler_test_util.cc b/base/profiler/stack_sampling_profiler_test_util.cc
index fc41fa8..1505914b 100644
--- a/base/profiler/stack_sampling_profiler_test_util.cc
+++ b/base/profiler/stack_sampling_profiler_test_util.cc
@@ -3,13 +3,14 @@
 // found in the LICENSE file.
 
 #include "base/profiler/stack_sampling_profiler_test_util.h"
-#include "base/memory/raw_ptr.h"
 
+#include <string_view>
 #include <utility>
 
 #include "base/functional/bind.h"
 #include "base/functional/callback.h"
 #include "base/location.h"
+#include "base/memory/raw_ptr.h"
 #include "base/path_service.h"
 #include "base/profiler/native_unwinder_android_map_delegate.h"
 #include "base/profiler/native_unwinder_android_memory_regions_map.h"
@@ -425,7 +426,7 @@
   }
 }
 
-NativeLibrary LoadTestLibrary(StringPiece library_name) {
+NativeLibrary LoadTestLibrary(std::string_view library_name) {
   // The lambda gymnastics works around the fact that we can't use ASSERT_*
   // macros in a function returning non-null.
   const auto load = [&](NativeLibrary* library) {
diff --git a/base/profiler/stack_sampling_profiler_test_util.h b/base/profiler/stack_sampling_profiler_test_util.h
index 17f4f6ec..9f8ac60f 100644
--- a/base/profiler/stack_sampling_profiler_test_util.h
+++ b/base/profiler/stack_sampling_profiler_test_util.h
@@ -7,6 +7,7 @@
 
 #include <memory>
 #include <string>
+#include <string_view>
 #include <vector>
 
 #include "base/base_export.h"
@@ -16,7 +17,6 @@
 #include "base/profiler/frame.h"
 #include "base/profiler/sampling_profiler_thread_token.h"
 #include "base/profiler/stack_sampling_profiler.h"
-#include "base/strings/string_piece.h"
 #include "base/synchronization/waitable_event.h"
 #include "base/threading/platform_thread.h"
 
@@ -178,7 +178,7 @@
     const std::vector<FunctionAddressRange>& functions);
 
 // Load test library with given name.
-NativeLibrary LoadTestLibrary(StringPiece library_name);
+NativeLibrary LoadTestLibrary(std::string_view library_name);
 
 // Loads the other library, which defines a function to be called in the
 // WITH_OTHER_LIBRARY configuration.