UNPKG

2.85 kBtext/x-cView Raw
1/*
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the LICENSE
5 * file in the root directory of this source tree.
6 */
7#pragma once
8
9#include <iosfwd>
10#include <string>
11
12#include <jsi/jsi.h>
13
14namespace facebook {
15namespace jsi {
16
17/// Methods for starting and collecting instrumentation, an \c Instrumentation
18/// instance is associated with a particular \c Runtime instance, which it
19/// controls the instrumentation of.
20class Instrumentation {
21 public:
22 virtual ~Instrumentation() = default;
23
24 /// Returns GC statistics as a JSON-encoded string, with an object containing
25 /// "type" and "version" fields outermost. "type" is a string, unique to a
26 /// particular implementation of \c jsi::Instrumentation, and "version" is a
27 /// number to indicate any revision to that implementation and its output
28 /// format.
29 ///
30 /// \pre This call can only be made on the instrumentation instance of a
31 /// runtime initialised to collect GC statistics.
32 ///
33 /// \post All cumulative measurements mentioned in the output are accumulated
34 /// across the entire lifetime of the Runtime.
35 ///
36 /// \return the GC statistics collected so far, as a JSON-encoded string.
37 virtual std::string getRecordedGCStats() = 0;
38
39 /// Request statistics about the current state of the runtime's heap. This
40 /// function can be called at any time, and should produce information that is
41 /// correct at the instant it is called (i.e, not stale).
42 ///
43 /// \return a jsi Value containing whichever statistics the runtime supports
44 /// for its heap.
45 virtual Value getHeapInfo(bool includeExpensive) = 0;
46
47 /// perform a full garbage collection
48 virtual void collectGarbage() = 0;
49
50 /// Captures the heap to a file
51 ///
52 /// \param path to save the heap capture
53 ///
54 /// \param compact Whether the JSON should be compact or pretty
55 ///
56 /// \return true iff the heap capture succeeded
57 virtual bool createSnapshotToFile(const std::string& path, bool compact) = 0;
58
59 /// Captures the heap to an output stream
60 ///
61 /// \param os output stream to write to.
62 ///
63 /// \param compact Whether the JSON should be compact or pretty
64 ///
65 /// \return true iff the heap capture succeeded.
66 virtual bool createSnapshotToStream(std::ostream& os, bool compact) = 0;
67
68 /// Write a trace of bridge traffic to the given file name.
69 virtual void writeBridgeTrafficTraceToFile(
70 const std::string& fileName) const = 0;
71
72 /// Write basic block profile trace to the given file name.
73 virtual void writeBasicBlockProfileTraceToFile(
74 const std::string& fileName) const = 0;
75
76 /// Dump external profiler symbols to the given file name.
77 virtual void dumpProfilerSymbolsToFile(const std::string& fileName) const = 0;
78};
79
80} // namespace jsi
81} // namespace facebook