diff options
author | Florian Mayer <fmayer@google.com> | 2020-07-07 14:46:36 +0100 |
---|---|---|
committer | Florian Mayer <fmayer@google.com> | 2020-07-08 09:22:31 +0000 |
commit | 198388c4da3b16dccefb208835c55f8bd261220b (patch) | |
tree | 4b0263f6296ec88bc03ee1552cb8bde664cdedcc | |
parent | a3502b504d3c4868bd8716e00dd649101bbe3cb3 (diff) | |
download | perfetto-android11-dev.tar.gz |
Fix incorrect max retry calculation.android11-dev
Bug: 160681127
(this is a cherry-pick of 5cffa459a75e4875ddf4c57c9efb19bef3cd3d9f)
Change-Id: I64ed9ffc30978e21662f6be6f32b3c8fa7dd364f
Merged-In: I64ed9ffc30978e21662f6be6f32b3c8fa7dd364f
-rw-r--r-- | src/profiling/memory/client.cc | 6 | ||||
-rw-r--r-- | src/profiling/memory/client.h | 2 | ||||
-rw-r--r-- | src/profiling/memory/client_unittest.cc | 36 |
3 files changed, 40 insertions, 4 deletions
diff --git a/src/profiling/memory/client.cc b/src/profiling/memory/client.cc index a194f754f..d7ea37022 100644 --- a/src/profiling/memory/client.cc +++ b/src/profiling/memory/client.cc @@ -86,19 +86,17 @@ int UnsetDumpable(int) { return 0; } -constexpr uint64_t kInfiniteTries = 0; +} // namespace uint64_t GetMaxTries(const ClientConfiguration& client_config) { if (!client_config.block_client) return 1u; if (client_config.block_client_timeout_us == 0) return kInfiniteTries; - return std::min<uint64_t>( + return std::max<uint64_t>( 1ul, client_config.block_client_timeout_us / kResendBackoffUs); } -} // namespace - const char* GetThreadStackBase() { pthread_attr_t attr; if (pthread_getattr_np(pthread_self(), &attr) != 0) diff --git a/src/profiling/memory/client.h b/src/profiling/memory/client.h index c6e581ec4..0ef00bed8 100644 --- a/src/profiling/memory/client.h +++ b/src/profiling/memory/client.h @@ -35,8 +35,10 @@ namespace perfetto { namespace profiling { +uint64_t GetMaxTries(const ClientConfiguration& client_config); const char* GetThreadStackBase(); +constexpr uint64_t kInfiniteTries = 0; constexpr uint32_t kClientSockTimeoutMs = 1000; // Profiling client, used to sample and record the malloc/free family of calls, diff --git a/src/profiling/memory/client_unittest.cc b/src/profiling/memory/client_unittest.cc index 68b2ee7ca..62f09093b 100644 --- a/src/profiling/memory/client_unittest.cc +++ b/src/profiling/memory/client_unittest.cc @@ -20,6 +20,7 @@ #include "perfetto/base/thread_utils.h" #include "perfetto/ext/base/unix_socket.h" +#include "src/profiling/memory/wire_protocol.h" #include "test/gtest_and_gmock.h" namespace perfetto { @@ -50,6 +51,41 @@ TEST(ClientTest, IsMainThread) { th.join(); } +TEST(ClientTest, GetMaxTriesBlock) { + ClientConfiguration cfg = {}; + cfg.block_client = true; + cfg.block_client_timeout_us = 200; + EXPECT_EQ(GetMaxTries(cfg), 2u); +} + +TEST(ClientTest, GetMaxTriesBlockSmall) { + ClientConfiguration cfg = {}; + cfg.block_client = true; + cfg.block_client_timeout_us = 99; + EXPECT_EQ(GetMaxTries(cfg), 1u); +} + +TEST(ClientTest, GetMaxTriesBlockVerySmall) { + ClientConfiguration cfg = {}; + cfg.block_client = true; + cfg.block_client_timeout_us = 1; + EXPECT_EQ(GetMaxTries(cfg), 1u); +} + +TEST(ClientTest, GetMaxTriesBlockInfinite) { + ClientConfiguration cfg = {}; + cfg.block_client = true; + cfg.block_client_timeout_us = 0; + EXPECT_EQ(GetMaxTries(cfg), kInfiniteTries); +} + +TEST(ClientTest, GetMaxTriesNoBlock) { + ClientConfiguration cfg = {}; + cfg.block_client = false; + cfg.block_client_timeout_us = 200; + EXPECT_EQ(GetMaxTries(cfg), 1u); +} + } // namespace } // namespace profiling } // namespace perfetto |