dumpstate.h revision 93d705b6d742e8f00167ff2384e35c2205a6f9da
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#endif
27#ifndef _DUMPSTATE_DRY_RUN_
28#define ON_DRY_RUN_RETURN(X)
29#endif
30
31
32#include <time.h>
33#include <unistd.h>
34#include <stdbool.h>
35#include <stdio.h>
36
37#define SU_PATH "/system/xbin/su"
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43typedef void (for_each_pid_func)(int, const char *);
44typedef void (for_each_tid_func)(int, int, const char *);
45
46/* prints the contents of a file */
47int dump_file(const char *title, const char *path);
48
49/* prints the contents of the fd
50 * fd must have been opened with the flag O_NONBLOCK.
51 */
52int dump_file_from_fd(const char *title, const char *path, int fd);
53
54/* calls skip to gate calling dump_from_fd recursively
55 * in the specified directory. dump_from_fd defaults to
56 * dump_file_from_fd above when set to NULL. skip defaults
57 * to false when set to NULL. dump_from_fd will always be
58 * called with title NULL.
59 */
60int dump_files(const char *title, const char *dir,
61        bool (*skip)(const char *path),
62        int (*dump_from_fd)(const char *title, const char *path, int fd));
63
64/* forks a command and waits for it to finish -- terminate args with NULL */
65int run_command(const char *title, int timeout_seconds, const char *command, ...);
66
67/* forks a command and waits for it to finish
68   first element of args is the command, and last must be NULL.
69   command is always ran, even when _DUMPSTATE_DRY_RUN_ is defined. */
70int run_command_always(const char *title, int timeout_seconds, const char *args[]);
71
72/* prints all the system properties */
73void print_properties();
74
75/* redirect output to a service control socket */
76void redirect_to_socket(FILE *redirect, const char *service);
77
78/* redirect output to a file */
79void redirect_to_file(FILE *redirect, char *path);
80
81/* dump Dalvik and native stack traces, return the trace file location (NULL if none) */
82const char *dump_traces();
83
84/* for each process in the system, run the specified function */
85void for_each_pid(for_each_pid_func func, const char *header);
86
87/* for each thread in the system, run the specified function */
88void for_each_tid(for_each_tid_func func, const char *header);
89
90/* Displays a blocked processes in-kernel wait channel */
91void show_wchan(int pid, int tid, const char *name);
92
93/* Runs "showmap" for a process */
94void do_showmap(int pid, const char *name);
95
96/* Gets the dmesg output for the kernel */
97void do_dmesg();
98
99/* Prints the contents of all the routing tables, both IPv4 and IPv6. */
100void dump_route_tables();
101
102/* Play a sound via Stagefright */
103void play_sound(const char *path);
104
105/* Implemented by libdumpstate_board to dump board-specific info */
106void dumpstate_board();
107
108#ifdef __cplusplus
109}
110#endif
111
112#endif /* _DUMPSTATE_H_ */
113