orderfile_instrumentation.h 2.0 KB

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