History log of /frameworks/native/cmds/dumpstate/utils.cpp
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
f0922cc1786c0c2fbf44c10b0005243ecbb4227d 15-May-2016 Nick Kralevich <nnk@google.com> dumpstate: convert sprintfs to snprintfs

Bug: 28731007
Change-Id: Icfa4d6dfaf69e989ec785146a6bde1afb6a6f345
5c04e7465eda8a558244e772da1e7d2a0d5f94e2 14-Apr-2016 Andy Hung <hunga@google.com> Unify dumped native stack traces

Bug: 28179196

Change-Id: Ie728ceace7aaf38389dd9684342e351feed6e5a7
2628e9e939fda323fa44c5cb743f4a77b12a312a 13-Apr-2016 Felipe Leme <felipeal@google.com> Added support for 'bugreport -z'.

Dumpstate now supports zipped bugreport, whose output is more complete
than the flat-file bugreports provided prior to N.

The whole workflow is split in different components:

- adb supports a 'bugreport -z <ZIP_FILE>' option, which calls a
bugreportz binary.
- bugreportz starts the dumpstatez service.
- dumpstatez starts dumpstate with some flags that opens a socket for
control (not output).
- Once dumpstate is finished, it prints the bugreport location to
- adb pulls the zip file and renames according to the command-line
- bugreport prints a deprecation message.

The reason for a new binary (bugreportz) instead of passing arguments to
bugreport (like -z) is backward compatibility: pre-N versions of
bugreport would ignore such argument and generate a text bugreport,
which is not what adb would be expecting.

BUG: 27653204

Change-Id: I47f6f677eba11d5fb54818ae5a0b3cab069776ee
29c39715b8a45ca2e97aecd8ebb63183f63da72b 01-Apr-2016 Felipe Leme <felipeal@google.com> Added option to redirect stdout on run_command_always.

There are cases where a command should not write to stdout. For example,
when sending the initial broadcast before the header is printed.

This change adds this option to run_command_always, and uses enums to
make it easier to read what's been passed to it.

BUG: 27953643

Change-Id: I9aed0cb0df4112b31d2079241114e206b9d0bb0c
14e034a02ec34b2c76afb06975bdfc943a9b5607 31-Mar-2016 Felipe Leme <felipeal@google.com> Dumps systrace to a file.

The atrace command can take a while, so rather than use a pipe it's
better to write its output to a temporary file and add that file to the
zip, timing out if necessary.

BUG: 27821761
Change-Id: I09f438077d001167d92da3009016bcab815ce530
baa85bd893665a48aee73d7ca7b73cd39b48f998 29-Mar-2016 Felipe Leme <felipeal@google.com> Call _exit() instead of exit() on child failure.

As explained on man _exit:

"The function _exit() terminates the calling process "immediately".
Any open file descriptors belonging to the process are closed;"

If exit() is called instead, the resulting zip file will be corrupted.

BUG: 27900023
BUG: 27804637
Change-Id: I6591749603753d6016f350c629b7082cf6780ae2
ea160d134cd46c246859072f90ab5dd05ada6364 24-Mar-2016 Felipe Leme <felipeal@google.com> Improved (or warned about lack of) error handling.

It would be safer for dumpstate to exit when execvp on a child fails; a
common occurrence is when a list of command arguments is missing NULL.

dumpstate should be more robust to detect those missing NULL-terminated
args, but that will be addressed in a future change.

BUG: 27804637
BUG: 27832567
Change-Id: Ibcbe46041a86b16e365fbb40613b8c4bdf39744c
73f731c30a8b7d811127b8e89e01c427b6aab622 24-Mar-2016 Felipe Leme <felipeal@google.com> Fixed send_broadcast and fork handling issues.

send_broadcast() was calling run_command_always(char*, bool, int, char*) passing:
run_command_always(NULL, 20, true, am_args);

I.e., it was passing "true" (!1) as the boolean, and 1 (true) as the
timeout value; the proper call should be:

run_command_always(NULL, true, 20, am_args);

Also, the code handling failure on child calls was calling _exit(),
which quits dumpstate - it should simply return the function instead.

BUG: 27804637

Change-Id: If8c9b40eddc8b76f92e6d11078dfe446a39ad4d4
ec72578b8461a5601962ea8102fd74a1f86d91fb 23-Mar-2016 Felipe Leme <felipeal@google.com> Flushes stdout when execvp fails.

