summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libartbase/base/debugstore.h39
-rw-r--r--libartpalette/apex/palette.cc7
-rw-r--r--libartpalette/apex/palette_test.cc30
-rw-r--r--libartpalette/include/palette/palette_method_list.h19
-rw-r--r--libartpalette/libartpalette.map6
-rw-r--r--libartpalette/system/palette_fake.cc6
-rw-r--r--runtime/signal_catcher.cc12
7 files changed, 113 insertions, 6 deletions
diff --git a/libartbase/base/debugstore.h b/libartbase/base/debugstore.h
new file mode 100644
index 0000000000..b3e6563c60
--- /dev/null
+++ b/libartbase/base/debugstore.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ART_LIBARTBASE_BASE_DEBUGSTORE_H_
+#define ART_LIBARTBASE_BASE_DEBUGSTORE_H_
+
+#include <array>
+#include <string>
+
+#include "palette/palette.h"
+
+namespace art {
+static constexpr size_t STORE_MAX_SIZE = 1024;
+
+inline std::string DebugStoreGetString() {
+ std::array<char, STORE_MAX_SIZE> result{};
+ // If PaletteDebugStoreGetString returns PALETTE_STATUS_NOT_SUPPORTED,
+ // set an empty string as the result.
+ result[0] = '\0';
+ PaletteDebugStoreGetString(result.data(), result.size());
+ return std::string(result.data());
+}
+
+} // namespace art
+
+#endif // ART_LIBARTBASE_BASE_DEBUGSTORE_H_
diff --git a/libartpalette/apex/palette.cc b/libartpalette/apex/palette.cc
index 346cd184ff..3efee45173 100644
--- a/libartpalette/apex/palette.cc
+++ b/libartpalette/apex/palette.cc
@@ -254,4 +254,11 @@ palette_status_t PaletteSetTaskProfiles(int32_t tid,
return m(tid, profiles, profiles_len);
}
+// Methods in version 4 API, corresponding to SDK level 36.
+palette_status_t PaletteDebugStoreGetString(char* result, size_t max_size) {
+ PaletteDebugStoreGetStringMethod m =
+ PaletteLoader::Instance().GetPaletteDebugStoreGetStringMethod();
+ return m(result, max_size);
+}
+
} // extern "C"
diff --git a/libartpalette/apex/palette_test.cc b/libartpalette/apex/palette_test.cc
index 63072c491b..d42a60685a 100644
--- a/libartpalette/apex/palette_test.cc
+++ b/libartpalette/apex/palette_test.cc
@@ -21,6 +21,7 @@
#include <sys/syscall.h>
#include <unistd.h>
+#include <cstring>
#include <filesystem>
#ifdef ART_TARGET_ANDROID
@@ -50,6 +51,14 @@ bool PaletteSetTaskProfilesIsSupported(palette_status_t res) {
<< "Device API level: " << android_get_device_api_level();
return false;
}
+bool PaletteDebugStoreIsSupported(palette_status_t res) {
+ if (android::modules::sdklevel::IsAtLeastV()) {
+ return true;
+ }
+ EXPECT_EQ(PALETTE_STATUS_NOT_SUPPORTED, res)
+ << "Device API level: " << android_get_device_api_level();
+ return false;
+}
#endif
} // namespace
@@ -166,3 +175,24 @@ TEST_F(PaletteClientTest, SetTaskProfilesCpp) {
}
#endif
}
+
+TEST_F(PaletteClientTest, DebugStore) {
+#ifndef ART_TARGET_ANDROID
+ GTEST_SKIP() << "DebugStore is only supported on Android";
+#else
+ std::array<char, 20> result{};
+ palette_status_t pstatus = PaletteDebugStoreGetString(result.data(), result.size());
+ // Make sure the we are on a correct API level.
+ if (PaletteDebugStoreIsSupported(pstatus)) {
+ EXPECT_EQ(PALETTE_STATUS_OK, pstatus);
+
+ size_t len = strnlen(result.data(), result.size());
+ EXPECT_TRUE(len < result.size());
+
+ const char* start = "1,0,";
+ const char* end = "::";
+ EXPECT_TRUE(len > strlen(start) + strlen(end));
+ EXPECT_EQ(strncmp(result.data() + len - strlen(end), end, strlen(end)), 0);
+ }
+#endif
+}
diff --git a/libartpalette/include/palette/palette_method_list.h b/libartpalette/include/palette/palette_method_list.h
index e5437cb33a..b2f0476892 100644
--- a/libartpalette/include/palette/palette_method_list.h
+++ b/libartpalette/include/palette/palette_method_list.h
@@ -75,6 +75,23 @@
/* PALETTE_STATUS_NOT_SUPPORTED if the implementation no longer supports this */ \
/* call. This can happen at any future SDK level since this function wraps an */ \
/* internal unstable API. */ \
- M(PaletteSetTaskProfiles, int32_t tid, const char* const profiles[], size_t profiles_len)
+ M(PaletteSetTaskProfiles, int32_t tid, const char* const profiles[], size_t profiles_len) \
+ \
+ /* Methods in version 4 API, corresponding to SDK level 36. */ \
+ \
+ /* Retrieves the debug store as a string. */ \
+ /* */ \
+ /* This function retrieves debug information stored in a predefined debug store. */ \
+ /* The information retrieved are used for debugging and logging purposes. */ \
+ /* */ \
+ /* @param result A pointer to a null-terminated character array where the retrieved */ \
+ /* string will be stored. */ \
+ /* @param max_size The maximum number of characters to be copied into the result, */ \
+ /* including the null terminator. It is the caller's responsibility */ \
+ /* to ensure that the pointed by result is large enough to store */ \
+ /* up to max_size characters. */ \
+ /* @return PALETTE_STATUS_OK if the call succeeded. */ \
+ /* PALETTE_STATUS_INVALID_ARGUMENT if the pointer is a nullptr or max_size is 0 */ \
+ M(PaletteDebugStoreGetString, char* result, size_t max_size)
#endif // ART_LIBARTPALETTE_INCLUDE_PALETTE_PALETTE_METHOD_LIST_H_
diff --git a/libartpalette/libartpalette.map b/libartpalette/libartpalette.map
index 6172a21427..e3c36f5277 100644
--- a/libartpalette/libartpalette.map
+++ b/libartpalette/libartpalette.map
@@ -51,3 +51,9 @@ LIBARTPALETTE_3 { # introduced=34
# --- VERSION 03 API ---
PaletteSetTaskProfiles; # apex
} LIBARTPALETTE_2;
+
+LIBARTPALETTE_4 { # introduced=36
+ global:
+ # --- VERSION 04 API ---
+ PaletteDebugStoreGetString; # apex
+} LIBARTPALETTE_3; \ No newline at end of file
diff --git a/libartpalette/system/palette_fake.cc b/libartpalette/system/palette_fake.cc
index e698267d10..f2fc76d68c 100644
--- a/libartpalette/system/palette_fake.cc
+++ b/libartpalette/system/palette_fake.cc
@@ -147,3 +147,9 @@ palette_status_t PaletteSetTaskProfiles([[maybe_unused]] int32_t tid,
[[maybe_unused]] size_t profiles_len) {
return PALETTE_STATUS_OK;
}
+
+// Methods in version 4 API, corresponding to SDK level 36.
+palette_status_t PaletteDebugStoreGetString([[maybe_unused]] char* result,
+ [[maybe_unused]] size_t max_size) {
+ return PALETTE_STATUS_OK;
+}
diff --git a/runtime/signal_catcher.cc b/runtime/signal_catcher.cc
index 3660ef3a19..09a4b2d85e 100644
--- a/runtime/signal_catcher.cc
+++ b/runtime/signal_catcher.cc
@@ -16,8 +16,8 @@
#include "signal_catcher.h"
-#include <csignal>
-#include <cstdlib>
+#include <android-base/file.h>
+#include <android-base/stringprintf.h>
#include <fcntl.h>
#include <pthread.h>
#include <sys/stat.h>
@@ -25,13 +25,13 @@
#include <sys/types.h>
#include <unistd.h>
+#include <csignal>
+#include <cstdlib>
#include <optional>
#include <sstream>
-#include <android-base/file.h>
-#include <android-base/stringprintf.h>
-
#include "arch/instruction_set.h"
+#include "base/debugstore.h"
#include "base/logging.h" // For GetCmdLine.
#include "base/os.h"
#include "base/time_utils.h"
@@ -136,6 +136,8 @@ void SignalCatcher::HandleSigQuit() {
os << "Build type: " << (kIsDebugBuild ? "debug" : "optimized") << "\n";
+ os << "Debug Store: " << DebugStoreGetString() << "\n";
+
runtime->DumpForSigQuit(os);
if ((false)) {