xref: /aosp_15_r20/external/cronet/base/android/orderfile/orderfile_instrumentation.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2017 The Chromium Authors
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 <string>
10 #include <vector>
11 
12 #include "base/android/orderfile/orderfile_buildflags.h"
13 
14 namespace base {
15 namespace android {
16 namespace orderfile {
17 #if BUILDFLAG(DEVTOOLS_INSTRUMENTATION_DUMPING)
18 constexpr int kPhases = 2;
19 #else
20 constexpr int kPhases = 1;
21 #endif  // BUILDFLAG(DEVTOOLS_INSTRUMENTATION_DUMPING)
22 
23 constexpr size_t kStartOfTextForTesting = 1000;
24 constexpr size_t kEndOfTextForTesting = kStartOfTextForTesting + 1000 * 1000;
25 
26 // Stop recording. Returns false if recording was already disabled.
27 bool Disable();
28 
29 // Switches to the next recording phase. If called from the last phase, dumps
30 // the data to disk, and returns |true|. |pid| is the current process pid, and
31 // |start_ns_since_epoch| the process start timestamp.
32 bool SwitchToNextPhaseOrDump(int pid, uint64_t start_ns_since_epoch);
33 
34 // Starts a thread to dump instrumentation after a delay.
35 void StartDelayedDump();
36 
37 // Dumps all information for the current process, annotating the dump file name
38 // with the given tag. Will disable instrumentation. Instrumentation must be
39 // disabled before this is called.
40 void Dump(const std::string& tag);
41 
42 // Record an |address|, if recording is enabled. Only for testing.
43 void RecordAddressForTesting(size_t address);
44 
45 // Record |callee_address, caller_address|, if recording is enabled.
46 // Only for testing.
47 void RecordAddressForTesting(size_t callee_address, size_t caller_address);
48 
49 // Resets the state. Only for testing.
50 void ResetForTesting();
51 
52 // Returns an ordered list of reached offsets. Only for testing.
53 std::vector<size_t> GetOrderedOffsetsForTesting();
54 }  // namespace orderfile
55 }  // namespace android
56 }  // namespace base
57 
58 #endif  // BASE_ANDROID_ORDERFILE_ORDERFILE_INSTRUMENTATION_H_
59