File: TraceSessionSaver.h

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (112 lines) | stat: -rw-r--r-- 4,417 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//===-- SessionSaver.h ----------------------------------------*- C++ //-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_TARGET_TRACESESSIONSAVER_H
#define LLDB_TARGET_TRACESESSIONSAVER_H

#include "TraceJSONStructs.h"

namespace lldb_private {

class TraceSessionSaver {

public:
  /// Save the trace session description JSON object inside the given directory
  /// as a file named \a trace.json.
  ///
  /// \param[in] trace_session_description
  ///     The trace's session, as JSON Object.
  ///
  /// \param[in] directory
  ///     The directory where the JSON file will be saved.
  ///
  /// \return
  ///     \a llvm::success if the operation was successful, or an \a llvm::Error
  ///     otherwise.
  static llvm::Error
  WriteSessionToFile(const llvm::json::Value &trace_session_description,
                     FileSpec directory);

  /// Build the processes section of the trace session description file. Besides
  /// returning the processes information, this method saves to disk all modules
  /// and raw traces corresponding to the traced threads of the given process.
  ///
  /// \param[in] live_process
  ///     The process being traced.
  ///
  /// \param[in] raw_trace_fetcher
  ///     Callback function that receives a thread ID and returns its raw trace.
  ///     This callback should return \a None if the thread is not being traced.
  ///     Otherwise, it should return the raw trace in bytes or an
  ///     \a llvm::Error in case of failures.
  ///
  /// \param[in] directory
  ///     The directory where files will be saved when building the processes
  ///     section.
  ///
  /// \return
  ///     The processes section or \a llvm::Error in case of failures.
  static llvm::Expected<JSONTraceSessionBase> BuildProcessesSection(
      Process &live_process,
      std::function<
          llvm::Expected<llvm::Optional<std::vector<uint8_t>>>(lldb::tid_t tid)>
          raw_trace_fetcher,
      FileSpec directory);

  /// Build the threads sub-section of the trace session description file.
  /// For each traced thread, its raw trace is also written to the file
  /// \a thread_id_.trace inside of the given directory.
  ///
  /// \param[in] live_process
  ///     The process being traced.
  ///
  /// \param[in] raw_trace_fetcher
  ///     Callback function that receives a thread ID and returns its raw trace.
  ///     This callback should return \a None if the thread is not being traced.
  ///     Otherwise, it should return the raw trace in bytes or an
  ///     \a llvm::Error in case of failures.
  ///
  /// \param[in] directory
  ///     The directory where files will be saved when building the threads
  ///     section.
  ///
  /// \return
  ///     The threads section or \a llvm::Error in case of failures.
  static llvm::Expected<std::vector<JSONThread>> BuildThreadsSection(
      Process &live_process,
      std::function<
          llvm::Expected<llvm::Optional<std::vector<uint8_t>>>(lldb::tid_t tid)>
          raw_trace_fetcher,
      FileSpec directory);

  /// Build modules sub-section of the trace's session. The original modules
  /// will be copied over to the \a <directory/modules> folder. Invalid modules
  /// are skipped.
  /// Copying the modules has the benefit of making these trace session
  /// directories self-contained, as the raw traces and modules are part of the
  /// output directory and can be sent to another machine, where lldb can load
  /// them and replicate exactly the same trace session.
  ///
  /// \param[in] live_process
  ///     The process being traced.
  ///
  /// \param[in] directory
  ///     The directory where the modules files will be saved when building
  ///     the modules section.
  ///     Example: If a module \a libbar.so exists in the path
  ///     \a /usr/lib/foo/libbar.so, then it will be copied to
  ///     \a <directory>/modules/usr/lib/foo/libbar.so.
  ///
  /// \return
  ///     The modules section or \a llvm::Error in case of failures.
  static llvm::Expected<std::vector<JSONModule>>
  BuildModulesSection(Process &live_process, FileSpec directory);
};
} // namespace lldb_private

#endif // LLDB_TARGET_TRACESESSIONSAVER_H