orderfile_instrumentation.h 2.0 KB

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