Loading Android.bp +6 −0 Original line number Diff line number Diff line Loading @@ -105,7 +105,13 @@ aidl_library { cc_library_headers { name: "libandroid_headers_private", host_supported: true, export_include_dirs: ["include/private"], target: { windows: { enabled: true, }, }, } filegroup { Loading cmds/dumpstate/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -114,6 +114,7 @@ cc_defaults { "libincidentcompanion", "libdumpsys", "libserviceutils", "android.tracing.flags_c_lib", ], } Loading cmds/dumpstate/dumpstate.cpp +114 −66 Original line number Diff line number Diff line Loading @@ -17,49 +17,9 @@ #define LOG_TAG "dumpstate" #define ATRACE_TAG ATRACE_TAG_ALWAYS #include <dirent.h> #include <errno.h> #include <fcntl.h> #include <inttypes.h> #include <libgen.h> #include <limits.h> #include <math.h> #include <poll.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/mount.h> #include <sys/poll.h> #include <sys/prctl.h> #include <sys/resource.h> #include <sys/stat.h> #include <sys/time.h> #include <sys/wait.h> #include <signal.h> #include <stdarg.h> #include <string.h> #include <sys/capability.h> #include <sys/inotify.h> #include <sys/klog.h> #include <time.h> #include <unistd.h> #include <chrono> #include <cmath> #include <fstream> #include <functional> #include <future> #include <memory> #include <numeric> #include <regex> #include <set> #include <string> #include <utility> #include <vector> #include "dumpstate.h" #include <aidl/android/hardware/dumpstate/IDumpstateDevice.h> #include <android_app_admin_flags.h> #include <android-base/file.h> #include <android-base/properties.h> #include <android-base/scopeguard.h> Loading @@ -74,6 +34,8 @@ #include <android/hardware/dumpstate/1.1/types.h> #include <android/hidl/manager/1.0/IServiceManager.h> #include <android/os/IIncidentCompanion.h> #include <android_app_admin_flags.h> #include <android_tracing.h> #include <binder/IServiceManager.h> #include <cutils/multiuser.h> #include <cutils/native_handle.h> Loading @@ -81,21 +43,60 @@ #include <cutils/sockets.h> #include <cutils/trace.h> #include <debuggerd/client.h> #include <dirent.h> #include <dumpsys.h> #include <dumputils/dump_utils.h> #include <errno.h> #include <fcntl.h> #include <hardware_legacy/power.h> #include <hidl/ServiceManagement.h> #include <inttypes.h> #include <libgen.h> #include <limits.h> #include <log/log.h> #include <log/log_read.h> #include <math.h> #include <openssl/sha.h> #include <poll.h> #include <private/android_filesystem_config.h> #include <private/android_logger.h> #include <serviceutils/PriorityDumper.h> #include <signal.h> #include <stdarg.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/capability.h> #include <sys/inotify.h> #include <sys/klog.h> #include <sys/mount.h> #include <sys/poll.h> #include <sys/prctl.h> #include <sys/resource.h> #include <sys/stat.h> #include <sys/time.h> #include <sys/wait.h> #include <time.h> #include <unistd.h> #include <utils/StrongPointer.h> #include <vintf/VintfObject.h> #include <chrono> #include <cmath> #include <fstream> #include <functional> #include <future> #include <memory> #include <numeric> #include <regex> #include <set> #include <string> #include <utility> #include <vector> #include "DumpstateInternal.h" #include "DumpstateService.h" #include "dumpstate.h" namespace dumpstate_hal_hidl_1_0 = android::hardware::dumpstate::V1_0; namespace dumpstate_hal_hidl = android::hardware::dumpstate::V1_1; Loading Loading @@ -248,7 +249,7 @@ static const std::string DUMP_NETSTATS_PROTO_TASK = "DUMP NETSTATS PROTO"; static const std::string DUMP_HALS_TASK = "DUMP HALS"; static const std::string DUMP_BOARD_TASK = "dumpstate_board()"; static const std::string DUMP_CHECKINS_TASK = "DUMP CHECKINS"; static const std::string POST_PROCESS_UI_TRACES_TASK = "POST-PROCESS UI TRACES"; static const std::string SERIALIZE_PERFETTO_TRACE_TASK = "SERIALIZE PERFETTO TRACE"; namespace android { namespace os { Loading Loading @@ -1088,11 +1089,11 @@ static void DumpNetstatsProto() { static void MaybeAddSystemTraceToZip() { // This function copies into the .zip the system trace that was snapshotted // by the early call to MaybeSnapshotSystemTrace(), if any background // by the early call to MaybeSnapshotSystemTraceAsync(), if any background // tracing was happening. bool system_trace_exists = access(SYSTEM_TRACE_SNAPSHOT, F_OK) == 0; if (!system_trace_exists) { // No background trace was happening at the time MaybeSnapshotSystemTrace() was invoked. // No background trace was happening at the time MaybeSnapshotSystemTraceAsync() was invoked if (!PropertiesHelper::IsUserBuild()) { MYLOGI( "No system traces found. Check for previously uploaded traces by looking for " Loading Loading @@ -1564,6 +1565,13 @@ static void DumpstateLimitedOnly() { RunDumpsys("DROPBOX SYSTEM SERVER CRASHES", {"dropbox", "-p", "system_server_crash"}); RunDumpsys("DROPBOX SYSTEM APP CRASHES", {"dropbox", "-p", "system_app_crash"}); printf("========================================================\n"); printf("== ANR Traces\n"); printf("========================================================\n"); AddAnrTraceFiles(); printf("========================================================\n"); printf("== Final progress (pid %d): %d/%d (estimated %d)\n", ds.pid_, ds.progress_->Get(), ds.progress_->GetMax(), ds.progress_->GetInitialMax()); Loading Loading @@ -1647,7 +1655,7 @@ Dumpstate::RunStatus Dumpstate::dumpstate() { // Enqueue slow functions into the thread pool, if the parallel run is enabled. std::future<std::string> dump_hals, dump_incident_report, dump_board, dump_checkins, dump_netstats_report, post_process_ui_traces; dump_netstats_report; if (ds.dump_pool_) { // Pool was shutdown in DumpstateDefaultAfterCritical method in order to // drop root user. Restarts it. Loading Loading @@ -3161,8 +3169,9 @@ void Dumpstate::Cancel() { } void Dumpstate::PreDumpUiData() { MaybeSnapshotSystemTrace(); auto snapshot_system_trace = MaybeSnapshotSystemTraceAsync(); MaybeSnapshotUiTraces(); MaybeWaitForSnapshotSystemTrace(std::move(snapshot_system_trace)); } /* Loading Loading @@ -3348,13 +3357,15 @@ Dumpstate::RunStatus Dumpstate::RunInternal(int32_t calling_uid, // duration is logged into MYLOG instead. PrintHeader(); std::future<std::string> snapshot_system_trace; bool is_dumpstate_restricted = options_->telephony_only || options_->wifi_only || options_->limited_only; if (!is_dumpstate_restricted) { // Snapshot the system trace now (if running) to avoid that dumpstate's // own activity pushes out interesting data from the trace ring buffer. // The trace file is added to the zip by MaybeAddSystemTraceToZip(). MaybeSnapshotSystemTrace(); snapshot_system_trace = MaybeSnapshotSystemTraceAsync(); // Invoke critical dumpsys to preserve system state, before doing anything else. RunDumpsysCritical(); Loading @@ -3365,6 +3376,7 @@ Dumpstate::RunStatus Dumpstate::RunInternal(int32_t calling_uid, } MaybeTakeEarlyScreenshot(); MaybeWaitForSnapshotSystemTrace(std::move(snapshot_system_trace)); onUiIntensiveBugreportDumpsFinished(calling_uid); MaybeCheckUserConsent(calling_uid, calling_package); if (options_->telephony_only) { Loading Loading @@ -3461,20 +3473,35 @@ void Dumpstate::MaybeTakeEarlyScreenshot() { TakeScreenshot(); } void Dumpstate::MaybeSnapshotSystemTrace() { std::future<std::string> Dumpstate::MaybeSnapshotSystemTraceAsync() { // When capturing traces via bugreport handler (BH), this function will be invoked twice: // 1) When BH invokes IDumpstate::PreDumpUiData() // 2) When BH invokes IDumpstate::startBugreport(flags = BUGREPORT_USE_PREDUMPED_UI_DATA) // In this case we don't want to re-invoke perfetto in step 2. // In all other standard invocation states, this function is invoked once // without the flag BUGREPORT_USE_PREDUMPED_UI_DATA. // This function must run asynchronously to avoid delaying MaybeTakeEarlyScreenshot() in the // standard invocation states (b/316110955). if (options_->use_predumped_ui_data) { return; return {}; } // Create temporary file for the command's output std::string outPath = ds.bugreport_internal_dir_ + "/tmp_serialize_perfetto_trace"; auto outFd = android::base::unique_fd(TEMP_FAILURE_RETRY( open(outPath.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))); if (outFd < 0) { MYLOGE("Could not open %s to serialize perfetto trace.\n", outPath.c_str()); return {}; } // If a stale file exists already, remove it. unlink(SYSTEM_TRACE_SNAPSHOT); MYLOGI("Launching async '%s'", SERIALIZE_PERFETTO_TRACE_TASK.c_str()) return std::async( std::launch::async, [this, outPath = std::move(outPath), outFd = std::move(outFd)] { // If a background system trace is happening and is marked as "suitable for // bugreport" (i.e. bugreport_score > 0 in the trace config), this command // will stop it and serialize into SYSTEM_TRACE_SNAPSHOT. In the (likely) Loading @@ -3482,10 +3509,23 @@ void Dumpstate::MaybeSnapshotSystemTrace() { // Note: this should not be enqueued as we need to freeze the trace before // dumpstate starts. Otherwise the trace ring buffers will contain mostly // the dumpstate's own activity which is irrelevant. RunCommand("SERIALIZE PERFETTO TRACE", {"perfetto", "--save-for-bugreport"}, CommandOptions::WithTimeout(10).DropRoot().CloseAllFileDescriptorsOnExec().Build()); RunCommand( SERIALIZE_PERFETTO_TRACE_TASK, {"perfetto", "--save-for-bugreport"}, CommandOptions::WithTimeout(10).DropRoot().CloseAllFileDescriptorsOnExec().Build(), false, outFd); // MaybeAddSystemTraceToZip() will take care of copying the trace in the zip // file in the later stages. return outPath; }); } void Dumpstate::MaybeWaitForSnapshotSystemTrace(std::future<std::string> task) { if (!task.valid()) { return; } WaitForTask(std::move(task), SERIALIZE_PERFETTO_TRACE_TASK, STDOUT_FILENO); } void Dumpstate::MaybeSnapshotUiTraces() { Loading @@ -3493,16 +3533,24 @@ void Dumpstate::MaybeSnapshotUiTraces() { return; } const std::vector<std::vector<std::string>> dumpTracesForBugReportCommands = { {"dumpsys", "activity", "service", "SystemUIService", "WMShell", "protolog", "save-for-bugreport"}, {"dumpsys", "activity", "service", "SystemUIService", "WMShell", "transitions", "tracing", "save-for-bugreport"}, std::vector<std::vector<std::string>> dumpTracesForBugReportCommands = { {"cmd", "input_method", "tracing", "save-for-bugreport"}, {"cmd", "window", "tracing", "save-for-bugreport"}, {"cmd", "window", "shell", "tracing", "save-for-bugreport"}, }; if (!android_tracing_perfetto_transition_tracing()) { dumpTracesForBugReportCommands.push_back({"dumpsys", "activity", "service", "SystemUIService", "WMShell", "transitions", "tracing", "save-for-bugreport"}); } if (!android_tracing_perfetto_protolog_tracing()) { dumpTracesForBugReportCommands.push_back({"dumpsys", "activity", "service", "SystemUIService", "WMShell", "protolog", "save-for-bugreport"}); } for (const auto& command : dumpTracesForBugReportCommands) { RunCommand( // Empty name because it's not intended to be classified as a bugreport section. Loading cmds/dumpstate/dumpstate.h +2 −1 Original line number Diff line number Diff line Loading @@ -570,7 +570,8 @@ class Dumpstate { RunStatus dumpstate(); void MaybeTakeEarlyScreenshot(); void MaybeSnapshotSystemTrace(); std::future<std::string> MaybeSnapshotSystemTraceAsync(); void MaybeWaitForSnapshotSystemTrace(std::future<std::string> task); void MaybeSnapshotUiTraces(); void MaybeAddUiTracesToZip(); Loading cmds/dumpstate/tests/dumpstate_test.cpp +24 −20 Original line number Diff line number Diff line Loading @@ -16,23 +16,7 @@ #define LOG_TAG "dumpstate_test" #include "DumpstateInternal.h" #include "DumpstateService.h" #include "android/os/BnDumpstate.h" #include "dumpstate.h" #include "DumpPool.h" #include <gmock/gmock.h> #include <gmock/gmock-matchers.h> #include <gtest/gtest.h> #include <fcntl.h> #include <libgen.h> #include <signal.h> #include <sys/types.h> #include <unistd.h> #include <filesystem> #include <thread> #include <aidl/android/hardware/dumpstate/IDumpstateDevice.h> #include <android-base/file.h> Loading @@ -41,10 +25,27 @@ #include <android-base/strings.h> #include <android-base/unique_fd.h> #include <android/hardware/dumpstate/1.1/types.h> #include <android_tracing.h> #include <cutils/log.h> #include <cutils/properties.h> #include <fcntl.h> #include <gmock/gmock-matchers.h> #include <gmock/gmock.h> #include <gtest/gtest.h> #include <libgen.h> #include <signal.h> #include <sys/types.h> #include <unistd.h> #include <ziparchive/zip_archive.h> #include <filesystem> #include <thread> #include "DumpPool.h" #include "DumpstateInternal.h" #include "DumpstateService.h" #include "android/os/BnDumpstate.h" namespace android { namespace os { namespace dumpstate { Loading Loading @@ -999,10 +1000,13 @@ TEST_F(DumpstateTest, DumpPool_withParallelRunDisabled_isNull) { TEST_F(DumpstateTest, PreDumpUiData) { // These traces are always enabled, i.e. they are always pre-dumped const std::vector<std::filesystem::path> uiTraces = { std::filesystem::path{"/data/misc/wmtrace/wm_transition_trace.winscope"}, std::filesystem::path{"/data/misc/wmtrace/shell_transition_trace.winscope"}, }; std::vector<std::filesystem::path> uiTraces; if (!android_tracing_perfetto_transition_tracing()) { uiTraces.push_back( std::filesystem::path{"/data/misc/wmtrace/wm_transition_trace.winscope"}); uiTraces.push_back( std::filesystem::path{"/data/misc/wmtrace/shell_transition_trace.winscope"}); } for (const auto traceFile : uiTraces) { std::system(("rm -f " + traceFile.string()).c_str()); Loading Loading
Android.bp +6 −0 Original line number Diff line number Diff line Loading @@ -105,7 +105,13 @@ aidl_library { cc_library_headers { name: "libandroid_headers_private", host_supported: true, export_include_dirs: ["include/private"], target: { windows: { enabled: true, }, }, } filegroup { Loading
cmds/dumpstate/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -114,6 +114,7 @@ cc_defaults { "libincidentcompanion", "libdumpsys", "libserviceutils", "android.tracing.flags_c_lib", ], } Loading
cmds/dumpstate/dumpstate.cpp +114 −66 Original line number Diff line number Diff line Loading @@ -17,49 +17,9 @@ #define LOG_TAG "dumpstate" #define ATRACE_TAG ATRACE_TAG_ALWAYS #include <dirent.h> #include <errno.h> #include <fcntl.h> #include <inttypes.h> #include <libgen.h> #include <limits.h> #include <math.h> #include <poll.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/mount.h> #include <sys/poll.h> #include <sys/prctl.h> #include <sys/resource.h> #include <sys/stat.h> #include <sys/time.h> #include <sys/wait.h> #include <signal.h> #include <stdarg.h> #include <string.h> #include <sys/capability.h> #include <sys/inotify.h> #include <sys/klog.h> #include <time.h> #include <unistd.h> #include <chrono> #include <cmath> #include <fstream> #include <functional> #include <future> #include <memory> #include <numeric> #include <regex> #include <set> #include <string> #include <utility> #include <vector> #include "dumpstate.h" #include <aidl/android/hardware/dumpstate/IDumpstateDevice.h> #include <android_app_admin_flags.h> #include <android-base/file.h> #include <android-base/properties.h> #include <android-base/scopeguard.h> Loading @@ -74,6 +34,8 @@ #include <android/hardware/dumpstate/1.1/types.h> #include <android/hidl/manager/1.0/IServiceManager.h> #include <android/os/IIncidentCompanion.h> #include <android_app_admin_flags.h> #include <android_tracing.h> #include <binder/IServiceManager.h> #include <cutils/multiuser.h> #include <cutils/native_handle.h> Loading @@ -81,21 +43,60 @@ #include <cutils/sockets.h> #include <cutils/trace.h> #include <debuggerd/client.h> #include <dirent.h> #include <dumpsys.h> #include <dumputils/dump_utils.h> #include <errno.h> #include <fcntl.h> #include <hardware_legacy/power.h> #include <hidl/ServiceManagement.h> #include <inttypes.h> #include <libgen.h> #include <limits.h> #include <log/log.h> #include <log/log_read.h> #include <math.h> #include <openssl/sha.h> #include <poll.h> #include <private/android_filesystem_config.h> #include <private/android_logger.h> #include <serviceutils/PriorityDumper.h> #include <signal.h> #include <stdarg.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/capability.h> #include <sys/inotify.h> #include <sys/klog.h> #include <sys/mount.h> #include <sys/poll.h> #include <sys/prctl.h> #include <sys/resource.h> #include <sys/stat.h> #include <sys/time.h> #include <sys/wait.h> #include <time.h> #include <unistd.h> #include <utils/StrongPointer.h> #include <vintf/VintfObject.h> #include <chrono> #include <cmath> #include <fstream> #include <functional> #include <future> #include <memory> #include <numeric> #include <regex> #include <set> #include <string> #include <utility> #include <vector> #include "DumpstateInternal.h" #include "DumpstateService.h" #include "dumpstate.h" namespace dumpstate_hal_hidl_1_0 = android::hardware::dumpstate::V1_0; namespace dumpstate_hal_hidl = android::hardware::dumpstate::V1_1; Loading Loading @@ -248,7 +249,7 @@ static const std::string DUMP_NETSTATS_PROTO_TASK = "DUMP NETSTATS PROTO"; static const std::string DUMP_HALS_TASK = "DUMP HALS"; static const std::string DUMP_BOARD_TASK = "dumpstate_board()"; static const std::string DUMP_CHECKINS_TASK = "DUMP CHECKINS"; static const std::string POST_PROCESS_UI_TRACES_TASK = "POST-PROCESS UI TRACES"; static const std::string SERIALIZE_PERFETTO_TRACE_TASK = "SERIALIZE PERFETTO TRACE"; namespace android { namespace os { Loading Loading @@ -1088,11 +1089,11 @@ static void DumpNetstatsProto() { static void MaybeAddSystemTraceToZip() { // This function copies into the .zip the system trace that was snapshotted // by the early call to MaybeSnapshotSystemTrace(), if any background // by the early call to MaybeSnapshotSystemTraceAsync(), if any background // tracing was happening. bool system_trace_exists = access(SYSTEM_TRACE_SNAPSHOT, F_OK) == 0; if (!system_trace_exists) { // No background trace was happening at the time MaybeSnapshotSystemTrace() was invoked. // No background trace was happening at the time MaybeSnapshotSystemTraceAsync() was invoked if (!PropertiesHelper::IsUserBuild()) { MYLOGI( "No system traces found. Check for previously uploaded traces by looking for " Loading Loading @@ -1564,6 +1565,13 @@ static void DumpstateLimitedOnly() { RunDumpsys("DROPBOX SYSTEM SERVER CRASHES", {"dropbox", "-p", "system_server_crash"}); RunDumpsys("DROPBOX SYSTEM APP CRASHES", {"dropbox", "-p", "system_app_crash"}); printf("========================================================\n"); printf("== ANR Traces\n"); printf("========================================================\n"); AddAnrTraceFiles(); printf("========================================================\n"); printf("== Final progress (pid %d): %d/%d (estimated %d)\n", ds.pid_, ds.progress_->Get(), ds.progress_->GetMax(), ds.progress_->GetInitialMax()); Loading Loading @@ -1647,7 +1655,7 @@ Dumpstate::RunStatus Dumpstate::dumpstate() { // Enqueue slow functions into the thread pool, if the parallel run is enabled. std::future<std::string> dump_hals, dump_incident_report, dump_board, dump_checkins, dump_netstats_report, post_process_ui_traces; dump_netstats_report; if (ds.dump_pool_) { // Pool was shutdown in DumpstateDefaultAfterCritical method in order to // drop root user. Restarts it. Loading Loading @@ -3161,8 +3169,9 @@ void Dumpstate::Cancel() { } void Dumpstate::PreDumpUiData() { MaybeSnapshotSystemTrace(); auto snapshot_system_trace = MaybeSnapshotSystemTraceAsync(); MaybeSnapshotUiTraces(); MaybeWaitForSnapshotSystemTrace(std::move(snapshot_system_trace)); } /* Loading Loading @@ -3348,13 +3357,15 @@ Dumpstate::RunStatus Dumpstate::RunInternal(int32_t calling_uid, // duration is logged into MYLOG instead. PrintHeader(); std::future<std::string> snapshot_system_trace; bool is_dumpstate_restricted = options_->telephony_only || options_->wifi_only || options_->limited_only; if (!is_dumpstate_restricted) { // Snapshot the system trace now (if running) to avoid that dumpstate's // own activity pushes out interesting data from the trace ring buffer. // The trace file is added to the zip by MaybeAddSystemTraceToZip(). MaybeSnapshotSystemTrace(); snapshot_system_trace = MaybeSnapshotSystemTraceAsync(); // Invoke critical dumpsys to preserve system state, before doing anything else. RunDumpsysCritical(); Loading @@ -3365,6 +3376,7 @@ Dumpstate::RunStatus Dumpstate::RunInternal(int32_t calling_uid, } MaybeTakeEarlyScreenshot(); MaybeWaitForSnapshotSystemTrace(std::move(snapshot_system_trace)); onUiIntensiveBugreportDumpsFinished(calling_uid); MaybeCheckUserConsent(calling_uid, calling_package); if (options_->telephony_only) { Loading Loading @@ -3461,20 +3473,35 @@ void Dumpstate::MaybeTakeEarlyScreenshot() { TakeScreenshot(); } void Dumpstate::MaybeSnapshotSystemTrace() { std::future<std::string> Dumpstate::MaybeSnapshotSystemTraceAsync() { // When capturing traces via bugreport handler (BH), this function will be invoked twice: // 1) When BH invokes IDumpstate::PreDumpUiData() // 2) When BH invokes IDumpstate::startBugreport(flags = BUGREPORT_USE_PREDUMPED_UI_DATA) // In this case we don't want to re-invoke perfetto in step 2. // In all other standard invocation states, this function is invoked once // without the flag BUGREPORT_USE_PREDUMPED_UI_DATA. // This function must run asynchronously to avoid delaying MaybeTakeEarlyScreenshot() in the // standard invocation states (b/316110955). if (options_->use_predumped_ui_data) { return; return {}; } // Create temporary file for the command's output std::string outPath = ds.bugreport_internal_dir_ + "/tmp_serialize_perfetto_trace"; auto outFd = android::base::unique_fd(TEMP_FAILURE_RETRY( open(outPath.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))); if (outFd < 0) { MYLOGE("Could not open %s to serialize perfetto trace.\n", outPath.c_str()); return {}; } // If a stale file exists already, remove it. unlink(SYSTEM_TRACE_SNAPSHOT); MYLOGI("Launching async '%s'", SERIALIZE_PERFETTO_TRACE_TASK.c_str()) return std::async( std::launch::async, [this, outPath = std::move(outPath), outFd = std::move(outFd)] { // If a background system trace is happening and is marked as "suitable for // bugreport" (i.e. bugreport_score > 0 in the trace config), this command // will stop it and serialize into SYSTEM_TRACE_SNAPSHOT. In the (likely) Loading @@ -3482,10 +3509,23 @@ void Dumpstate::MaybeSnapshotSystemTrace() { // Note: this should not be enqueued as we need to freeze the trace before // dumpstate starts. Otherwise the trace ring buffers will contain mostly // the dumpstate's own activity which is irrelevant. RunCommand("SERIALIZE PERFETTO TRACE", {"perfetto", "--save-for-bugreport"}, CommandOptions::WithTimeout(10).DropRoot().CloseAllFileDescriptorsOnExec().Build()); RunCommand( SERIALIZE_PERFETTO_TRACE_TASK, {"perfetto", "--save-for-bugreport"}, CommandOptions::WithTimeout(10).DropRoot().CloseAllFileDescriptorsOnExec().Build(), false, outFd); // MaybeAddSystemTraceToZip() will take care of copying the trace in the zip // file in the later stages. return outPath; }); } void Dumpstate::MaybeWaitForSnapshotSystemTrace(std::future<std::string> task) { if (!task.valid()) { return; } WaitForTask(std::move(task), SERIALIZE_PERFETTO_TRACE_TASK, STDOUT_FILENO); } void Dumpstate::MaybeSnapshotUiTraces() { Loading @@ -3493,16 +3533,24 @@ void Dumpstate::MaybeSnapshotUiTraces() { return; } const std::vector<std::vector<std::string>> dumpTracesForBugReportCommands = { {"dumpsys", "activity", "service", "SystemUIService", "WMShell", "protolog", "save-for-bugreport"}, {"dumpsys", "activity", "service", "SystemUIService", "WMShell", "transitions", "tracing", "save-for-bugreport"}, std::vector<std::vector<std::string>> dumpTracesForBugReportCommands = { {"cmd", "input_method", "tracing", "save-for-bugreport"}, {"cmd", "window", "tracing", "save-for-bugreport"}, {"cmd", "window", "shell", "tracing", "save-for-bugreport"}, }; if (!android_tracing_perfetto_transition_tracing()) { dumpTracesForBugReportCommands.push_back({"dumpsys", "activity", "service", "SystemUIService", "WMShell", "transitions", "tracing", "save-for-bugreport"}); } if (!android_tracing_perfetto_protolog_tracing()) { dumpTracesForBugReportCommands.push_back({"dumpsys", "activity", "service", "SystemUIService", "WMShell", "protolog", "save-for-bugreport"}); } for (const auto& command : dumpTracesForBugReportCommands) { RunCommand( // Empty name because it's not intended to be classified as a bugreport section. Loading
cmds/dumpstate/dumpstate.h +2 −1 Original line number Diff line number Diff line Loading @@ -570,7 +570,8 @@ class Dumpstate { RunStatus dumpstate(); void MaybeTakeEarlyScreenshot(); void MaybeSnapshotSystemTrace(); std::future<std::string> MaybeSnapshotSystemTraceAsync(); void MaybeWaitForSnapshotSystemTrace(std::future<std::string> task); void MaybeSnapshotUiTraces(); void MaybeAddUiTracesToZip(); Loading
cmds/dumpstate/tests/dumpstate_test.cpp +24 −20 Original line number Diff line number Diff line Loading @@ -16,23 +16,7 @@ #define LOG_TAG "dumpstate_test" #include "DumpstateInternal.h" #include "DumpstateService.h" #include "android/os/BnDumpstate.h" #include "dumpstate.h" #include "DumpPool.h" #include <gmock/gmock.h> #include <gmock/gmock-matchers.h> #include <gtest/gtest.h> #include <fcntl.h> #include <libgen.h> #include <signal.h> #include <sys/types.h> #include <unistd.h> #include <filesystem> #include <thread> #include <aidl/android/hardware/dumpstate/IDumpstateDevice.h> #include <android-base/file.h> Loading @@ -41,10 +25,27 @@ #include <android-base/strings.h> #include <android-base/unique_fd.h> #include <android/hardware/dumpstate/1.1/types.h> #include <android_tracing.h> #include <cutils/log.h> #include <cutils/properties.h> #include <fcntl.h> #include <gmock/gmock-matchers.h> #include <gmock/gmock.h> #include <gtest/gtest.h> #include <libgen.h> #include <signal.h> #include <sys/types.h> #include <unistd.h> #include <ziparchive/zip_archive.h> #include <filesystem> #include <thread> #include "DumpPool.h" #include "DumpstateInternal.h" #include "DumpstateService.h" #include "android/os/BnDumpstate.h" namespace android { namespace os { namespace dumpstate { Loading Loading @@ -999,10 +1000,13 @@ TEST_F(DumpstateTest, DumpPool_withParallelRunDisabled_isNull) { TEST_F(DumpstateTest, PreDumpUiData) { // These traces are always enabled, i.e. they are always pre-dumped const std::vector<std::filesystem::path> uiTraces = { std::filesystem::path{"/data/misc/wmtrace/wm_transition_trace.winscope"}, std::filesystem::path{"/data/misc/wmtrace/shell_transition_trace.winscope"}, }; std::vector<std::filesystem::path> uiTraces; if (!android_tracing_perfetto_transition_tracing()) { uiTraces.push_back( std::filesystem::path{"/data/misc/wmtrace/wm_transition_trace.winscope"}); uiTraces.push_back( std::filesystem::path{"/data/misc/wmtrace/shell_transition_trace.winscope"}); } for (const auto traceFile : uiTraces) { std::system(("rm -f " + traceFile.string()).c_str()); Loading