Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8268ed2d authored by Felipe Leme's avatar Felipe Leme
Browse files

Uses a system property to set dry-run mode.

On Android N, dumpstate was using a #define to set dry-run mode, which
allows dumpstate to run much faster, which in turn is useful when
developing new dumpstate features.

The drawback of this approach is that it requires modifying dumpstate.h
locally, building a new binary, and re-redeploying it in the device; a
better and more flexible approach is to use a system
property (dumpstate.dry_run) so developers can enable /disable it during
runtime.

Change-Id: I41d1e6ae3fa6ca2be23887f59d5ad4e9df7c10e6
Fixes: 30604041
parent 62164224
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ int control_socket_fd = -1;
/* suffix of the bugreport files - it's typically the date (when invoked with -d),
 * although it could be changed by the user using a system property */
static std::string suffix;
static bool dry_run = false;

#define PSTORE_LAST_KMSG "/sys/fs/pstore/console-ramoops"
#define ALT_PSTORE_LAST_KMSG "/sys/fs/pstore/console-ramoops-0"
@@ -95,7 +96,7 @@ std::string bugreport_dir;
/*
 * List of supported zip format versions.
 *
 * See bugreport-format.txt for more info.
 * See bugreport-format.md for more info.
 */
static std::string VERSION_DEFAULT = "1.0";

@@ -103,6 +104,10 @@ bool is_user_build() {
    return 0 == strncmp(build_type, "user", PROPERTY_VALUE_MAX - 1);
}

bool is_dry_run() {
    return dry_run;
}

/* gets the tombstone data, according to the bugreport type: if zipped, gets all tombstones;
 * otherwise, gets just those modified in the last half an hour. */
static void get_tombstone_fds(tombstone_data_t data[NUM_TOMBSTONES]) {
@@ -1161,6 +1166,11 @@ int main(int argc, char *argv[]) {

    MYLOGI("begin\n");

    dry_run = property_get_bool("dumpstate.dry_run", 0) != 0;
    if (is_dry_run()) {
        MYLOGI("Running on dry-run mode (to disable it, call 'setprop dumpstate.dry_run false')\n");
    }

    /* gets the sequential id */
    char last_id[PROPERTY_VALUE_MAX];
    property_get("dumpstate.last_id", last_id, "0");
+19 −14
Original line number Diff line number Diff line
@@ -14,19 +14,15 @@
 * limitations under the License.
 */

#ifndef _DUMPSTATE_H_
#define _DUMPSTATE_H_

/* When defined, skips the real dumps and just print the section headers.
   Useful when debugging dumpstate itself. */
//#define _DUMPSTATE_DRY_RUN_

#ifdef _DUMPSTATE_DRY_RUN_
#define ON_DRY_RUN_RETURN(X) return X
#define ON_DRY_RUN(code) code
#else
#define ON_DRY_RUN_RETURN(X)
#define ON_DRY_RUN(code)
#ifndef FRAMEWORK_NATIVE_CMD_DUMPSTATE_H_
#define FRAMEWORK_NATIVE_CMD_DUMPSTATE_H_

#ifndef ON_DRY_RUN_RETURN
#define ON_DRY_RUN_RETURN(X) if (is_dry_run()) return X
#endif

#ifndef ON_DRY_RUN
#define ON_DRY_RUN(code) if (is_dry_run()) code
#endif

#ifndef MYLOGD
@@ -211,6 +207,15 @@ void format_args(int argc, const char *argv[], std::string *args);
/** Tells if the device is running a user build. */
bool is_user_build();

/*
 * When running in dry-run mode, skips the real dumps and just print the section headers.
 *
 * Useful when debugging dumpstate or other bugreport-related activities.
 *
 * Dry-run mode is enabled by setting the system property dumpstate.dry_run to true.
 */
bool is_dry_run();

/*
 * Helper class used to report how long it takes for a section to finish.
 *
@@ -238,4 +243,4 @@ private:
}
#endif

#endif /* _DUMPSTATE_H_ */
#endif /* FRAMEWORK_NATIVE_CMD_DUMPSTATE_H_ */