dumpstate.h revision 36b3f6ff17e456dea81501006e33d5fdd1d3b480
1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _DUMPSTATE_H_
18#define _DUMPSTATE_H_
19
20/* When defined, skips the real dumps and just print the section headers.
21   Useful when debugging dumpstate itself. */
22//#define _DUMPSTATE_DRY_RUN_
23
24#ifdef _DUMPSTATE_DRY_RUN_
25#define ON_DRY_RUN_RETURN(X) return X
26#define ON_DRY_RUN(code) code
27#else
28#define ON_DRY_RUN_RETURN(X)
29#define ON_DRY_RUN(code)
30#endif
31
32
33#include <time.h>
34#include <unistd.h>
35#include <stdbool.h>
36#include <stdio.h>
37#include <vector>
38
39#define SU_PATH "/system/xbin/su"
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45typedef void (for_each_pid_func)(int, const char *);
46typedef void (for_each_tid_func)(int, int, const char *);
47
48/* prints the contents of a file */
49int dump_file(const char *title, const char *path);
50
51/* prints the contents of the fd
52 * fd must have been opened with the flag O_NONBLOCK.
53 */
54int dump_file_from_fd(const char *title, const char *path, int fd);
55
56/* calls skip to gate calling dump_from_fd recursively
57 * in the specified directory. dump_from_fd defaults to
58 * dump_file_from_fd above when set to NULL. skip defaults
59 * to false when set to NULL. dump_from_fd will always be
60 * called with title NULL.
61 */
62int dump_files(const char *title, const char *dir,
63        bool (*skip)(const char *path),
64        int (*dump_from_fd)(const char *title, const char *path, int fd));
65
66/* forks a command and waits for it to finish -- terminate args with NULL */
67int run_command(const char *title, int timeout_seconds, const char *command, ...);
68
69/* forks a command and waits for it to finish
70   first element of args is the command, and last must be NULL.
71   command is always ran, even when _DUMPSTATE_DRY_RUN_ is defined. */
72int run_command_always(const char *title, int timeout_seconds, const char *args[]);
73
74/* sends a broadcast using Activity Manager */
75void send_broadcast(const std::string& action, const std::vector<std::string>& args);
76
77/* prints all the system properties */
78void print_properties();
79
80/* redirect output to a service control socket */
81void redirect_to_socket(FILE *redirect, const char *service);
82
83/* redirect output to a file */
84void redirect_to_file(FILE *redirect, char *path);
85
86/* dump Dalvik and native stack traces, return the trace file location (NULL if none) */
87const char *dump_traces();
88
89/* for each process in the system, run the specified function */
90void for_each_pid(for_each_pid_func func, const char *header);
91
92/* for each thread in the system, run the specified function */
93void for_each_tid(for_each_tid_func func, const char *header);
94
95/* Displays a blocked processes in-kernel wait channel */
96void show_wchan(int pid, int tid, const char *name);
97
98/* Runs "showmap" for a process */
99void do_showmap(int pid, const char *name);
100
101/* Gets the dmesg output for the kernel */
102void do_dmesg();
103
104/* Prints the contents of all the routing tables, both IPv4 and IPv6. */
105void dump_route_tables();
106
107/* Play a sound via Stagefright */
108void play_sound(const char *path);
109
110/* Implemented by libdumpstate_board to dump board-specific info */
111void dumpstate_board();
112
113#ifdef __cplusplus
114}
115#endif
116
117#endif /* _DUMPSTATE_H_ */
118