1f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross/* 2f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross * Copyright (C) 2008 The Android Open Source Project 3f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross * 4f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross * Licensed under the Apache License, Version 2.0 (the "License"); 5f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross * you may not use this file except in compliance with the License. 6f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross * You may obtain a copy of the License at 7f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross * 8f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross * http://www.apache.org/licenses/LICENSE-2.0 9f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross * 10f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross * Unless required by applicable law or agreed to in writing, software 11f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross * distributed under the License is distributed on an "AS IS" BASIS, 12f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross * See the License for the specific language governing permissions and 14f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross * limitations under the License. 15f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross */ 16f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross 17f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross#ifndef _DUMPSTATE_H_ 18f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross#define _DUMPSTATE_H_ 19f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross 2093d705b6d742e8f00167ff2384e35c2205a6f9daFelipe Leme/* When defined, skips the real dumps and just print the section headers. 2193d705b6d742e8f00167ff2384e35c2205a6f9daFelipe Leme Useful when debugging dumpstate itself. */ 2293d705b6d742e8f00167ff2384e35c2205a6f9daFelipe Leme//#define _DUMPSTATE_DRY_RUN_ 2393d705b6d742e8f00167ff2384e35c2205a6f9daFelipe Leme 2493d705b6d742e8f00167ff2384e35c2205a6f9daFelipe Leme#ifdef _DUMPSTATE_DRY_RUN_ 2593d705b6d742e8f00167ff2384e35c2205a6f9daFelipe Leme#define ON_DRY_RUN_RETURN(X) return X 26ed24d2ae2cd6e8b0afb86efa555f18bcfaf74a64Christopher Ferris#define ON_DRY_RUN(code) code 27ed24d2ae2cd6e8b0afb86efa555f18bcfaf74a64Christopher Ferris#else 2893d705b6d742e8f00167ff2384e35c2205a6f9daFelipe Leme#define ON_DRY_RUN_RETURN(X) 29ed24d2ae2cd6e8b0afb86efa555f18bcfaf74a64Christopher Ferris#define ON_DRY_RUN(code) 3093d705b6d742e8f00167ff2384e35c2205a6f9daFelipe Leme#endif 3193d705b6d742e8f00167ff2384e35c2205a6f9daFelipe Leme 32cbce55d4fdbdd2e5a5515054c48d2116c5db2712Felipe Leme#ifndef MYLOGD 3360869c9e1e91170d487715fc30b795d786630c54Felipe Leme#define MYLOGD(...) fprintf(stderr, __VA_ARGS__); ALOGD(__VA_ARGS__); 34cbce55d4fdbdd2e5a5515054c48d2116c5db2712Felipe Leme#endif 35cbce55d4fdbdd2e5a5515054c48d2116c5db2712Felipe Leme 36cbce55d4fdbdd2e5a5515054c48d2116c5db2712Felipe Leme#ifndef MYLOGI 3760869c9e1e91170d487715fc30b795d786630c54Felipe Leme#define MYLOGI(...) fprintf(stderr, __VA_ARGS__); ALOGI(__VA_ARGS__); 38cbce55d4fdbdd2e5a5515054c48d2116c5db2712Felipe Leme#endif 39cbce55d4fdbdd2e5a5515054c48d2116c5db2712Felipe Leme 40cbce55d4fdbdd2e5a5515054c48d2116c5db2712Felipe Leme#ifndef MYLOGE 4160869c9e1e91170d487715fc30b795d786630c54Felipe Leme#define MYLOGE(...) fprintf(stderr, __VA_ARGS__); ALOGE(__VA_ARGS__); 42cbce55d4fdbdd2e5a5515054c48d2116c5db2712Felipe Leme#endif 4393d705b6d742e8f00167ff2384e35c2205a6f9daFelipe Leme 44f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross#include <time.h> 45f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross#include <unistd.h> 460c22e8b31651caf12a2b4d4acef5bc65d486e570Colin Cross#include <stdbool.h> 47f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross#include <stdio.h> 4836b3f6ff17e456dea81501006e33d5fdd1d3b480Felipe Leme#include <vector> 49f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross 50f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross#define SU_PATH "/system/xbin/su" 51f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross 528620bb4118a68721d10c29529dc6978847d08d00Felipe Leme#ifdef __cplusplus 538620bb4118a68721d10c29529dc6978847d08d00Felipe Lemeextern "C" { 548620bb4118a68721d10c29529dc6978847d08d00Felipe Leme#endif 558620bb4118a68721d10c29529dc6978847d08d00Felipe Leme 560c22e8b31651caf12a2b4d4acef5bc65d486e570Colin Crosstypedef void (for_each_pid_func)(int, const char *); 570c22e8b31651caf12a2b4d4acef5bc65d486e570Colin Crosstypedef void (for_each_tid_func)(int, int, const char *); 580c22e8b31651caf12a2b4d4acef5bc65d486e570Colin Cross 5971bbfc57974331dce79242ce806d92035fce06baFelipe Leme/* Estimated total weight of bugreport generation. 6071bbfc57974331dce79242ce806d92035fce06baFelipe Leme * 6171bbfc57974331dce79242ce806d92035fce06baFelipe Leme * Each section contributes to the total weight by an individual weight, so the overall progress 6271bbfc57974331dce79242ce806d92035fce06baFelipe Leme * can be calculated by dividing the all completed weight by the total weight. 6371bbfc57974331dce79242ce806d92035fce06baFelipe Leme * 6471bbfc57974331dce79242ce806d92035fce06baFelipe Leme * This value is defined empirically and it need to be adjusted as more sections are added. 65ad5f6c475934ac6a658a203069a9f055540946e7Felipe Leme * 66ad5f6c475934ac6a658a203069a9f055540946e7Felipe Leme * It does not need to match the exact sum of all sections, but ideally it should to be slight more 67ad5f6c475934ac6a658a203069a9f055540946e7Felipe Leme * than such sum: a value too high will cause the bugreport to finish before the user expected (for 68faf67e3fe2451e75d0369906a579d3e1386a5064Felipe Leme * example, jumping from 70% to 100%), while a value too low will cause the progress to get stuck 69faf67e3fe2451e75d0369906a579d3e1386a5064Felipe Leme * at an almost-finished value (like 99%) for a while. 7071bbfc57974331dce79242ce806d92035fce06baFelipe Leme */ 71faf67e3fe2451e75d0369906a579d3e1386a5064Felipe Lemestatic const int WEIGHT_TOTAL = 6500; 7271bbfc57974331dce79242ce806d92035fce06baFelipe Leme 7371bbfc57974331dce79242ce806d92035fce06baFelipe Leme/* Most simple commands have 10 as timeout, so 5 is a good estimate */ 7471bbfc57974331dce79242ce806d92035fce06baFelipe Lemestatic const int WEIGHT_FILE = 5; 7571bbfc57974331dce79242ce806d92035fce06baFelipe Leme 7671bbfc57974331dce79242ce806d92035fce06baFelipe Leme/* 770c80cf0caaf5dce5ef4d0265b249bd1ec680cca1Felipe Leme * TODO: the dumpstate internal state is getting fragile; for example, this variable is defined 7871bbfc57974331dce79242ce806d92035fce06baFelipe Leme * here, declared at utils.cpp, and used on utils.cpp and dumpstate.cpp. 7971bbfc57974331dce79242ce806d92035fce06baFelipe Leme * It would be better to take advantage of the C++ migration and encapsulate the state in an object, 8071bbfc57974331dce79242ce806d92035fce06baFelipe Leme * but that will be better handled in a major C++ refactoring, which would also get rid of other C 8171bbfc57974331dce79242ce806d92035fce06baFelipe Leme * idioms (like using std::string instead of char*, removing varargs, etc...) */ 8202b7e00c1e1b0bf22997ab7ed913a9451e5b6b8aFelipe Lemeextern int do_update_progress, progress, weight_total, control_socket_fd; 8371bbfc57974331dce79242ce806d92035fce06baFelipe Leme 8471ca15eadd3da0c102a8539f7a88294a94456623Felipe Leme/* full path of the directory where the bugreport files will be written */ 8571ca15eadd3da0c102a8539f7a88294a94456623Felipe Lemeextern std::string bugreport_dir; 8671ca15eadd3da0c102a8539f7a88294a94456623Felipe Leme 8771ca15eadd3da0c102a8539f7a88294a94456623Felipe Leme/* root dir for all files copied as-is into the bugreport. */ 8871ca15eadd3da0c102a8539f7a88294a94456623Felipe Lemeextern const std::string ZIP_ROOT_DIR; 8971ca15eadd3da0c102a8539f7a88294a94456623Felipe Leme 9003974984bf23a24ec81fa87764e567590da14608Felipe Leme/* Checkes whether dumpstate is generating a zipped bugreport. */ 9103974984bf23a24ec81fa87764e567590da14608Felipe Lemebool is_zipping(); 9203974984bf23a24ec81fa87764e567590da14608Felipe Leme 9371ca15eadd3da0c102a8539f7a88294a94456623Felipe Leme/* adds a new entry to the existing zip file. */ 9471ca15eadd3da0c102a8539f7a88294a94456623Felipe Lemebool add_zip_entry(const std::string& entry_name, const std::string& entry_path); 9571ca15eadd3da0c102a8539f7a88294a94456623Felipe Leme 9671ca15eadd3da0c102a8539f7a88294a94456623Felipe Leme/* adds a new entry to the existing zip file. */ 9771ca15eadd3da0c102a8539f7a88294a94456623Felipe Lemebool add_zip_entry_from_fd(const std::string& entry_name, int fd); 9871ca15eadd3da0c102a8539f7a88294a94456623Felipe Leme 99249beee359da256f7c41c481d45c06765b6a1d8aCalvin On/* adds all files from a directory to the zipped bugreport file */ 100249beee359da256f7c41c481d45c06765b6a1d8aCalvin Onvoid add_dir(const char *dir, bool recursive); 101249beee359da256f7c41c481d45c06765b6a1d8aCalvin On 102f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross/* prints the contents of a file */ 1031fe6107b66516b225e0843836d60a69b1b57f3c3Christopher Ferrisint dump_file(const char *title, const char *path); 1041fe6107b66516b225e0843836d60a69b1b57f3c3Christopher Ferris 10571a74ac75c8687195d27642fa0db31a796102c59Felipe Leme/* saves the the contents of a file as a long */ 10671a74ac75c8687195d27642fa0db31a796102c59Felipe Lemeint read_file_as_long(const char *path, long int *output); 10771a74ac75c8687195d27642fa0db31a796102c59Felipe Leme 10854bcc5ffd5a79f4f194089c58d3de571532bf39bChristopher Ferris/* prints the contents of the fd 10954bcc5ffd5a79f4f194089c58d3de571532bf39bChristopher Ferris * fd must have been opened with the flag O_NONBLOCK. 11054bcc5ffd5a79f4f194089c58d3de571532bf39bChristopher Ferris */ 1111fe6107b66516b225e0843836d60a69b1b57f3c3Christopher Ferrisint dump_file_from_fd(const char *title, const char *path, int fd); 112f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross 113326842fca4883f1256aa9ed019bb3206ee76fca7Mark Salyzyn/* calls skip to gate calling dump_from_fd recursively 114326842fca4883f1256aa9ed019bb3206ee76fca7Mark Salyzyn * in the specified directory. dump_from_fd defaults to 115326842fca4883f1256aa9ed019bb3206ee76fca7Mark Salyzyn * dump_file_from_fd above when set to NULL. skip defaults 116326842fca4883f1256aa9ed019bb3206ee76fca7Mark Salyzyn * to false when set to NULL. dump_from_fd will always be 117326842fca4883f1256aa9ed019bb3206ee76fca7Mark Salyzyn * called with title NULL. 118326842fca4883f1256aa9ed019bb3206ee76fca7Mark Salyzyn */ 119326842fca4883f1256aa9ed019bb3206ee76fca7Mark Salyzynint dump_files(const char *title, const char *dir, 120326842fca4883f1256aa9ed019bb3206ee76fca7Mark Salyzyn bool (*skip)(const char *path), 121326842fca4883f1256aa9ed019bb3206ee76fca7Mark Salyzyn int (*dump_from_fd)(const char *title, const char *path, int fd)); 122326842fca4883f1256aa9ed019bb3206ee76fca7Mark Salyzyn 123cf6a8b47dc04f1c33ddc337b5e21f2c5b7354cb5Felipe Leme// TODO: need to refactor all those run_command variations; there shold be just one, receiving an 124cf6a8b47dc04f1c33ddc337b5e21f2c5b7354cb5Felipe Leme// optional CommandOptions objects with values such as run_always, drop_root, etc... 125cf6a8b47dc04f1c33ddc337b5e21f2c5b7354cb5Felipe Leme 126f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross/* forks a command and waits for it to finish -- terminate args with NULL */ 127cf6a8b47dc04f1c33ddc337b5e21f2c5b7354cb5Felipe Lemeint run_command_as_shell(const char *title, int timeout_seconds, const char *command, ...); 128f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Crossint run_command(const char *title, int timeout_seconds, const char *command, ...); 129f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross 13029c39715b8a45ca2e97aecd8ebb63183f63da72bFelipe Lemeenum RootMode { DROP_ROOT, DONT_DROP_ROOT }; 13129c39715b8a45ca2e97aecd8ebb63183f63da72bFelipe Lemeenum StdoutMode { NORMAL_STDOUT, REDIRECT_TO_STDERR }; 13229c39715b8a45ca2e97aecd8ebb63183f63da72bFelipe Leme 13393d705b6d742e8f00167ff2384e35c2205a6f9daFelipe Leme/* forks a command and waits for it to finish 13493d705b6d742e8f00167ff2384e35c2205a6f9daFelipe Leme first element of args is the command, and last must be NULL. 13593d705b6d742e8f00167ff2384e35c2205a6f9daFelipe Leme command is always ran, even when _DUMPSTATE_DRY_RUN_ is defined. */ 13629c39715b8a45ca2e97aecd8ebb63183f63da72bFelipe Lemeint run_command_always(const char *title, RootMode root_mode, StdoutMode stdout_mode, 13729c39715b8a45ca2e97aecd8ebb63183f63da72bFelipe Leme int timeout_seconds, const char *args[]); 138cf6a8b47dc04f1c33ddc337b5e21f2c5b7354cb5Felipe Leme 139cf6a8b47dc04f1c33ddc337b5e21f2c5b7354cb5Felipe Leme/* switch to non-root user and group */ 140cf6a8b47dc04f1c33ddc337b5e21f2c5b7354cb5Felipe Lemebool drop_root_user(); 14193d705b6d742e8f00167ff2384e35c2205a6f9daFelipe Leme 14236b3f6ff17e456dea81501006e33d5fdd1d3b480Felipe Leme/* sends a broadcast using Activity Manager */ 14336b3f6ff17e456dea81501006e33d5fdd1d3b480Felipe Lemevoid send_broadcast(const std::string& action, const std::vector<std::string>& args); 14436b3f6ff17e456dea81501006e33d5fdd1d3b480Felipe Leme 14571bbfc57974331dce79242ce806d92035fce06baFelipe Leme/* updates the overall progress of dumpstate by the given weight increment */ 14671bbfc57974331dce79242ce806d92035fce06baFelipe Lemevoid update_progress(int weight); 14771bbfc57974331dce79242ce806d92035fce06baFelipe Leme 148f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross/* prints all the system properties */ 149f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Crossvoid print_properties(); 150f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross 1512628e9e939fda323fa44c5cb743f4a77b12a312aFelipe Leme/** opens a socket and returns its file descriptor */ 1522628e9e939fda323fa44c5cb743f4a77b12a312aFelipe Lemeint open_socket(const char *service); 1532628e9e939fda323fa44c5cb743f4a77b12a312aFelipe Leme 154f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross/* redirect output to a service control socket */ 155f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Crossvoid redirect_to_socket(FILE *redirect, const char *service); 156f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross 157ff4a4dc7e6e3ead12020b4dc17548d767a419ddeChristopher Ferris/* redirect output to a file */ 158ff4a4dc7e6e3ead12020b4dc17548d767a419ddeChristopher Ferrisvoid redirect_to_file(FILE *redirect, char *path); 159f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross 160111b9d06cc0fc72438782c9234f28675e5077ef4Felipe Leme/* create leading directories, if necessary */ 161111b9d06cc0fc72438782c9234f28675e5077ef4Felipe Lemevoid create_parent_dirs(const char *path); 162111b9d06cc0fc72438782c9234f28675e5077ef4Felipe Leme 163bf7f49238d0af497d4300f7e611cf831854d6434Jeff Brown/* dump Dalvik and native stack traces, return the trace file location (NULL if none) */ 164bf7f49238d0af497d4300f7e611cf831854d6434Jeff Brownconst char *dump_traces(); 165f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross 166f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross/* for each process in the system, run the specified function */ 1670c22e8b31651caf12a2b4d4acef5bc65d486e570Colin Crossvoid for_each_pid(for_each_pid_func func, const char *header); 1680c22e8b31651caf12a2b4d4acef5bc65d486e570Colin Cross 1690c22e8b31651caf12a2b4d4acef5bc65d486e570Colin Cross/* for each thread in the system, run the specified function */ 1700c22e8b31651caf12a2b4d4acef5bc65d486e570Colin Crossvoid for_each_tid(for_each_tid_func func, const char *header); 171f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross 172f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross/* Displays a blocked processes in-kernel wait channel */ 1730c22e8b31651caf12a2b4d4acef5bc65d486e570Colin Crossvoid show_wchan(int pid, int tid, const char *name); 174f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross 175a297c3258f6f7ea52cc2dcc42d62f85fda12a163Mark Salyzyn/* Displays a processes times */ 176a297c3258f6f7ea52cc2dcc42d62f85fda12a163Mark Salyzynvoid show_showtime(int pid, const char *name); 177a297c3258f6f7ea52cc2dcc42d62f85fda12a163Mark Salyzyn 178f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross/* Runs "showmap" for a process */ 179f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Crossvoid do_showmap(int pid, const char *name); 180f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross 181f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross/* Gets the dmesg output for the kernel */ 182f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Crossvoid do_dmesg(); 183f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross 1842b3bba34aec65b612be8d1f52cd124d9c30955f9Sreeram Ramachandran/* Prints the contents of all the routing tables, both IPv4 and IPv6. */ 1852b3bba34aec65b612be8d1f52cd124d9c30955f9Sreeram Ramachandranvoid dump_route_tables(); 1862b3bba34aec65b612be8d1f52cd124d9c30955f9Sreeram Ramachandran 187f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross/* Play a sound via Stagefright */ 1881fe6107b66516b225e0843836d60a69b1b57f3c3Christopher Ferrisvoid play_sound(const char *path); 189f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross 190f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross/* Implemented by libdumpstate_board to dump board-specific info */ 191f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Crossvoid dumpstate_board(); 192f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross 193e338bf60701e5b955ab0a097f2631f2190218894Felipe Leme/* Takes a screenshot and save it to the given file */ 1943634a1e3459cb609da709646107e246cafbc01f9Felipe Lemevoid take_screenshot(const std::string& path); 195e338bf60701e5b955ab0a097f2631f2190218894Felipe Leme 1960c80cf0caaf5dce5ef4d0265b249bd1ec680cca1Felipe Leme/* Vibrates for a given durating (in milliseconds). */ 1970c80cf0caaf5dce5ef4d0265b249bd1ec680cca1Felipe Lemevoid vibrate(FILE* vibrator, int ms); 1980c80cf0caaf5dce5ef4d0265b249bd1ec680cca1Felipe Leme 1990c80cf0caaf5dce5ef4d0265b249bd1ec680cca1Felipe Leme/* Checks if a given path is a directory. */ 2000c80cf0caaf5dce5ef4d0265b249bd1ec680cca1Felipe Lemebool is_dir(const char* pathname); 2010c80cf0caaf5dce5ef4d0265b249bd1ec680cca1Felipe Leme 2020c80cf0caaf5dce5ef4d0265b249bd1ec680cca1Felipe Leme/** Gets the last modification time of a file, or default time if file is not found. */ 2030c80cf0caaf5dce5ef4d0265b249bd1ec680cca1Felipe Lemetime_t get_mtime(int fd, time_t default_mtime); 2040c80cf0caaf5dce5ef4d0265b249bd1ec680cca1Felipe Leme 205249beee359da256f7c41c481d45c06765b6a1d8aCalvin On/* Dumps eMMC Extended CSD data. */ 20678f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Lemevoid dump_emmc_ecsd(const char *ext_csd_path); 20778f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Leme 208249beee359da256f7c41c481d45c06765b6a1d8aCalvin On/** Gets command-line arguments. */ 209a34efb7ae17a7ea1078cce75be634120bd72a421Felipe Lemevoid format_args(int argc, const char *argv[], std::string *args); 21088c7933df551f6dadd8cc931d104b01d6d1609e4Felipe Leme 211249beee359da256f7c41c481d45c06765b6a1d8aCalvin On/** Tells if the device is running a user build. */ 212249beee359da256f7c41c481d45c06765b6a1d8aCalvin Onbool is_user_build(); 213249beee359da256f7c41c481d45c06765b6a1d8aCalvin On 21478f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Leme/* 21578f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Leme * Helper class used to report how long it takes for a section to finish. 21678f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Leme * 21778f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Leme * Typical usage: 21878f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Leme * 21978f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Leme * DurationReporter duration_reporter(title); 22078f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Leme * 22178f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Leme */ 22278f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Lemeclass DurationReporter { 22378f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Lemepublic: 22478f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Leme DurationReporter(const char *title); 225608385dd151e36a93f3e3f4a7514b1e720d20ae9Felipe Leme DurationReporter(const char *title, FILE* out); 22678f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Leme 22778f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Leme ~DurationReporter(); 22878f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Leme 22978f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Leme static uint64_t nanotime(); 23078f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Leme 23178f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Lemeprivate: 23278f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Leme const char* title_; 233608385dd151e36a93f3e3f4a7514b1e720d20ae9Felipe Leme FILE* out_; 23478f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Leme uint64_t started_; 23578f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Leme}; 23678f2c86235d5882a8dc84c85a1c1864062e5f3afFelipe Leme 2378620bb4118a68721d10c29529dc6978847d08d00Felipe Leme#ifdef __cplusplus 2388620bb4118a68721d10c29529dc6978847d08d00Felipe Leme} 2398620bb4118a68721d10c29529dc6978847d08d00Felipe Leme#endif 2408620bb4118a68721d10c29529dc6978847d08d00Felipe Leme 241f45fa6b2853cc32385375a0b63ee39ad6a968869Colin Cross#endif /* _DUMPSTATE_H_ */ 242