diff options
author | Cronet Mainline Eng <cronet-mainline-eng+copybara@google.com> | 2024-06-07 18:59:21 +0900 |
---|---|---|
committer | Motomu Utsumi <motomuman@google.com> | 2024-06-07 19:00:37 +0900 |
commit | 93dc77d4cfa4a2996ac5bf4c67b0d4223847eb65 (patch) | |
tree | 92c5aba3655194ff55d27c652a265bd6f87b0470 /base/profiler | |
parent | b66ce594f84a102bf71c3e2754d9c0bfdd620b85 (diff) | |
download | cronet-93dc77d4cfa4a2996ac5bf4c67b0d4223847eb65.tar.gz |
Import Cronet version 124.0.6367.42
FolderOrigin-RevId: /tmp/copybara-origin/src
Change-Id: I727d2277512236d7d0db42e102d291b6204b38e5
Diffstat (limited to 'base/profiler')
24 files changed, 180 insertions, 169 deletions
diff --git a/base/profiler/chrome_unwinder_android.cc b/base/profiler/chrome_unwinder_android.cc index a13f2d1b4..2a4afa133 100644 --- a/base/profiler/chrome_unwinder_android.cc +++ b/base/profiler/chrome_unwinder_android.cc @@ -96,7 +96,7 @@ UnwindResult ChromeUnwinderAndroid::TryUnwind(RegisterContext* thread_context, const uintptr_t instruction_byte_offset_from_text_section_start = pc - text_section_start_address_; - const absl::optional<FunctionOffsetTableIndex> function_offset_table_index = + const std::optional<FunctionOffsetTableIndex> function_offset_table_index = GetFunctionTableIndexFromInstructionOffset( unwind_info_.page_table, unwind_info_.function_table, instruction_byte_offset_from_text_section_start); @@ -299,7 +299,7 @@ uintptr_t GetFirstUnwindInstructionIndexFromFunctionOffsetTableEntry( return 0; } -const absl::optional<FunctionOffsetTableIndex> +const std::optional<FunctionOffsetTableIndex> GetFunctionTableIndexFromInstructionOffset( span<const uint32_t> page_start_instructions, span<const FunctionTableEntry> function_offset_table_indices, @@ -320,7 +320,7 @@ GetFunctionTableIndexFromInstructionOffset( // Invalid instruction_byte_offset_from_text_section_start: // instruction_byte_offset_from_text_section_start falls after the last page. if (page_number >= page_start_instructions.size()) { - return absl::nullopt; + return std::nullopt; } const span<const FunctionTableEntry>::iterator function_table_entry_start = diff --git a/base/profiler/chrome_unwinder_android.h b/base/profiler/chrome_unwinder_android.h index 7f8fdc5f6..c1e1c2081 100644 --- a/base/profiler/chrome_unwinder_android.h +++ b/base/profiler/chrome_unwinder_android.h @@ -7,13 +7,14 @@ #include <stdint.h> +#include <optional> + #include "base/base_export.h" #include "base/containers/span.h" #include "base/profiler/chrome_unwind_info_android.h" #include "base/profiler/module_cache.h" #include "base/profiler/register_context.h" #include "base/profiler/unwinder.h" -#include "third_party/abseil-cpp/absl/types/optional.h" namespace base { @@ -103,7 +104,7 @@ GetFirstUnwindInstructionIndexFromFunctionOffsetTableEntry( // `ChromeUnwindInfoAndroid::function_table` for details. // instruction_byte_offset_from_text_section_start: The distance in bytes // between the instruction of interest and text section start. -BASE_EXPORT const absl::optional<FunctionOffsetTableIndex> +BASE_EXPORT const std::optional<FunctionOffsetTableIndex> GetFunctionTableIndexFromInstructionOffset( span<const uint32_t> page_start_instructions, span<const FunctionTableEntry> function_offset_table_indices, diff --git a/base/profiler/chrome_unwinder_android_unittest.cc b/base/profiler/chrome_unwinder_android_unittest.cc index 8995b9c13..731b60b27 100644 --- a/base/profiler/chrome_unwinder_android_unittest.cc +++ b/base/profiler/chrome_unwinder_android_unittest.cc @@ -759,7 +759,7 @@ TEST(ChromeUnwinderAndroidTest, TestAddressTableLookupEntryInPage) { page_start_instructions, function_offset_table_indices, /* instruction_offset */ (page_instruction_offset << 1) + (page_number << 17)); - ASSERT_NE(absl::nullopt, entry_found); + ASSERT_NE(std::nullopt, entry_found); EXPECT_EQ(0, entry_found->instruction_offset_from_function_start); EXPECT_EQ(40ul, entry_found->function_offset_table_byte_index); } @@ -771,7 +771,7 @@ TEST(ChromeUnwinderAndroidTest, TestAddressTableLookupEntryInPage) { page_start_instructions, function_offset_table_indices, /* instruction_offset */ (page_instruction_offset << 1) + (page_number << 17)); - ASSERT_NE(absl::nullopt, entry_found); + ASSERT_NE(std::nullopt, entry_found); EXPECT_EQ(46, entry_found->instruction_offset_from_function_start); EXPECT_EQ(40ul, entry_found->function_offset_table_byte_index); } @@ -784,7 +784,7 @@ TEST(ChromeUnwinderAndroidTest, TestAddressTableLookupEntryInPage) { page_start_instructions, function_offset_table_indices, /* instruction_offset */ (page_instruction_offset << 1) + (page_number << 17)); - ASSERT_NE(absl::nullopt, entry_found); + ASSERT_NE(std::nullopt, entry_found); // 0xffff - 6 = 0xfff9. EXPECT_EQ(0xfff9, entry_found->instruction_offset_from_function_start); EXPECT_EQ(70ul, entry_found->function_offset_table_byte_index); @@ -813,7 +813,7 @@ TEST(ChromeUnwinderAndroidTest, TestAddressTableLookupEmptyPage) { page_start_instructions, function_offset_table_indices, /* instruction_offset */ (page_instruction_offset << 1) + (page_number << 17)); - ASSERT_NE(absl::nullopt, entry_found); + ASSERT_NE(std::nullopt, entry_found); EXPECT_EQ(0x10004, entry_found->instruction_offset_from_function_start); EXPECT_EQ(20ul, entry_found->function_offset_table_byte_index); } @@ -842,7 +842,7 @@ TEST(ChromeUnwinderAndroidTest, TestAddressTableLookupInvalidIntructionOffset) { page_start_instructions, function_offset_table_indices, /* instruction_offset */ (page_instruction_offset << 1) + (page_number << 17)); - ASSERT_EQ(absl::nullopt, entry_found); + ASSERT_EQ(std::nullopt, entry_found); } { const uint32_t page_number = 2; @@ -851,7 +851,7 @@ TEST(ChromeUnwinderAndroidTest, TestAddressTableLookupInvalidIntructionOffset) { page_start_instructions, function_offset_table_indices, /* instruction_offset */ (page_instruction_offset << 1) + (page_number << 17)); - ASSERT_EQ(absl::nullopt, entry_found); + ASSERT_EQ(std::nullopt, entry_found); } } @@ -881,7 +881,7 @@ TEST(ChromeUnwinderAndroidTest, page_start_instructions, function_offset_table_indices, /* instruction_offset */ (page_instruction_offset << 1) + (page_number << 17)); - ASSERT_NE(absl::nullopt, entry_found); + ASSERT_NE(std::nullopt, entry_found); EXPECT_EQ(0x10004, entry_found->instruction_offset_from_function_start); EXPECT_EQ(20ul, entry_found->function_offset_table_byte_index); } @@ -912,7 +912,7 @@ TEST(ChromeUnwinderAndroidTest, page_start_instructions, function_offset_table_indices, /* instruction_offset */ (page_instruction_offset << 1) + (page_number << 17)); - ASSERT_NE(absl::nullopt, entry_found); + ASSERT_NE(std::nullopt, entry_found); EXPECT_EQ(0x4, entry_found->instruction_offset_from_function_start); EXPECT_EQ(20ul, entry_found->function_offset_table_byte_index); } @@ -923,7 +923,7 @@ TEST(ChromeUnwinderAndroidTest, page_start_instructions, function_offset_table_indices, /* instruction_offset */ (page_instruction_offset << 1) + (page_number << 17)); - ASSERT_NE(absl::nullopt, entry_found); + ASSERT_NE(std::nullopt, entry_found); EXPECT_EQ(0x10004, entry_found->instruction_offset_from_function_start); EXPECT_EQ(20ul, entry_found->function_offset_table_byte_index); } @@ -934,7 +934,7 @@ TEST(ChromeUnwinderAndroidTest, page_start_instructions, function_offset_table_indices, /* instruction_offset */ (page_instruction_offset << 1) + (page_number << 17)); - ASSERT_NE(absl::nullopt, entry_found); + ASSERT_NE(std::nullopt, entry_found); EXPECT_EQ(0x20004, entry_found->instruction_offset_from_function_start); EXPECT_EQ(20ul, entry_found->function_offset_table_byte_index); } @@ -945,7 +945,7 @@ TEST(ChromeUnwinderAndroidTest, page_start_instructions, function_offset_table_indices, /* instruction_offset */ (page_instruction_offset << 1) + (page_number << 17)); - ASSERT_NE(absl::nullopt, entry_found); + ASSERT_NE(std::nullopt, entry_found); EXPECT_EQ(0x30004, entry_found->instruction_offset_from_function_start); EXPECT_EQ(20ul, entry_found->function_offset_table_byte_index); } diff --git a/base/profiler/metadata_recorder.cc b/base/profiler/metadata_recorder.cc index 9f4d2af7f..4888d9ce2 100644 --- a/base/profiler/metadata_recorder.cc +++ b/base/profiler/metadata_recorder.cc @@ -4,16 +4,17 @@ #include "base/profiler/metadata_recorder.h" +#include <optional> + #include "base/metrics/histogram_macros.h" -#include "third_party/abseil-cpp/absl/types/optional.h" namespace base { const size_t MetadataRecorder::MAX_METADATA_COUNT; MetadataRecorder::Item::Item(uint64_t name_hash, - absl::optional<int64_t> key, - absl::optional<PlatformThreadId> thread_id, + std::optional<int64_t> key, + std::optional<PlatformThreadId> thread_id, int64_t value) : name_hash(name_hash), key(key), thread_id(thread_id), value(value) {} @@ -37,8 +38,8 @@ MetadataRecorder::MetadataRecorder() { MetadataRecorder::~MetadataRecorder() = default; void MetadataRecorder::Set(uint64_t name_hash, - absl::optional<int64_t> key, - absl::optional<PlatformThreadId> thread_id, + std::optional<int64_t> key, + std::optional<PlatformThreadId> thread_id, int64_t value) { AutoLock lock(write_lock_); @@ -86,8 +87,8 @@ void MetadataRecorder::Set(uint64_t name_hash, } void MetadataRecorder::Remove(uint64_t name_hash, - absl::optional<int64_t> key, - absl::optional<PlatformThreadId> thread_id) { + std::optional<int64_t> key, + std::optional<PlatformThreadId> thread_id) { AutoLock lock(write_lock_); size_t item_slots_used = item_slots_used_.load(std::memory_order_relaxed); diff --git a/base/profiler/metadata_recorder.h b/base/profiler/metadata_recorder.h index b0f8c3628..e90284392 100644 --- a/base/profiler/metadata_recorder.h +++ b/base/profiler/metadata_recorder.h @@ -7,6 +7,7 @@ #include <array> #include <atomic> +#include <optional> #include <utility> #include "base/base_export.h" @@ -14,7 +15,6 @@ #include "base/synchronization/lock.h" #include "base/thread_annotations.h" #include "base/threading/platform_thread.h" -#include "third_party/abseil-cpp/absl/types/optional.h" namespace base { @@ -132,8 +132,8 @@ class BASE_EXPORT MetadataRecorder { struct BASE_EXPORT Item { Item(uint64_t name_hash, - absl::optional<int64_t> key, - absl::optional<PlatformThreadId> thread_id, + std::optional<int64_t> key, + std::optional<PlatformThreadId> thread_id, int64_t value); Item(); @@ -143,10 +143,10 @@ class BASE_EXPORT MetadataRecorder { // The hash of the metadata name, as produced by HashMetricName(). uint64_t name_hash; // The key if specified when setting the item. - absl::optional<int64_t> key; + std::optional<int64_t> key; // The thread_id is captured from the current thread for a thread-scoped // item. - absl::optional<PlatformThreadId> thread_id; + std::optional<PlatformThreadId> thread_id; // The value of the metadata item. int64_t value; }; @@ -157,15 +157,15 @@ class BASE_EXPORT MetadataRecorder { // value previously set for the tuple. Nullopt keys are treated as just // another key state for the purpose of associating values. void Set(uint64_t name_hash, - absl::optional<int64_t> key, - absl::optional<PlatformThreadId> thread_id, + std::optional<int64_t> key, + std::optional<PlatformThreadId> thread_id, int64_t value); // Removes the item with the specified name hash and optional key. Has no // effect if such an item does not exist. void Remove(uint64_t name_hash, - absl::optional<int64_t> key, - absl::optional<PlatformThreadId> thread_id); + std::optional<int64_t> key, + std::optional<PlatformThreadId> thread_id); // An object that provides access to a MetadataRecorder's items and holds the // necessary exclusive read lock until the object is destroyed. Reclaiming of @@ -235,8 +235,8 @@ class BASE_EXPORT MetadataRecorder { // we're guaranteed that |name_hash|, |key| and |thread_id| will be finished // writing before |is_active| is set to true. uint64_t name_hash; - absl::optional<int64_t> key; - absl::optional<PlatformThreadId> thread_id; + std::optional<int64_t> key; + std::optional<PlatformThreadId> thread_id; // Requires atomic reads and writes to avoid word tearing when updating an // existing item unsynchronized. Does not require acquire/release semantics diff --git a/base/profiler/metadata_recorder_unittest.cc b/base/profiler/metadata_recorder_unittest.cc index c41b7c698..889d8ff4d 100644 --- a/base/profiler/metadata_recorder_unittest.cc +++ b/base/profiler/metadata_recorder_unittest.cc @@ -4,11 +4,12 @@ #include "base/profiler/metadata_recorder.h" +#include <optional> + #include "base/ranges/algorithm.h" #include "base/test/gtest_util.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" -#include "third_party/abseil-cpp/absl/types/optional.h" namespace base { @@ -37,7 +38,7 @@ TEST(MetadataRecorderTest, GetItems_Empty) { TEST(MetadataRecorderTest, Set_NewNameHash) { MetadataRecorder recorder; - recorder.Set(10, absl::nullopt, absl::nullopt, 20); + recorder.Set(10, std::nullopt, std::nullopt, 20); MetadataRecorder::ItemArray items; size_t item_count; @@ -52,7 +53,7 @@ TEST(MetadataRecorderTest, Set_NewNameHash) { EXPECT_EQ(20, items[0].value); } - recorder.Set(20, absl::nullopt, absl::nullopt, 30); + recorder.Set(20, std::nullopt, std::nullopt, 30); { item_count = MetadataRecorder::MetadataProvider(&recorder, @@ -68,8 +69,8 @@ TEST(MetadataRecorderTest, Set_NewNameHash) { TEST(MetadataRecorderTest, Set_ExistingNameNash) { MetadataRecorder recorder; - recorder.Set(10, absl::nullopt, absl::nullopt, 20); - recorder.Set(10, absl::nullopt, absl::nullopt, 30); + recorder.Set(10, std::nullopt, std::nullopt, 20); + recorder.Set(10, std::nullopt, std::nullopt, 30); MetadataRecorder::ItemArray items; size_t item_count = @@ -87,16 +88,16 @@ TEST(MetadataRecorderTest, Set_ReAddRemovedNameNash) { MetadataRecorder::ItemArray items; std::vector<MetadataRecorder::Item> expected; for (size_t i = 0; i < items.size(); ++i) { - expected.emplace_back(i, absl::nullopt, absl::nullopt, 0); - recorder.Set(i, absl::nullopt, absl::nullopt, 0); + expected.emplace_back(i, std::nullopt, std::nullopt, 0); + recorder.Set(i, std::nullopt, std::nullopt, 0); } // By removing an item from a full recorder, re-setting the same item, and // verifying that the item is returned, we can verify that the recorder is // reusing the inactive slot for the same name hash instead of trying (and // failing) to allocate a new slot. - recorder.Remove(3, absl::nullopt, absl::nullopt); - recorder.Set(3, absl::nullopt, absl::nullopt, 0); + recorder.Remove(3, std::nullopt, std::nullopt); + recorder.Set(3, std::nullopt, std::nullopt, 0); size_t item_count = MetadataRecorder::MetadataProvider(&recorder, PlatformThread::CurrentId()) @@ -109,17 +110,17 @@ TEST(MetadataRecorderTest, Set_AddPastMaxCount) { MetadataRecorder recorder; MetadataRecorder::ItemArray items; for (size_t i = 0; i < items.size(); ++i) { - recorder.Set(i, absl::nullopt, absl::nullopt, 0); + recorder.Set(i, std::nullopt, std::nullopt, 0); } // This should fail silently. - recorder.Set(items.size(), absl::nullopt, absl::nullopt, 0); + recorder.Set(items.size(), std::nullopt, std::nullopt, 0); } TEST(MetadataRecorderTest, Set_NulloptKeyIsIndependentOfNonNulloptKey) { MetadataRecorder recorder; - recorder.Set(10, 100, absl::nullopt, 20); + recorder.Set(10, 100, std::nullopt, 20); MetadataRecorder::ItemArray items; size_t item_count; @@ -134,7 +135,7 @@ TEST(MetadataRecorderTest, Set_NulloptKeyIsIndependentOfNonNulloptKey) { EXPECT_EQ(20, items[0].value); } - recorder.Set(10, absl::nullopt, absl::nullopt, 30); + recorder.Set(10, std::nullopt, std::nullopt, 30); { item_count = MetadataRecorder::MetadataProvider(&recorder, @@ -156,7 +157,7 @@ TEST(MetadataRecorderTest, Set_NulloptKeyIsIndependentOfNonNulloptKey) { TEST(MetadataRecorderTest, Set_ThreadIdIsScoped) { MetadataRecorder recorder; - recorder.Set(10, absl::nullopt, PlatformThread::CurrentId(), 20); + recorder.Set(10, std::nullopt, PlatformThread::CurrentId(), 20); MetadataRecorder::ItemArray items; size_t item_count; @@ -181,8 +182,8 @@ TEST(MetadataRecorderTest, Set_ThreadIdIsScoped) { TEST(MetadataRecorderTest, Set_NulloptThreadAndNonNulloptThread) { MetadataRecorder recorder; - recorder.Set(10, absl::nullopt, PlatformThread::CurrentId(), 20); - recorder.Set(10, absl::nullopt, absl::nullopt, 30); + recorder.Set(10, std::nullopt, PlatformThread::CurrentId(), 20); + recorder.Set(10, std::nullopt, std::nullopt, 30); MetadataRecorder::ItemArray items; size_t item_count = @@ -203,10 +204,10 @@ TEST(MetadataRecorderTest, Set_NulloptThreadAndNonNulloptThread) { TEST(MetadataRecorderTest, Remove) { MetadataRecorder recorder; - recorder.Set(10, absl::nullopt, absl::nullopt, 20); - recorder.Set(30, absl::nullopt, absl::nullopt, 40); - recorder.Set(50, absl::nullopt, absl::nullopt, 60); - recorder.Remove(30, absl::nullopt, absl::nullopt); + recorder.Set(10, std::nullopt, std::nullopt, 20); + recorder.Set(30, std::nullopt, std::nullopt, 40); + recorder.Set(50, std::nullopt, std::nullopt, 60); + recorder.Remove(30, std::nullopt, std::nullopt); MetadataRecorder::ItemArray items; size_t item_count = @@ -223,8 +224,8 @@ TEST(MetadataRecorderTest, Remove) { TEST(MetadataRecorderTest, Remove_DoesntExist) { MetadataRecorder recorder; - recorder.Set(10, absl::nullopt, absl::nullopt, 20); - recorder.Remove(20, absl::nullopt, absl::nullopt); + recorder.Set(10, std::nullopt, std::nullopt, 20); + recorder.Remove(20, std::nullopt, std::nullopt); MetadataRecorder::ItemArray items; size_t item_count = @@ -239,10 +240,10 @@ TEST(MetadataRecorderTest, Remove_DoesntExist) { TEST(MetadataRecorderTest, Remove_NulloptKeyIsIndependentOfNonNulloptKey) { MetadataRecorder recorder; - recorder.Set(10, 100, absl::nullopt, 20); - recorder.Set(10, absl::nullopt, absl::nullopt, 30); + recorder.Set(10, 100, std::nullopt, 20); + recorder.Set(10, std::nullopt, std::nullopt, 30); - recorder.Remove(10, absl::nullopt, absl::nullopt); + recorder.Remove(10, std::nullopt, std::nullopt); MetadataRecorder::ItemArray items; size_t item_count = @@ -259,10 +260,10 @@ TEST(MetadataRecorderTest, Remove_NulloptThreadIsIndependentOfNonNulloptThread) { MetadataRecorder recorder; - recorder.Set(10, absl::nullopt, PlatformThread::CurrentId(), 20); - recorder.Set(10, absl::nullopt, absl::nullopt, 30); + recorder.Set(10, std::nullopt, PlatformThread::CurrentId(), 20); + recorder.Set(10, std::nullopt, std::nullopt, 30); - recorder.Remove(10, absl::nullopt, absl::nullopt); + recorder.Remove(10, std::nullopt, std::nullopt); MetadataRecorder::ItemArray items; size_t item_count = @@ -282,25 +283,25 @@ TEST(MetadataRecorderTest, ReclaimInactiveSlots) { std::set<MetadataRecorder::Item> items_set; // Fill up the metadata map. for (size_t i = 0; i < MetadataRecorder::MAX_METADATA_COUNT; ++i) { - recorder.Set(i, absl::nullopt, absl::nullopt, i); - items_set.insert(MetadataRecorder::Item{i, absl::nullopt, absl::nullopt, + recorder.Set(i, std::nullopt, std::nullopt, i); + items_set.insert(MetadataRecorder::Item{i, std::nullopt, std::nullopt, static_cast<int64_t>(i)}); } // Remove every fourth entry to fragment the data. size_t entries_removed = 0; for (size_t i = 3; i < MetadataRecorder::MAX_METADATA_COUNT; i += 4) { - recorder.Remove(i, absl::nullopt, absl::nullopt); + recorder.Remove(i, std::nullopt, std::nullopt); ++entries_removed; - items_set.erase(MetadataRecorder::Item{i, absl::nullopt, absl::nullopt, + items_set.erase(MetadataRecorder::Item{i, std::nullopt, std::nullopt, static_cast<int64_t>(i)}); } // Ensure that the inactive slots are reclaimed to make room for more entries. for (size_t i = 1; i <= entries_removed; ++i) { - recorder.Set(i * 100, absl::nullopt, absl::nullopt, i * 100); - items_set.insert(MetadataRecorder::Item{ - i * 100, absl::nullopt, absl::nullopt, static_cast<int64_t>(i * 100)}); + recorder.Set(i * 100, std::nullopt, std::nullopt, i * 100); + items_set.insert(MetadataRecorder::Item{i * 100, std::nullopt, std::nullopt, + static_cast<int64_t>(i * 100)}); } MetadataRecorder::ItemArray items_arr; diff --git a/base/profiler/module_cache.cc b/base/profiler/module_cache.cc index 7911f89e5..41c086f5a 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 @@ struct ModuleAddressCompare { } // 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 335fd330d..0a3ca023c 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 @@ namespace base { // 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 e00b0b580..f150a2487 100644 --- a/base/profiler/module_cache_posix.cc +++ b/base/profiler/module_cache_posix.cc @@ -7,10 +7,11 @@ #include <dlfcn.h> #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" -#include "third_party/abseil-cpp/absl/types/optional.h" #if BUILDFLAG(IS_ANDROID) extern "C" { @@ -67,12 +68,12 @@ size_t GetLastExecutableOffset(const void* module_addr) { } 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. - absl::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 59154b0d7..277f52e47 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" @@ -25,7 +26,7 @@ // Note: The special-case IS_CHROMEOS code inside GetDebugBasenameForModule to // handle the interaction between that function and // SetProcessTitleFromCommandLine() is tested in -// content/common/set_process_title_linux_unittest.cc due to dependency issues. +// base/process/set_process_title_linux_unittest.cc due to dependency issues. namespace base { namespace { @@ -347,7 +348,7 @@ TEST(ModuleCacheTest, CheckAgainstProcMaps) { // 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(®ion); diff --git a/base/profiler/sample_metadata.cc b/base/profiler/sample_metadata.cc index f93b36432..9d3cf5b32 100644 --- a/base/profiler/sample_metadata.cc +++ b/base/profiler/sample_metadata.cc @@ -4,30 +4,32 @@ #include "base/profiler/sample_metadata.h" +#include <optional> +#include <string_view> + #include "base/metrics/metrics_hashes.h" #include "base/no_destructor.h" #include "base/profiler/stack_sampling_profiler.h" #include "base/threading/thread_local.h" -#include "third_party/abseil-cpp/absl/types/optional.h" namespace base { namespace { -absl::optional<PlatformThreadId> GetPlatformThreadIdForScope( +std::optional<PlatformThreadId> GetPlatformThreadIdForScope( SampleMetadataScope scope) { if (scope == SampleMetadataScope::kProcess) - return absl::nullopt; + return std::nullopt; return PlatformThread::CurrentId(); } } // 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) { - GetSampleMetadataRecorder()->Set(name_hash_, absl::nullopt, + GetSampleMetadataRecorder()->Set(name_hash_, std::nullopt, GetPlatformThreadIdForScope(scope_), value); } @@ -37,7 +39,7 @@ void SampleMetadata::Set(int64_t key, int64_t value) { } void SampleMetadata::Remove() { - GetSampleMetadataRecorder()->Remove(name_hash_, absl::nullopt, + GetSampleMetadataRecorder()->Remove(name_hash_, std::nullopt, GetPlatformThreadIdForScope(scope_)); } @@ -46,16 +48,15 @@ void SampleMetadata::Remove(int64_t key) { GetPlatformThreadIdForScope(scope_)); } -ScopedSampleMetadata::ScopedSampleMetadata(StringPiece name, +ScopedSampleMetadata::ScopedSampleMetadata(std::string_view name, int64_t value, SampleMetadataScope scope) : name_hash_(HashMetricName(name)), thread_id_(GetPlatformThreadIdForScope(scope)) { - GetSampleMetadataRecorder()->Set(name_hash_, absl::nullopt, thread_id_, - value); + 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) @@ -71,30 +72,29 @@ ScopedSampleMetadata::~ScopedSampleMetadata() { // This function is friended by StackSamplingProfiler so must live directly in // the base namespace. -void ApplyMetadataToPastSamplesImpl( - TimeTicks period_start, - TimeTicks period_end, - uint64_t name_hash, - absl::optional<int64_t> key, - int64_t value, - absl::optional<PlatformThreadId> thread_id) { +void ApplyMetadataToPastSamplesImpl(TimeTicks period_start, + TimeTicks period_end, + uint64_t name_hash, + std::optional<int64_t> key, + int64_t value, + std::optional<PlatformThreadId> thread_id) { StackSamplingProfiler::ApplyMetadataToPastSamples( period_start, period_end, name_hash, key, value, thread_id); } void ApplyMetadataToPastSamples(TimeTicks period_start, TimeTicks period_end, - StringPiece name, + std::string_view name, int64_t value, SampleMetadataScope scope) { return ApplyMetadataToPastSamplesImpl( - period_start, period_end, HashMetricName(name), absl::nullopt, value, + period_start, period_end, HashMetricName(name), std::nullopt, value, GetPlatformThreadIdForScope(scope)); } void ApplyMetadataToPastSamples(TimeTicks period_start, TimeTicks period_end, - StringPiece name, + std::string_view name, int64_t key, int64_t value, SampleMetadataScope scope) { @@ -106,11 +106,11 @@ void ApplyMetadataToPastSamples(TimeTicks period_start, void AddProfileMetadataImpl(uint64_t name_hash, int64_t key, int64_t value, - absl::optional<PlatformThreadId> thread_id) { + std::optional<PlatformThreadId> thread_id) { 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 48fb0e811..a4b233d70 100644 --- a/base/profiler/sample_metadata.h +++ b/base/profiler/sample_metadata.h @@ -5,11 +5,12 @@ #ifndef BASE_PROFILER_SAMPLE_METADATA_H_ #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" -#include "third_party/abseil-cpp/absl/types/optional.h" // ----------------------------------------------------------------------------- // Usage documentation @@ -68,7 +69,7 @@ enum class SampleMetadataScope { 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; @@ -115,7 +116,7 @@ class BASE_EXPORT SampleMetadata { 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); @@ -126,7 +127,7 @@ class BASE_EXPORT ScopedSampleMetadata { // 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); @@ -138,8 +139,8 @@ class BASE_EXPORT ScopedSampleMetadata { private: const uint64_t name_hash_; - absl::optional<int64_t> key_; - absl::optional<PlatformThreadId> thread_id_; + std::optional<int64_t> key_; + std::optional<PlatformThreadId> thread_id_; }; // Applies the specified metadata to samples already recorded between @@ -153,12 +154,12 @@ class BASE_EXPORT ScopedSampleMetadata { // 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); @@ -168,7 +169,7 @@ BASE_EXPORT void ApplyMetadataToPastSamples(TimeTicks period_start, // 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/sampling_profiler_thread_token.cc b/base/profiler/sampling_profiler_thread_token.cc index 8186e673d..5ef3ec4a5 100644 --- a/base/profiler/sampling_profiler_thread_token.cc +++ b/base/profiler/sampling_profiler_thread_token.cc @@ -19,7 +19,7 @@ SamplingProfilerThreadToken GetSamplingProfilerCurrentThreadToken() { #if BUILDFLAG(IS_ANDROID) return {id, pthread_self()}; #elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) - absl::optional<uintptr_t> maybe_stack_base = + std::optional<uintptr_t> maybe_stack_base = GetThreadStackBaseAddress(id, pthread_self()); return {id, maybe_stack_base}; #else diff --git a/base/profiler/sampling_profiler_thread_token.h b/base/profiler/sampling_profiler_thread_token.h index 43ca39569..c2e9ef1b5 100644 --- a/base/profiler/sampling_profiler_thread_token.h +++ b/base/profiler/sampling_profiler_thread_token.h @@ -5,10 +5,11 @@ #ifndef BASE_PROFILER_SAMPLING_PROFILER_THREAD_TOKEN_H_ #define BASE_PROFILER_SAMPLING_PROFILER_THREAD_TOKEN_H_ +#include <optional> + #include "base/base_export.h" #include "base/threading/platform_thread.h" #include "build/build_config.h" -#include "third_party/abseil-cpp/absl/types/optional.h" #if BUILDFLAG(IS_ANDROID) #include <pthread.h> @@ -30,7 +31,7 @@ struct SamplingProfilerThreadToken { // Due to the sandbox, we can only retrieve the stack base address for the // current thread. We must grab it during // GetSamplingProfilerCurrentThreadToken() and not try to get it later. - absl::optional<uintptr_t> stack_base_address; + std::optional<uintptr_t> stack_base_address; #endif }; diff --git a/base/profiler/stack_base_address_posix.cc b/base/profiler/stack_base_address_posix.cc index c49b1bb23..082106f8d 100644 --- a/base/profiler/stack_base_address_posix.cc +++ b/base/profiler/stack_base_address_posix.cc @@ -26,12 +26,12 @@ namespace base { namespace { #if BUILDFLAG(IS_ANDROID) -absl::optional<uintptr_t> GetAndroidMainThreadStackBaseAddressImpl() { +std::optional<uintptr_t> GetAndroidMainThreadStackBaseAddressImpl() { char line[1024]; base::ScopedFILE fp(base::OpenFile(base::FilePath("/proc/self/maps"), "r")); uintptr_t stack_addr = reinterpret_cast<uintptr_t>(line); if (!fp) - return absl::nullopt; + return std::nullopt; while (fgets(line, sizeof(line), fp.get()) != nullptr) { uintptr_t start, end; if (sscanf(line, "%" SCNxPTR "-%" SCNxPTR, &start, &end) == 2) { @@ -39,7 +39,7 @@ absl::optional<uintptr_t> GetAndroidMainThreadStackBaseAddressImpl() { return end; } } - return absl::nullopt; + return std::nullopt; } #endif @@ -71,14 +71,14 @@ uintptr_t GetThreadStackBaseAddressImpl(pthread_t pthread_id) { } // namespace -absl::optional<uintptr_t> GetThreadStackBaseAddress(PlatformThreadId id, - pthread_t pthread_id) { +std::optional<uintptr_t> GetThreadStackBaseAddress(PlatformThreadId id, + pthread_t pthread_id) { #if BUILDFLAG(IS_LINUX) // We don't currently support Linux; pthread_getattr_np() fails for the main // thread after zygote forks. https://crbug.com/1394278. Since we don't // support stack profiling at all on Linux, we just return nullopt instead of // trying to work around the problem. - return absl::nullopt; + return std::nullopt; #else const bool is_main_thread = id == GetCurrentProcId(); if (is_main_thread) { @@ -88,7 +88,7 @@ absl::optional<uintptr_t> GetThreadStackBaseAddress(PlatformThreadId id, // read or parse the file. So, try to read the maps to get the main thread // stack base and cache the result. Other thread base addresses are sourced // from pthread state so are cheap to get. - static const absl::optional<uintptr_t> main_thread_base_address = + static const std::optional<uintptr_t> main_thread_base_address = GetAndroidMainThreadStackBaseAddressImpl(); return main_thread_base_address; #elif BUILDFLAG(IS_CHROMEOS) diff --git a/base/profiler/stack_base_address_posix.h b/base/profiler/stack_base_address_posix.h index 9769c036c..04c4e8a5d 100644 --- a/base/profiler/stack_base_address_posix.h +++ b/base/profiler/stack_base_address_posix.h @@ -8,9 +8,10 @@ #include <pthread.h> #include <stdint.h> +#include <optional> + #include "base/base_export.h" #include "base/threading/platform_thread.h" -#include "third_party/abseil-cpp/absl/types/optional.h" namespace base { @@ -25,7 +26,7 @@ namespace base { // // May return nullopt on Android if the thread's memory range is not found in // /proc/self/maps. -BASE_EXPORT absl::optional<uintptr_t> GetThreadStackBaseAddress( +BASE_EXPORT std::optional<uintptr_t> GetThreadStackBaseAddress( PlatformThreadId id, pthread_t pthread_id); diff --git a/base/profiler/stack_base_address_posix_unittest.cc b/base/profiler/stack_base_address_posix_unittest.cc index 498df04c5..6c602ad61 100644 --- a/base/profiler/stack_base_address_posix_unittest.cc +++ b/base/profiler/stack_base_address_posix_unittest.cc @@ -28,7 +28,7 @@ using ::testing::Optional; #define MAYBE_CurrentThread CurrentThread #endif TEST(GetThreadStackBaseAddressTest, MAYBE_CurrentThread) { - absl::optional<uintptr_t> base = + std::optional<uintptr_t> base = GetThreadStackBaseAddress(PlatformThread::CurrentId(), pthread_self()); EXPECT_THAT(base, Optional(Gt(0u))); uintptr_t stack_addr = reinterpret_cast<uintptr_t>(&base); @@ -41,7 +41,7 @@ TEST(GetThreadStackBaseAddressTest, MAYBE_CurrentThread) { TEST(GetThreadStackBaseAddressTest, MainThread) { // GetThreadStackBaseAddress does not use pthread_id for main thread on these // platforms. - absl::optional<uintptr_t> base = + std::optional<uintptr_t> base = GetThreadStackBaseAddress(GetCurrentProcId(), pthread_t()); EXPECT_THAT(base, Optional(Gt(0u))); } diff --git a/base/profiler/stack_copier_signal.cc b/base/profiler/stack_copier_signal.cc index 36bc79e11..6ad23536e 100644 --- a/base/profiler/stack_copier_signal.cc +++ b/base/profiler/stack_copier_signal.cc @@ -13,6 +13,7 @@ #include <atomic> #include <cstring> +#include <optional> #include "base/memory/raw_ptr.h" #include "base/memory/raw_ptr_exclusion.h" @@ -23,7 +24,6 @@ #include "base/time/time_override.h" #include "base/trace_event/base_tracing.h" #include "build/build_config.h" -#include "third_party/abseil-cpp/absl/types/optional.h" namespace base { @@ -129,7 +129,7 @@ struct HandlerParams { RAW_PTR_EXCLUSION const uint8_t** stack_copy_bottom; // The timestamp when the stack was copied. - RAW_PTR_EXCLUSION absl::optional<TimeTicks>* maybe_timestamp; + RAW_PTR_EXCLUSION std::optional<TimeTicks>* maybe_timestamp; // The delegate provided to the StackCopier. RAW_PTR_EXCLUSION StackCopier::Delegate* stack_copier_delegate; @@ -148,7 +148,7 @@ void CopyStackSignalHandler(int n, siginfo_t* siginfo, void* sigcontext) { // MaybeTimeTicksNowIgnoringOverride() is implemented in terms of // clock_gettime on Linux, which is signal safe per the signal-safety(7) man - // page, but is not garanteed to succeed, in which case absl::nullopt is + // page, but is not garanteed to succeed, in which case std::nullopt is // returned. TimeTicks::Now() can't be used because it expects clock_gettime // to always succeed and is thus not signal-safe. *params->maybe_timestamp = subtle::MaybeTimeTicksNowIgnoringOverride(); @@ -234,7 +234,7 @@ bool StackCopierSignal::CopyStack(StackBuffer* stack_buffer, bool copied = false; const uint8_t* stack_copy_bottom = nullptr; const uintptr_t stack_base_address = thread_delegate_->GetStackBaseAddress(); - absl::optional<TimeTicks> maybe_timestamp; + std::optional<TimeTicks> maybe_timestamp; HandlerParams params = {stack_base_address, &wait_event, &copied, thread_context, stack_buffer, &stack_copy_bottom, &maybe_timestamp, delegate}; diff --git a/base/profiler/stack_sampling_profiler.cc b/base/profiler/stack_sampling_profiler.cc index 7697ef6d3..d6d3070ba 100644 --- a/base/profiler/stack_sampling_profiler.cc +++ b/base/profiler/stack_sampling_profiler.cc @@ -7,6 +7,7 @@ #include <algorithm> #include <cmath> #include <map> +#include <optional> #include <utility> #include "base/atomic_sequence_num.h" @@ -30,7 +31,6 @@ #include "base/time/time.h" #include "base/trace_event/base_tracing.h" #include "build/build_config.h" -#include "third_party/abseil-cpp/absl/types/optional.h" #if BUILDFLAG(IS_WIN) #include "base/win/static_constants.h" @@ -180,16 +180,16 @@ class StackSamplingProfiler::SamplingThread : public Thread { void ApplyMetadataToPastSamples(base::TimeTicks period_start, base::TimeTicks period_end, uint64_t name_hash, - absl::optional<int64_t> key, + std::optional<int64_t> key, int64_t value, - absl::optional<PlatformThreadId> thread_id); + std::optional<PlatformThreadId> thread_id); // Adds the metadata as profile metadata. Profile metadata stores metadata // global to the profile. void AddProfileMetadata(uint64_t name_hash, - absl::optional<int64_t> key, + std::optional<int64_t> key, int64_t value, - absl::optional<PlatformThreadId> thread_id); + std::optional<PlatformThreadId> thread_id); // Removes an active collection based on its collection id, forcing it to run // its callback if any data has been collected. This can be called externally @@ -246,13 +246,13 @@ class StackSamplingProfiler::SamplingThread : public Thread { base::TimeTicks period_start, base::TimeTicks period_end, uint64_t name_hash, - absl::optional<int64_t> key, + std::optional<int64_t> key, int64_t value, - absl::optional<PlatformThreadId> thread_id); + std::optional<PlatformThreadId> thread_id); void AddProfileMetadataTask(uint64_t name_hash, - absl::optional<int64_t> key, + std::optional<int64_t> key, int64_t value, - absl::optional<PlatformThreadId> thread_id); + std::optional<PlatformThreadId> thread_id); void RemoveCollectionTask(int collection_id); void RecordSampleTask(int collection_id); void ShutdownTask(int add_events); @@ -418,9 +418,9 @@ void StackSamplingProfiler::SamplingThread::ApplyMetadataToPastSamples( base::TimeTicks period_start, base::TimeTicks period_end, uint64_t name_hash, - absl::optional<int64_t> key, + std::optional<int64_t> key, int64_t value, - absl::optional<PlatformThreadId> thread_id) { + std::optional<PlatformThreadId> thread_id) { ThreadExecutionState state; scoped_refptr<SingleThreadTaskRunner> task_runner = GetTaskRunner(&state); if (state != RUNNING) @@ -434,9 +434,9 @@ void StackSamplingProfiler::SamplingThread::ApplyMetadataToPastSamples( void StackSamplingProfiler::SamplingThread::AddProfileMetadata( uint64_t name_hash, - absl::optional<int64_t> key, + std::optional<int64_t> key, int64_t value, - absl::optional<PlatformThreadId> thread_id) { + std::optional<PlatformThreadId> thread_id) { ThreadExecutionState state; scoped_refptr<SingleThreadTaskRunner> task_runner = GetTaskRunner(&state); if (state != RUNNING) { @@ -603,9 +603,9 @@ void StackSamplingProfiler::SamplingThread::ApplyMetadataToPastSamplesTask( base::TimeTicks period_start, base::TimeTicks period_end, uint64_t name_hash, - absl::optional<int64_t> key, + std::optional<int64_t> key, int64_t value, - absl::optional<PlatformThreadId> thread_id) { + std::optional<PlatformThreadId> thread_id) { DCHECK_EQ(GetThreadId(), PlatformThread::CurrentId()); MetadataRecorder::Item item(name_hash, key, thread_id, value); for (auto& id_collection_pair : active_collections_) { @@ -618,9 +618,9 @@ void StackSamplingProfiler::SamplingThread::ApplyMetadataToPastSamplesTask( void StackSamplingProfiler::SamplingThread::AddProfileMetadataTask( uint64_t name_hash, - absl::optional<int64_t> key, + std::optional<int64_t> key, int64_t value, - absl::optional<PlatformThreadId> thread_id) { + std::optional<PlatformThreadId> thread_id) { DCHECK_EQ(GetThreadId(), PlatformThread::CurrentId()); MetadataRecorder::Item item(name_hash, key, thread_id, value); for (auto& id_collection_pair : active_collections_) { @@ -938,9 +938,9 @@ void StackSamplingProfiler::ApplyMetadataToPastSamples( base::TimeTicks period_start, base::TimeTicks period_end, uint64_t name_hash, - absl::optional<int64_t> key, + std::optional<int64_t> key, int64_t value, - absl::optional<PlatformThreadId> thread_id) { + std::optional<PlatformThreadId> thread_id) { SamplingThread::GetInstance()->ApplyMetadataToPastSamples( period_start, period_end, name_hash, key, value, thread_id); } @@ -950,7 +950,7 @@ void StackSamplingProfiler::AddProfileMetadata( uint64_t name_hash, int64_t key, int64_t value, - absl::optional<PlatformThreadId> thread_id) { + std::optional<PlatformThreadId> thread_id) { SamplingThread::GetInstance()->AddProfileMetadata(name_hash, key, value, thread_id); } diff --git a/base/profiler/stack_sampling_profiler.h b/base/profiler/stack_sampling_profiler.h index f8d27fe12..c5f428b22 100644 --- a/base/profiler/stack_sampling_profiler.h +++ b/base/profiler/stack_sampling_profiler.h @@ -6,6 +6,7 @@ #define BASE_PROFILER_STACK_SAMPLING_PROFILER_H_ #include <memory> +#include <optional> #include <vector> #include "base/base_export.h" @@ -15,7 +16,6 @@ #include "base/synchronization/waitable_event.h" #include "base/threading/platform_thread.h" #include "base/time/time.h" -#include "third_party/abseil-cpp/absl/types/optional.h" namespace base { @@ -180,14 +180,13 @@ class BASE_EXPORT StackSamplingProfiler { TimeTicks period_start, TimeTicks period_end, uint64_t name_hash, - absl::optional<int64_t> key, + std::optional<int64_t> key, int64_t value, - absl::optional<PlatformThreadId> thread_id); - friend void AddProfileMetadataImpl( - uint64_t name_hash, - int64_t key, - int64_t value, - absl::optional<PlatformThreadId> thread_id); + std::optional<PlatformThreadId> thread_id); + friend void AddProfileMetadataImpl(uint64_t name_hash, + int64_t key, + int64_t value, + std::optional<PlatformThreadId> thread_id); // Apply metadata to already recorded samples. See the // ApplyMetadataToPastSamples() docs in sample_metadata.h. @@ -195,15 +194,15 @@ class BASE_EXPORT StackSamplingProfiler { TimeTicks period_start, TimeTicks period_end, uint64_t name_hash, - absl::optional<int64_t> key, + std::optional<int64_t> key, int64_t value, - absl::optional<PlatformThreadId> thread_id); + std::optional<PlatformThreadId> thread_id); // Adds metadata as metadata global to the sampling profile. static void AddProfileMetadata(uint64_t name_hash, int64_t key, int64_t value, - absl::optional<PlatformThreadId> thread_id); + std::optional<PlatformThreadId> thread_id); // The thread whose stack will be sampled. SamplingProfilerThreadToken thread_token_; diff --git a/base/profiler/stack_sampling_profiler_test_util.cc b/base/profiler/stack_sampling_profiler_test_util.cc index fc41fa88e..1505914b8 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 @@ void ExpectStackDoesNotContain( } } -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 17f4f6ec3..9f8ac60fa 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 @@ void ExpectStackDoesNotContain( 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. diff --git a/base/profiler/stack_sampling_profiler_unittest.cc b/base/profiler/stack_sampling_profiler_unittest.cc index 4f5f421c5..4f9ebe944 100644 --- a/base/profiler/stack_sampling_profiler_unittest.cc +++ b/base/profiler/stack_sampling_profiler_unittest.cc @@ -323,8 +323,9 @@ void TestLibraryUnload(bool wait_until_unloaded, ModuleCache* module_cache) { NativeLibrary other_library = LoadOtherLibrary(); - UnwindScenario scenario( - BindRepeating(&CallThroughOtherLibrary, Unretained(other_library))); + // TODO(https://crbug.com/1380714): Remove `UnsafeDanglingUntriaged` + UnwindScenario scenario(BindRepeating( + &CallThroughOtherLibrary, UnsafeDanglingUntriaged(other_library))); UnwindScenario::SampleEvents events; TargetThread target_thread( diff --git a/base/profiler/thread_delegate_posix.cc b/base/profiler/thread_delegate_posix.cc index d70413aaa..cc085950e 100644 --- a/base/profiler/thread_delegate_posix.cc +++ b/base/profiler/thread_delegate_posix.cc @@ -8,10 +8,11 @@ #include <pthread.h> #include <stdio.h> +#include <optional> + #include "base/memory/ptr_util.h" #include "base/process/process_handle.h" #include "build/build_config.h" -#include "third_party/abseil-cpp/absl/types/optional.h" #if !(BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) #include "base/profiler/stack_base_address_posix.h" @@ -21,7 +22,7 @@ namespace base { // static std::unique_ptr<ThreadDelegatePosix> ThreadDelegatePosix::Create( SamplingProfilerThreadToken thread_token) { - absl::optional<uintptr_t> base_address; + std::optional<uintptr_t> base_address; #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) base_address = thread_token.stack_base_address; #else |