aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2020-07-09 01:09:08 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2020-07-09 01:09:08 +0000
commit3b1b3443a76ea1de477f38dc2b0f463402d53d6b (patch)
tree4b0263f6296ec88bc03ee1552cb8bde664cdedcc
parent095d474ced557bc6572fd9b28dc2181e9743f079 (diff)
parent198388c4da3b16dccefb208835c55f8bd261220b (diff)
downloadperfetto-android11-release.tar.gz
Change-Id: I0f0e2eb595e16a42f4609e21a7adaad1ecfce485
-rw-r--r--src/profiling/memory/client.cc6
-rw-r--r--src/profiling/memory/client.h2
-rw-r--r--src/profiling/memory/client_unittest.cc36
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