Loading bootstat/Android.bp +4 −1 Original line number Diff line number Diff line Loading @@ -63,7 +63,10 @@ cc_binary { name: "bootstat", defaults: ["bootstat_defaults"], static_libs: ["libbootstat"], shared_libs: ["liblogcat"], shared_libs: [ "liblogcat", "libstatslog" ], init_rc: ["bootstat.rc"], product_variables: { debuggable: { Loading bootstat/bootstat.cpp +55 −9 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ #include <cutils/properties.h> #include <log/logcat.h> #include <metricslogger/metrics_logger.h> #include <statslog.h> #include "boot_event_record_store.h" Loading Loading @@ -881,6 +882,16 @@ const BootloaderTimingMap GetBootLoaderTimings() { return timings; } // Returns the total bootloader boot time from the ro.boot.boottime system property. int32_t GetBootloaderTime(const BootloaderTimingMap& bootloader_timings) { int32_t total_time = 0; for (const auto& timing : bootloader_timings) { total_time += timing.second; } return total_time; } // Parses and records the set of bootloader stages and associated boot times // from the ro.boot.boottime system property. void RecordBootloaderTimings(BootEventRecordStore* boot_event_store, Loading @@ -894,10 +905,9 @@ void RecordBootloaderTimings(BootEventRecordStore* boot_event_store, boot_event_store->AddBootEventWithValue("boottime.bootloader.total", total_time); } // Records the closest estimation to the absolute device boot time, i.e., // Returns the closest estimation to the absolute device boot time, i.e., // from power on to boot_complete, including bootloader times. void RecordAbsoluteBootTime(BootEventRecordStore* boot_event_store, const BootloaderTimingMap& bootloader_timings, std::chrono::milliseconds GetAbsoluteBootTime(const BootloaderTimingMap& bootloader_timings, std::chrono::milliseconds uptime) { int32_t bootloader_time_ms = 0; Loading @@ -908,9 +918,36 @@ void RecordAbsoluteBootTime(BootEventRecordStore* boot_event_store, } auto bootloader_duration = std::chrono::milliseconds(bootloader_time_ms); auto absolute_total = std::chrono::duration_cast<std::chrono::seconds>(bootloader_duration + uptime); boot_event_store->AddBootEventWithValue("absolute_boot_time", absolute_total.count()); return bootloader_duration + uptime; } // Records the closest estimation to the absolute device boot time in seconds. // i.e. from power on to boot_complete, including bootloader times. void RecordAbsoluteBootTime(BootEventRecordStore* boot_event_store, std::chrono::milliseconds absolute_total) { auto absolute_total_sec = std::chrono::duration_cast<std::chrono::seconds>(absolute_total); boot_event_store->AddBootEventWithValue("absolute_boot_time", absolute_total_sec.count()); } // Logs the total boot time and reason to statsd. void LogBootInfoToStatsd(std::chrono::milliseconds end_time, std::chrono::milliseconds total_duration, int32_t bootloader_duration_ms, double time_since_last_boot_sec) { const std::string reason(GetProperty(bootloader_reboot_reason_property)); if (reason.empty()) { android::util::stats_write(android::util::BOOT_SEQUENCE_REPORTED, "<EMPTY>", "<EMPTY>", end_time.count(), total_duration.count(), (int64_t)bootloader_duration_ms, (int64_t)time_since_last_boot_sec * 1000); return; } const std::string system_reason(BootReasonStrToReason(reason)); android::util::stats_write(android::util::BOOT_SEQUENCE_REPORTED, reason.c_str(), system_reason.c_str(), end_time.count(), total_duration.count(), (int64_t)bootloader_duration_ms, (int64_t)time_since_last_boot_sec * 1000); } // Records several metrics related to the time it takes to boot the device, Loading @@ -922,10 +959,11 @@ void RecordBootComplete() { auto time_since_epoch = android::base::boot_clock::now().time_since_epoch(); auto uptime = std::chrono::duration_cast<std::chrono::seconds>(time_since_epoch); time_t current_time_utc = time(nullptr); time_t time_since_last_boot = 0; if (boot_event_store.GetBootEvent("last_boot_time_utc", &record)) { time_t last_boot_time_utc = record.second; time_t time_since_last_boot = difftime(current_time_utc, last_boot_time_utc); time_since_last_boot = difftime(current_time_utc, last_boot_time_utc); boot_event_store.AddBootEventWithValue("time_since_last_boot", time_since_last_boot); } Loading Loading @@ -964,10 +1002,18 @@ void RecordBootComplete() { RecordInitBootTimeProp(&boot_event_store, "ro.boottime.init.cold_boot_wait"); const BootloaderTimingMap bootloader_timings = GetBootLoaderTimings(); int32_t bootloader_boot_duration = GetBootloaderTime(bootloader_timings); RecordBootloaderTimings(&boot_event_store, bootloader_timings); auto uptime_ms = std::chrono::duration_cast<std::chrono::milliseconds>(time_since_epoch); RecordAbsoluteBootTime(&boot_event_store, bootloader_timings, uptime_ms); auto absolute_boot_time = GetAbsoluteBootTime(bootloader_timings, uptime_ms); RecordAbsoluteBootTime(&boot_event_store, absolute_boot_time); auto boot_end_time_point = std::chrono::system_clock::now().time_since_epoch(); auto boot_end_time = std::chrono::duration_cast<std::chrono::milliseconds>(boot_end_time_point); LogBootInfoToStatsd(boot_end_time, absolute_boot_time, bootloader_boot_duration, time_since_last_boot); } // Records the boot_reason metric by querying the ro.boot.bootreason system Loading libbacktrace/Android.bp +2 −53 Original line number Diff line number Diff line Loading @@ -128,39 +128,8 @@ cc_library_shared { cflags: ["-O0"], srcs: ["backtrace_testlib.cpp"], target: { linux: { shared_libs: [ "libunwind", "libunwindstack", ], }, } } //------------------------------------------------------------------------- // The libbacktrace_offline static library. //------------------------------------------------------------------------- cc_library_static { name: "libbacktrace_offline", defaults: ["libbacktrace_common"], host_supported: true, srcs: ["BacktraceOffline.cpp"], cflags: [ "-D__STDC_CONSTANT_MACROS", "-D__STDC_LIMIT_MACROS", "-D__STDC_FORMAT_MACROS", ], header_libs: ["llvm-headers"], // Use shared libraries so their headers get included during build. shared_libs = [ "libbase", "libunwind", "libunwindstack", "libziparchive", ], } Loading Loading @@ -193,28 +162,11 @@ cc_test { "libbase", "libcutils", "liblog", "libunwind", "libunwindstack", ], group_static_libs: true, // Statically link LLVMlibraries to remove dependency on llvm shared library. static_libs = [ "libbacktrace_offline", "libLLVMObject", "libLLVMBitReader", "libLLVMMC", "libLLVMMCParser", "libLLVMCore", "libLLVMSupport", "libziparchive", "libz", ], header_libs: ["llvm-headers"], target: { android: { cflags: ["-DENABLE_PSS_TESTS"], Loading @@ -223,9 +175,6 @@ cc_test { ], }, linux_glibc: { host_ldlibs: [ "-lncurses", ], static_libs: ["libutils"], }, }, Loading libbacktrace/Backtrace.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -168,5 +168,9 @@ std::string Backtrace::GetErrorString(BacktraceUnwindError error) { return "Failed to find a function in debug sections"; case BACKTRACE_UNWIND_ERROR_EXECUTE_DWARF_INSTRUCTION_FAILED: return "Failed to execute dwarf instructions in debug sections"; case BACKTRACE_UNWIND_ERROR_UNWIND_INFO: return "Failed to unwind due to invalid unwind information"; case BACKTRACE_UNWIND_ERROR_REPEATED_FRAME: return "Failed to unwind due to same sp/pc repeating"; } } libbacktrace/BacktraceCurrent.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -64,7 +64,7 @@ size_t BacktraceCurrent::Read(uint64_t addr, uint8_t* buffer, size_t bytes) { return bytes; } bool BacktraceCurrent::Unwind(size_t num_ignore_frames, ucontext_t* ucontext) { bool BacktraceCurrent::Unwind(size_t num_ignore_frames, void* ucontext) { if (GetMap() == nullptr) { // Without a map object, we can't do anything. error_.error_code = BACKTRACE_UNWIND_ERROR_MAP_MISSING; Loading Loading
bootstat/Android.bp +4 −1 Original line number Diff line number Diff line Loading @@ -63,7 +63,10 @@ cc_binary { name: "bootstat", defaults: ["bootstat_defaults"], static_libs: ["libbootstat"], shared_libs: ["liblogcat"], shared_libs: [ "liblogcat", "libstatslog" ], init_rc: ["bootstat.rc"], product_variables: { debuggable: { Loading
bootstat/bootstat.cpp +55 −9 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ #include <cutils/properties.h> #include <log/logcat.h> #include <metricslogger/metrics_logger.h> #include <statslog.h> #include "boot_event_record_store.h" Loading Loading @@ -881,6 +882,16 @@ const BootloaderTimingMap GetBootLoaderTimings() { return timings; } // Returns the total bootloader boot time from the ro.boot.boottime system property. int32_t GetBootloaderTime(const BootloaderTimingMap& bootloader_timings) { int32_t total_time = 0; for (const auto& timing : bootloader_timings) { total_time += timing.second; } return total_time; } // Parses and records the set of bootloader stages and associated boot times // from the ro.boot.boottime system property. void RecordBootloaderTimings(BootEventRecordStore* boot_event_store, Loading @@ -894,10 +905,9 @@ void RecordBootloaderTimings(BootEventRecordStore* boot_event_store, boot_event_store->AddBootEventWithValue("boottime.bootloader.total", total_time); } // Records the closest estimation to the absolute device boot time, i.e., // Returns the closest estimation to the absolute device boot time, i.e., // from power on to boot_complete, including bootloader times. void RecordAbsoluteBootTime(BootEventRecordStore* boot_event_store, const BootloaderTimingMap& bootloader_timings, std::chrono::milliseconds GetAbsoluteBootTime(const BootloaderTimingMap& bootloader_timings, std::chrono::milliseconds uptime) { int32_t bootloader_time_ms = 0; Loading @@ -908,9 +918,36 @@ void RecordAbsoluteBootTime(BootEventRecordStore* boot_event_store, } auto bootloader_duration = std::chrono::milliseconds(bootloader_time_ms); auto absolute_total = std::chrono::duration_cast<std::chrono::seconds>(bootloader_duration + uptime); boot_event_store->AddBootEventWithValue("absolute_boot_time", absolute_total.count()); return bootloader_duration + uptime; } // Records the closest estimation to the absolute device boot time in seconds. // i.e. from power on to boot_complete, including bootloader times. void RecordAbsoluteBootTime(BootEventRecordStore* boot_event_store, std::chrono::milliseconds absolute_total) { auto absolute_total_sec = std::chrono::duration_cast<std::chrono::seconds>(absolute_total); boot_event_store->AddBootEventWithValue("absolute_boot_time", absolute_total_sec.count()); } // Logs the total boot time and reason to statsd. void LogBootInfoToStatsd(std::chrono::milliseconds end_time, std::chrono::milliseconds total_duration, int32_t bootloader_duration_ms, double time_since_last_boot_sec) { const std::string reason(GetProperty(bootloader_reboot_reason_property)); if (reason.empty()) { android::util::stats_write(android::util::BOOT_SEQUENCE_REPORTED, "<EMPTY>", "<EMPTY>", end_time.count(), total_duration.count(), (int64_t)bootloader_duration_ms, (int64_t)time_since_last_boot_sec * 1000); return; } const std::string system_reason(BootReasonStrToReason(reason)); android::util::stats_write(android::util::BOOT_SEQUENCE_REPORTED, reason.c_str(), system_reason.c_str(), end_time.count(), total_duration.count(), (int64_t)bootloader_duration_ms, (int64_t)time_since_last_boot_sec * 1000); } // Records several metrics related to the time it takes to boot the device, Loading @@ -922,10 +959,11 @@ void RecordBootComplete() { auto time_since_epoch = android::base::boot_clock::now().time_since_epoch(); auto uptime = std::chrono::duration_cast<std::chrono::seconds>(time_since_epoch); time_t current_time_utc = time(nullptr); time_t time_since_last_boot = 0; if (boot_event_store.GetBootEvent("last_boot_time_utc", &record)) { time_t last_boot_time_utc = record.second; time_t time_since_last_boot = difftime(current_time_utc, last_boot_time_utc); time_since_last_boot = difftime(current_time_utc, last_boot_time_utc); boot_event_store.AddBootEventWithValue("time_since_last_boot", time_since_last_boot); } Loading Loading @@ -964,10 +1002,18 @@ void RecordBootComplete() { RecordInitBootTimeProp(&boot_event_store, "ro.boottime.init.cold_boot_wait"); const BootloaderTimingMap bootloader_timings = GetBootLoaderTimings(); int32_t bootloader_boot_duration = GetBootloaderTime(bootloader_timings); RecordBootloaderTimings(&boot_event_store, bootloader_timings); auto uptime_ms = std::chrono::duration_cast<std::chrono::milliseconds>(time_since_epoch); RecordAbsoluteBootTime(&boot_event_store, bootloader_timings, uptime_ms); auto absolute_boot_time = GetAbsoluteBootTime(bootloader_timings, uptime_ms); RecordAbsoluteBootTime(&boot_event_store, absolute_boot_time); auto boot_end_time_point = std::chrono::system_clock::now().time_since_epoch(); auto boot_end_time = std::chrono::duration_cast<std::chrono::milliseconds>(boot_end_time_point); LogBootInfoToStatsd(boot_end_time, absolute_boot_time, bootloader_boot_duration, time_since_last_boot); } // Records the boot_reason metric by querying the ro.boot.bootreason system Loading
libbacktrace/Android.bp +2 −53 Original line number Diff line number Diff line Loading @@ -128,39 +128,8 @@ cc_library_shared { cflags: ["-O0"], srcs: ["backtrace_testlib.cpp"], target: { linux: { shared_libs: [ "libunwind", "libunwindstack", ], }, } } //------------------------------------------------------------------------- // The libbacktrace_offline static library. //------------------------------------------------------------------------- cc_library_static { name: "libbacktrace_offline", defaults: ["libbacktrace_common"], host_supported: true, srcs: ["BacktraceOffline.cpp"], cflags: [ "-D__STDC_CONSTANT_MACROS", "-D__STDC_LIMIT_MACROS", "-D__STDC_FORMAT_MACROS", ], header_libs: ["llvm-headers"], // Use shared libraries so their headers get included during build. shared_libs = [ "libbase", "libunwind", "libunwindstack", "libziparchive", ], } Loading Loading @@ -193,28 +162,11 @@ cc_test { "libbase", "libcutils", "liblog", "libunwind", "libunwindstack", ], group_static_libs: true, // Statically link LLVMlibraries to remove dependency on llvm shared library. static_libs = [ "libbacktrace_offline", "libLLVMObject", "libLLVMBitReader", "libLLVMMC", "libLLVMMCParser", "libLLVMCore", "libLLVMSupport", "libziparchive", "libz", ], header_libs: ["llvm-headers"], target: { android: { cflags: ["-DENABLE_PSS_TESTS"], Loading @@ -223,9 +175,6 @@ cc_test { ], }, linux_glibc: { host_ldlibs: [ "-lncurses", ], static_libs: ["libutils"], }, }, Loading
libbacktrace/Backtrace.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -168,5 +168,9 @@ std::string Backtrace::GetErrorString(BacktraceUnwindError error) { return "Failed to find a function in debug sections"; case BACKTRACE_UNWIND_ERROR_EXECUTE_DWARF_INSTRUCTION_FAILED: return "Failed to execute dwarf instructions in debug sections"; case BACKTRACE_UNWIND_ERROR_UNWIND_INFO: return "Failed to unwind due to invalid unwind information"; case BACKTRACE_UNWIND_ERROR_REPEATED_FRAME: return "Failed to unwind due to same sp/pc repeating"; } }
libbacktrace/BacktraceCurrent.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -64,7 +64,7 @@ size_t BacktraceCurrent::Read(uint64_t addr, uint8_t* buffer, size_t bytes) { return bytes; } bool BacktraceCurrent::Unwind(size_t num_ignore_frames, ucontext_t* ucontext) { bool BacktraceCurrent::Unwind(size_t num_ignore_frames, void* ucontext) { if (GetMap() == nullptr) { // Without a map object, we can't do anything. error_.error_code = BACKTRACE_UNWIND_ERROR_MAP_MISSING; Loading