diff options
Diffstat (limited to 'cmds/dumpstate/dumpstate.h')
-rw-r--r-- | cmds/dumpstate/dumpstate.h | 95 |
1 files changed, 62 insertions, 33 deletions
diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h index 0d25d307a6..83e6787ebf 100644 --- a/cmds/dumpstate/dumpstate.h +++ b/cmds/dumpstate/dumpstate.h @@ -35,6 +35,8 @@ #include <ziparchive/zip_writer.h> #include "DumpstateUtil.h" +#include "DumpPool.h" +#include "TaskQueue.h" // Workaround for const char *args[MAX_ARGS_ARRAY_SIZE] variables until they're converted to // std::vector<std::string> @@ -52,6 +54,7 @@ namespace dumpstate { class DumpstateTest; class ProgressTest; +class ZippedBugReportStreamTest; } // namespace dumpstate } // namespace os @@ -75,7 +78,7 @@ extern "C" { class DurationReporter { public: explicit DurationReporter(const std::string& title, bool logcat_only = false, - bool verbose = false); + bool verbose = false, int duration_fd = STDOUT_FILENO); ~DurationReporter(); @@ -84,6 +87,7 @@ class DurationReporter { bool logcat_only_; bool verbose_; uint64_t started_; + int duration_fd_; DISALLOW_COPY_AND_ASSIGN(DurationReporter); }; @@ -193,7 +197,8 @@ struct DumpData { * that are spread accross utils.cpp and dumpstate.cpp will be moved to it. */ class Dumpstate { - friend class DumpstateTest; + friend class android::os::dumpstate::DumpstateTest; + friend class android::os::dumpstate::ZippedBugReportStreamTest; public: enum RunStatus { OK, HELP, INVALID_INPUT, ERROR, USER_CONSENT_DENIED, USER_CONSENT_TIMED_OUT }; @@ -227,11 +232,13 @@ class Dumpstate { * |full_command| array containing the command (first entry) and its arguments. * Must contain at least one element. * |options| optional argument defining the command's behavior. + * |out_fd| A fd to support the DumpPool to output results to a temporary + * file. Using STDOUT_FILENO if it's not running in the parallel task. */ int RunCommand(const std::string& title, const std::vector<std::string>& fullCommand, const android::os::dumpstate::CommandOptions& options = android::os::dumpstate::CommandOptions::DEFAULT, - bool verbose_duration = false); + bool verbose_duration = false, int out_fd = STDOUT_FILENO); /* * Runs `dumpsys` with the given arguments, automatically setting its timeout @@ -244,10 +251,12 @@ class Dumpstate { * |options| optional argument defining the command's behavior. * |dumpsys_timeout| when > 0, defines the value passed to `dumpsys -T` (otherwise it uses the * timeout from `options`) + * |out_fd| A fd to support the DumpPool to output results to a temporary + * file. Using STDOUT_FILENO if it's not running in the parallel task. */ void RunDumpsys(const std::string& title, const std::vector<std::string>& dumpsys_args, const android::os::dumpstate::CommandOptions& options = DEFAULT_DUMPSYS, - long dumpsys_timeout_ms = 0); + long dumpsys_timeout_ms = 0, int out_fd = STDOUT_FILENO); /* * Prints the contents of a file. @@ -304,7 +313,12 @@ class Dumpstate { // Returns OK in all other cases. RunStatus DumpTraces(const char** path); - void DumpstateBoard(); + /* + * |out_fd| A fd to support the DumpPool to output results to a temporary file. + * Dumpstate can pick up later and output to the bugreport. Using STDOUT_FILENO + * if it's not running in the parallel task. + */ + void DumpstateBoard(int out_fd = STDOUT_FILENO); /* * Updates the overall progress of the bugreport generation by the given weight increment. @@ -361,20 +375,30 @@ class Dumpstate { bool CalledByApi() const; /* + * Enqueues a task to the dumpstate's TaskQueue if the parallel run is enabled, + * otherwise invokes it immediately. The task adds file at path entry_path + * as a zip file entry with name entry_name. Unlinks entry_path when done. + * + * All enqueued tasks will be executed in the dumpstate's FinishZipFile method + * before the zip file is finished. Tasks will be cancelled in dumpstate's + * ShutdownDumpPool method if they have never been called. + */ + void EnqueueAddZipEntryAndCleanupIfNeeded(const std::string& entry_name, + const std::string& entry_path); + + /* * Structure to hold options that determine the behavior of dumpstate. */ struct DumpOptions { - bool do_add_date = false; - bool do_zip_file = false; bool do_vibrate = true; - // Writes bugreport content to a socket; only flatfile format is supported. - bool use_socket = false; - bool use_control_socket = false; + // Writes bugreport zipped file to a socket. + bool stream_to_socket = false; + // Writes generation progress updates to a socket. + bool progress_updates_to_socket = false; bool do_screenshot = false; bool is_screenshot_copied = false; bool is_remote_mode = false; bool show_header_only = false; - bool do_start_service = false; bool telephony_only = false; bool wifi_only = false; // Trimmed-down version of dumpstate to only include whitelisted logs. @@ -411,13 +435,6 @@ class Dumpstate { /* Returns true if the options set so far are consistent. */ bool ValidateOptions() const; - /* Returns if options specified require writing bugreport to a file */ - bool OutputToFile() const { - // If we are not writing to socket, we will write to a file. If bugreport_fd is - // specified, it is preferred. If not bugreport is written to /bugreports. - return !use_socket; - } - /* Returns if options specified require writing to custom file location */ bool OutputToCustomFile() { // Custom location is only honored in limited mode. @@ -441,9 +458,15 @@ class Dumpstate { // Whether it should take an screenshot earlier in the process. bool do_early_screenshot_ = false; + // This is set to true when the trace snapshot request in the early call to + // MaybeSnapshotSystemTrace(). When this is true, the later stages of + // dumpstate will append the trace to the zip archive. + bool has_system_trace_ = false; + std::unique_ptr<Progress> progress_; - // When set, defines a socket file-descriptor use to report progress to bugreportz. + // When set, defines a socket file-descriptor use to report progress to bugreportz + // or to stream the zipped file to. int control_socket_fd_ = -1; // Bugreport format version; @@ -455,8 +478,8 @@ class Dumpstate { // `bugreport-BUILD_ID`. std::string base_name_; - // Name is the suffix part of the bugreport files - it's typically the date (when invoked with - // `-d`), but it could be changed by the user.. + // Name is the suffix part of the bugreport files - it's typically the date, + // but it could be changed by the user.. std::string name_; std::string bugreport_internal_dir_ = DUMPSTATE_DIRECTORY; @@ -490,6 +513,13 @@ class Dumpstate { // List of open ANR dump files. std::vector<DumpData> anr_data_; + // A thread pool to execute dump tasks simultaneously if the parallel run is enabled. + std::unique_ptr<android::os::dumpstate::DumpPool> dump_pool_; + + // A task queue to collect adding zip entry tasks inside dump tasks if the + // parallel run is enabled. + std::unique_ptr<android::os::dumpstate::TaskQueue> zip_entry_tasks_; + // A callback to IncidentCompanion service, which checks user consent for sharing the // bugreport with the calling app. If the user has not responded yet to the dialog it will // be neither confirmed nor denied. @@ -518,9 +548,10 @@ class Dumpstate { RunStatus DumpstateDefaultAfterCritical(); void MaybeTakeEarlyScreenshot(); + void MaybeSnapshotSystemTrace(); + void MaybeSnapshotWinTrace(); - void onUiIntensiveBugreportDumpsFinished(int32_t calling_uid, - const std::string& calling_package); + void onUiIntensiveBugreportDumpsFinished(int32_t calling_uid); void MaybeCheckUserConsent(int32_t calling_uid, const std::string& calling_package); @@ -528,17 +559,25 @@ class Dumpstate { // but leaves the log file alone. void CleanupTmpFiles(); + // Create the thread pool to enable the parallel run function. + void EnableParallelRunIfNeeded(); + void ShutdownDumpPool(); + RunStatus HandleUserConsentDenied(); // Copies bugreport artifacts over to the caller's directories provided there is user consent or // called by Shell. RunStatus CopyBugreportIfUserConsented(int32_t calling_uid); + std::function<int(const char *)> open_socket_fn_; + // Used by GetInstance() only. explicit Dumpstate(const std::string& version = VERSION_CURRENT); android::sp<ConsentCallback> consent_callback_; + std::recursive_mutex mutex_; + DISALLOW_COPY_AND_ASSIGN(Dumpstate); }; @@ -565,16 +604,6 @@ int dump_file_from_fd(const char *title, const char *path, int fd); int dump_files(const std::string& title, const char* dir, bool (*skip)(const char* path), int (*dump_from_fd)(const char* title, const char* path, int fd)); -/** opens a socket and returns its file descriptor */ -int open_socket(const char *service); - -/* - * Redirects 'redirect' to a service control socket. - * - * Returns true if redirect succeeds. - */ -bool redirect_to_socket(FILE* redirect, const char* service); - /* * Redirects 'redirect' to a file indicated by 'path', truncating it. * |