BUG: 27804637
Change-Id: Idf414a1d08bf51854475c74767588a4814c8d806
b0133cdeaa98afa55249546f68b6167f1dde65b8 23-Mar-2016 Felipe Leme <felipeal@google.com> Handled failure of execvp and increases am timeout.

The run_command_always() call fork and runs the command in the child
code, and user to have the above logic:

if (pid == 0) {
// boiling code
execvp(command, (char**) args);
// execvp's result will be handled after waitpid_with_timeout() below...
_exit(-1); // ...but it doesn't hurt to force exit, just in case

Recently, the _exit(-1) line was removed and there's been reports of
dumpstate hanging after, because it tries to wait for pid 0 to
finish (and in some cases it even tries to kill it).

Also increased the timeout when running am to send broadcasts.

BUG: 27804637
BUG: 27809534
Change-Id: Ia129253e367e5886d305947e56a643fd660a33bd
7363bafd0a94aa98a267edbbcb27abc9ef72f1dd 21-Mar-2016 Felipe Leme <felipeal@google.com> Merge "Don't use su to when calling am or dumpsys." into nyc-dev
71a74ac75c8687195d27642fa0db31a796102c59 17-Mar-2016 Felipe Leme <felipeal@google.com> Capture systrace buffers.

When tracing is enabled (/sys/kernel/debug/tracing/tracing_on = 1),
dumpstate will run 'atrace --async_dump' and redirect its output to a
systrace.txt entry in the zip file.

BUG: 27419521
Change-Id: Ia6de46a691b25febac31331fe0aa8701c9a84ebb
3dba69aad214a873c619d125ff0441b817947100 17-Mar-2016 Felipe Leme <felipeal@google.com> Added -q flag to showmap.

dumpstate calls showmap for each pid, and since most of them are empty,
it ends up polluting logcat with entries like:

03-17 14:49:05.974 12160 12160 E dumpstate: command '/system/xbin/su
root showmap -q 9867' failed: No such file or directory

BUG: 26906985
Change-Id: I7e064b2ec8901b6ccee49b228be96ff2847c703c
cf6a8b47dc04f1c33ddc337b5e21f2c5b7354cb5 11-Mar-2016 Felipe Leme <felipeal@google.com> Don't use su to when calling am or dumpsys.

su is not available on user builds anymore, hence the bugreport
notifications would never be sent on those builds. Instead, it should
explicitly drop root using system calls.

BUG: 27583193
Change-Id: Ia6256b241fdd6ab4c059fb764b10b4445ad6551d
a34efb7ae17a7ea1078cce75be634120bd72a421 11-Mar-2016 Felipe Leme <felipeal@google.com> Improve logging of child commands.

When execvpe() is called it doesn't return, so the child error handling
should be done at the parent, otherwise the failure is not printed in the bugreport.

BUG: 27583193
Change-Id: I6161e4c72b7b0da7b82bff7fd72d7a5aaf4d6e89
107a05f72e711c92545d0be648ab79c4f858f372 09-Mar-2016 Felipe Leme <felipeal@google.com> Improved usage of stderr for logging.

Dumpstate have some macros that write logs to both ALOG and stderr,
which is useful when the latter is redirected to a file.

But prior to this change, only the log statements from dumpstate.cpp
were using it, and utils.cpp was logging to stderr directly.

This change not only uses MYLOGE for all error messages, but also closes
stderr at the very end (so it doesn't miss statements like the
parameters sent to send_broadcast) and uses MYLOGD for the overall progress.

BUG: 27437378
Change-Id: I373a523e20c98d8f445822103784fa9900c6c684
88c7933df551f6dadd8cc931d104b01d6d1609e4 22-Feb-2016 Felipe Leme <felipeal@google.com> Improved dumpstate logging.

BUG: 26906985
Change-Id: Id439560504a365961337fddcca4ba6c1ef9f377d
60292e5c8324475c5afbd0a6703b6b3ae2c94b1a 16-Feb-2016 Xia Yang <xiay@nvidia.com> dumpstate: remove length modifier on assignment suppressed scanf item

gcc throws warning for using the two together as there is no point specifying
storage size if the item is not to be stored. With -Werror enabled in this
module, such warning breaks the build under gcc compiling.

Change-Id: I6478c7cdb39f4709a63089191cc4ff541564cea4
d5e724a4d3f77024d311b1b4e01846e41fdbe98b 11-Feb-2016 Felipe Leme <felipeal@google.com> Send broadcasts as Shell.

The BUGREPORT_STARTED was being sent as root, which would cause it to
bypass Shell restrictions when DISALLOW_DEBUGGING_FEATURES is set.

Also added the missing --receiver-background and unhardcoded shell's uid
from previous changes.

BUG: 26814173

Change-Id: I867361efafb96c7e709f83806a9301afc637a27e
fdf52d3697aa0396bd9d8883892937b99a6772a0 02-Feb-2016 Srinath Sridharan <srinathsr@google.com> Split dumpsys into critical and non-critical sections.

Order in which we report stats in bugreport can disrupt cpu and memory
stats. This CL sorts the bugreport process
from least impactful to most impactful to try and keep the
system stats as close to its initial state as possible throughout the BR (eg.
things like dumpsys meminfo should run before dumping thread stacks)

BUG: 26639621
Change-Id: I29dccfd423d83a6a69b7e025d45cb9cebfc41cc4
a297c3258f6f7ea52cc2dcc42d62f85fda12a163 06-Feb-2016 Mark Salyzyn <salyzyn@google.com> dumpstate: report process times

(cherry picked from commit 0751efa64cddfab69749236193e776058c9db595)

- Fix per-pid helper to pick up comm if cmdline is empty
and assume kernel thread.
- Add per pid report command line user time if not kernel thread,
system time and I/O time, plus percentage if non zero.

Bug: 26966375
Change-Id: I6b499f535cc3687eb468b32ae39e7d151dffb11f
cbce55d4fdbdd2e5a5515054c48d2116c5db2712 08-Feb-2016 Felipe Leme <felipeal@google.com> Improved dumpstate logging.

dumpstate generates 3 types of output:

- stdout: used for the bugreport itself and is redirected to a file
if requested.
- stderr: used for errors, is only useful when dumpstate is called from
adb (otherwise is ignored).
- ALOG: logged into logcat and available in the bugreport.

This current approach has 2 problems:

- stderr output is ignored when dumpstatet is called from bugreport
- bugs on dumpstate are often hard to diagnose
(AKA 'Who watches the watchmen?').

This change mitigates these problems by redirecting stderr into a log
file (which will also be included in the bugreport notification) and by
keeping the .tmp file around (for the extreme cases where the .zip file
could not be generated or got corrupted).

BUG: 26906985
Change-Id: I73e7b1dd10ad9f83b7aa1043131ff3b74c426fdb
111b9d06cc0fc72438782c9234f28675e5077ef4 03-Feb-2016 Felipe Leme <felipeal@google.com> Improved how the Shell directories are created.

When dumpstate is run for the first time, the
/data/data/com.android.shell/files/bugreports does not exist, which was
crashing dumpstate because the code that added the version.txt entry was
not checking if the zip_writer was NULL.

The crash itself was fixed by adding a sanity check in the functions
that add entries to the zip file, but that only hid the real problem:
it is necessary to create the parent directories before creating the zip
file, otherwise the first run will always generate a .txt file (since
dumpstate falls back to .txt when it cannot create the .zip).

This change also improves how the parent directories are created by
checking if they exist first, rather than always calling mkdir().

BUG: 26949960

Change-Id: I1434be5c36a3fad0b3a2a26c7eaaab03a1228c30
608385dd151e36a93f3e3f4a7514b1e720d20ae9 01-Feb-2016 Felipe Leme <felipeal@google.com> Redirect output to file ASAP, otherwise printf() calls might be missed.

Also removed the duraction reporter on add_zip_entry_from_fd - since it
was spamming the report and the timing could be infered by calculating the
delta between each ALOGD entry anyways - and logged PID and statistics.

BUG: 26885492
Change-Id: Iadb00957daac68b7a40b0e36ee5cce2b82264588
942c50d1e5fa92a8e9b5c5a20a6918ee72ee68f2 29-Jan-2016 Felipe Leme <felipeal@google.com> Merge "Fixed usage --receiver-foreground on am call."
b0b4aa2d1df3c2c1f591776083a33cd28ad306bd 29-Jan-2016 Felipe Leme <felipeal@google.com> Fixed usage --receiver-foreground on am call.

BUG: 26871362
Change-Id: Ied8e663eec59c83a06a8f2a6e2908c02ac1558c8
f5248da50134b087cbe8b58d2e1d2310537911e3 28-Jan-2016 Chien-Yu Chen <cychen@google.com> dumpstate: enable cameraserver

Enable bugreport callstack dump for cameraserver.

Bug: 24511454
Change-Id: I8f4b14a95b3a1abedc4cf072335f0f31b18006af
edb0b0c309dd1a48d127f691e6d9b29392d1af44 27-Jan-2016 Felipe Leme <felipeal@google.com> Pass --receiver-foreground to AM intents.

BUG: 26805230
Change-Id: I29181367522353817c730b398550a738a4776594
770410dcf2f72cf4e806442263e63719a0be0f5a 27-Jan-2016 Felipe Leme <felipeal@google.com> Fixed performance issue by moving buffer allocation outside loop.

Also improved logging.

BUG: 26637170
BUG: 26777547
Change-Id: I99511f3f71c58eba1f5539508f9a685d0a58cc58
635ca31754ae734b0c540ac5600d58ae55cd4237 05-Jan-2016 Felipe Leme <felipeal@google.com> Include mount info on zipped bugreport.

BUG: 7280247
Change-Id: Iae2a7881c11564c8dbd3641f5ee5ab72c181da2a
0c80cf0caaf5dce5ef4d0265b249bd1ec680cca1 05-Jan-2016 Felipe Leme <felipeal@google.com> Adds all tombstone files when writing to zipped file.

Currently, a bugreport simply cats any tombstone file modified in the
last half an hour into the bugreport. This is a problem since the
tombstones contain a lot of really valuable information, and sometimes
users don't get a bugreport in this time frame. In addition, some of our
monkey testing has the same problem.

Since now dumpstate can create a zip file, we can include all directly
on it, although still using the old mechanism when it's creating it (for example, when invoked through 'adb bugreport').

BUG: 25974224
Change-Id: Ie29fd7d91953d91232b0db1c9588043aee13f93e
78f2c86235d5882a8dc84c85a1c1864062e5f3af 21-Dec-2015 Felipe Leme <felipeal@google.com> Prints out how long it takes to generate each section.

It's done using a DurationReporter helper class that prints starts
counting when constructed and prints the duration when destructed.

Typical usage:

function do_something() {
DurationReporter duration_reporter(title);
// Do something.

Change-Id: I87134d9a1b003300384376c242a3c034a46244c4
9609bbd79668dbc3c8c16c773c92637de98bfa70 15-Dec-2015 Andy Hung <hunga@google.com> dumpstate: add audioserver

enable bugreport callstack dump of /system/bin/audioserver

Bug: 24511453
Change-Id: I1c73c2ec299913b717e69b357bd669babafe58d1
7def230c05111876d44f56cd2a4f711b4b408c48 11-Dec-2015 Mark Salyzyn <salyzyn@google.com> Merge "dumpstate: build breakage @2482293" am: c93d0937e4
am: 8197219a6e

* commit '8197219a6e34d72174fc69ff60608afec912a4f4':
dumpstate: build breakage @2482293
f55d402132afa4b9dd38aa69e50ec7b7efb1927c 11-Dec-2015 Mark Salyzyn <salyzyn@google.com> resolve merge conflicts of 01c1129fe6 to master.

Change-Id: I84f862b4858ecc97461750833a0e6f9cf96c34c4
3634a1e3459cb609da709646107e246cafbc01f9 09-Dec-2015 Felipe Leme <felipeal@google.com> Fixed logic that was passing NULL to a std::string parameter and
crashing dumpstate.

BUG: 8420215
Change-Id: If2f3ebad559683b5b6a8c2209de93ac3bec4fb1e
e338bf60701e5b955ab0a097f2631f2190218894 07-Dec-2015 Felipe Leme <felipeal@google.com> Take screenshot right away when invoked with -P.

Traditionally, the screenshot was not taken right away because it could
skew other services like the Surface Flinger, and such approach often
resulted on irrelevant screenshots.

Now there is more user-friendly workflow, where the bugreport progress
is shown in the UI and the user can take further actions. In this
workflow, it's ok to take the screeshot right away, since the other
features might already be causing interference: if the user doesn't want
interference, the old workflow should be used instead.

Since the new workflow requires the -P (for Progress) parameter, such
parameter can also be used to determine when to take the screenshot.

Also added progress statistics at the end of the bugreport.

BUG: 8420215
Change-Id: I9dad8ea59d47848f217182ccec0f527b42e07f50
ad5f6c475934ac6a658a203069a9f055540946e7 30-Nov-2015 Felipe Leme <felipeal@google.com> Minor improvements in the bugreport progress workflow:

- Allow users to rename the suffix in the bugreport files by setting the
dumpstate.pid.name system property. For example, instead of
bugreport-2015-12-02-15-23-46, it could be bugreport-My-App-Crashed.

- Dynamically adjust the max weight if the current progress overflows
the previous max (and set the dumpstate.pid.max system property
accordingly, so UI can be updated as well).

- Strip .txt from the name sent on BUGREPORT_STARTED.

BUG: 25794470
Change-Id: I7634ddd2975bcf93d6612d16c09da1cd7b4e1d91
08b5578b7370b11e6eeb1f2619fd9d54b0536760 01-Dec-2015 Felipe Leme <felipeal@google.com> Fix initial value of do_update_progress.

Since it was set to 1, dumpstate (and bugreport as well) would fail if
-o option was not set.

BUG: 25944860
Change-Id: Iafcb2bc6a4120ebff237f25a998a3c528d7bc1aa
71bbfc57974331dce79242ce806d92035fce06ba 23-Nov-2015 Felipe Leme <felipeal@google.com> Adds a -P option so dumpstate can report its progress.

The old workflow was:

1. dumpstate starts.
2. When dumpstate finishes, it sends a BUGREPORT_FINISHED event.
3. Shell's BugreportReceiver receives the BUGREPORT_FINISHED and issues a
system notification so user can share the bug report.

The new workflow is:

1. When dumpstate starts, it sends a BUGREPORT_STARTED with its pid and
the estimated total effort.
2. When Shell's BugreportReceiver receives the BUGREPORT_STARTED, it:
2.1 Issues a system notification so user can watch the
progresss (which is 0% initially).
2.2 Starts a service (BugreportProgressService) responsible for
polling the dumpstate progress (using system properties and the
pid) and updating the system notification.
3. As dumpstate progress, it updates the proper system property.
4. When dumpstate finishes, it sends a BUGREPORT_FINISHED event.
5. When Shell's BugreportReceiver receives the BUGREPORT_FINISHED, it:
5.1 Finishes the service if necessary.
5.2 Issues a system notification so user can share the bug report.

This CL handles the dumpstate changes only, the Shell changes will be
handled in a separate CL.

BUG: 25794470
Change-Id: I6e04203411802c88ab0d093420ccdfd26700d565
36b3f6ff17e456dea81501006e33d5fdd1d3b480 20-Nov-2015 Felipe Leme <felipeal@google.com> Allow broadcasting of bug reports without a screenshot.

BUG: 25751868
Change-Id: Ideaa6c549f639aa64b30225147b2fad6c5f2d556
ed24d2ae2cd6e8b0afb86efa555f18bcfaf74a64 12-Nov-2015 Christopher Ferris <cferris@google.com> Fix a few bugs related to dumping files.


- Fix double print of header in dump_file.

- Fix a few possible file descriptor leaks.

- Add /d/ as another directory which should be skipped when printing out
last mod time of a file.

- Fix possible crash if the path passed to _dump_file_from_fd is less than
the length of one of the directory checks.

Change-Id: I450dfab76fd0ce4d4dca9ed39c82a980054f3cc3
d907b32052aca02ad679e6ae786848d328723080 17-Oct-2015 keunyoung <keunyoung@google.com> add vehicle_network_service to stack dump

bug: 24095928
Change-Id: I32874f36003cd0dfacc8d9d5b568e6fc963bfa43
93d705b6d742e8f00167ff2384e35c2205a6f9da 11-Nov-2015 Felipe Leme <felipeal@google.com> Add option to #define _DUMPSTATE_DRY_RUN_ to skip the actual dumps.

Such option is useful when debugging dumpstate itself, since it will
finish much sooner and its output will be much smaller.

Change-Id: If821ed21715461bf82eea0b2be4b926239ad69da
8620bb4118a68721d10c29529dc6978847d08d00 10-Nov-2015 Felipe Leme <felipeal@google.com> Migrated dumpstate to C++.

Changes required:

- Explicity casting function pointers.
- Moving variables initialization before 'goto' statements.
- Changing string references from 'char *' to 'const char *'.
- Using 'extern "C"' so device-dependent implementation of
'dumpstate_board()' can be written in C or C++.

BUG: 25563823
Change-Id: I5712c2adbe181c6d17983cbb136b17757900b4ba