1 // Copyright 2017 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_ANDROID_ORDERFILE_ORDERFILE_INSTRUMENTATION_H_ 6 #define BASE_ANDROID_ORDERFILE_ORDERFILE_INSTRUMENTATION_H_ 7 8 #include <cstdint> 9 #include <vector> 10 11 #include "base/android/orderfile/orderfile_buildflags.h" 12 13 namespace base { 14 namespace android { 15 namespace orderfile { 16 #if BUILDFLAG(DEVTOOLS_INSTRUMENTATION_DUMPING) 17 constexpr int kPhases = 2; 18 #else 19 constexpr int kPhases = 1; 20 #endif // BUILDFLAG(DEVTOOLS_INSTRUMENTATION_DUMPING) 21 22 constexpr size_t kStartOfTextForTesting = 1000; 23 constexpr size_t kEndOfTextForTesting = kStartOfTextForTesting + 1000 * 1000; 24 25 // Stop recording. Returns false if recording was already disabled. 26 bool Disable(); 27 28 // CHECK()s that the offsets are correctly set up. 29 void SanityChecks(); 30 31 // Switches to the next recording phase. If called from the last phase, dumps 32 // the data to disk, and returns |true|. |pid| is the current process pid, and 33 // |start_ns_since_epoch| the process start timestamp. 34 bool SwitchToNextPhaseOrDump(int pid, uint64_t start_ns_since_epoch); 35 36 // Starts a thread to dump instrumentation after a delay. 37 void StartDelayedDump(); 38 39 // Dumps all information for the current process, annotating the dump file name 40 // with the given tag. Will disable instrumentation. Instrumentation must be 41 // disabled before this is called. 42 void Dump(const std::string& tag); 43 44 // Record an |address|, if recording is enabled. Only for testing. 45 void RecordAddressForTesting(size_t address); 46 47 // Resets the state. Only for testing. 48 void ResetForTesting(); 49 50 // Returns an ordered list of reached offsets. Only for testing. 51 std::vector<size_t> GetOrderedOffsetsForTesting(); 52 } // namespace orderfile 53 } // namespace android 54 } // namespace base 55 56 #endif // BASE_ANDROID_ORDERFILE_ORDERFILE_INSTRUMENTATION_H_ 57