xref: /openbsd-src/gnu/llvm/compiler-rt/lib/xray/xray_profile_collector.h (revision 3cab2bb3f667058bece8e38b12449a63a9d73c4b)
1*3cab2bb3Spatrick //===-- xray_profile_collector.h -------------------------------*- C++ -*-===//
2*3cab2bb3Spatrick //
3*3cab2bb3Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*3cab2bb3Spatrick // See https://llvm.org/LICENSE.txt for license information.
5*3cab2bb3Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*3cab2bb3Spatrick //
7*3cab2bb3Spatrick //===----------------------------------------------------------------------===//
8*3cab2bb3Spatrick //
9*3cab2bb3Spatrick // This file is a part of XRay, a dynamic runtime instrumentation system.
10*3cab2bb3Spatrick //
11*3cab2bb3Spatrick // This file defines the interface for a data collection service, for XRay
12*3cab2bb3Spatrick // profiling. What we implement here is an in-process service where
13*3cab2bb3Spatrick // FunctionCallTrie instances can be handed off by threads, to be
14*3cab2bb3Spatrick // consolidated/collected.
15*3cab2bb3Spatrick //
16*3cab2bb3Spatrick //===----------------------------------------------------------------------===//
17*3cab2bb3Spatrick #ifndef XRAY_XRAY_PROFILE_COLLECTOR_H
18*3cab2bb3Spatrick #define XRAY_XRAY_PROFILE_COLLECTOR_H
19*3cab2bb3Spatrick 
20*3cab2bb3Spatrick #include "xray_function_call_trie.h"
21*3cab2bb3Spatrick 
22*3cab2bb3Spatrick #include "xray/xray_log_interface.h"
23*3cab2bb3Spatrick 
24*3cab2bb3Spatrick namespace __xray {
25*3cab2bb3Spatrick 
26*3cab2bb3Spatrick /// The ProfileCollectorService implements a centralised mechanism for
27*3cab2bb3Spatrick /// collecting FunctionCallTrie instances, indexed by thread ID. On demand, the
28*3cab2bb3Spatrick /// ProfileCollectorService can be queried for the most recent state of the
29*3cab2bb3Spatrick /// data, in a form that allows traversal.
30*3cab2bb3Spatrick namespace profileCollectorService {
31*3cab2bb3Spatrick 
32*3cab2bb3Spatrick /// Posts the FunctionCallTrie associated with a specific Thread ID. This
33*3cab2bb3Spatrick /// will:
34*3cab2bb3Spatrick ///
35*3cab2bb3Spatrick /// Moves the collection of FunctionCallTrie, Allocators, and Buffers associated
36*3cab2bb3Spatrick /// with a thread's data to the queue. This takes ownership of the memory
37*3cab2bb3Spatrick /// associated with a thread, and manages those exclusively.
38*3cab2bb3Spatrick ///
39*3cab2bb3Spatrick void post(BufferQueue *Q, FunctionCallTrie &&T,
40*3cab2bb3Spatrick           FunctionCallTrie::Allocators &&A,
41*3cab2bb3Spatrick           FunctionCallTrie::Allocators::Buffers &&B, tid_t TId);
42*3cab2bb3Spatrick 
43*3cab2bb3Spatrick /// The serialize will process all FunctionCallTrie instances in memory, and
44*3cab2bb3Spatrick /// turn those into specifically formatted blocks, each describing the
45*3cab2bb3Spatrick /// function call trie's contents in a compact form. In memory, this looks
46*3cab2bb3Spatrick /// like the following layout:
47*3cab2bb3Spatrick ///
48*3cab2bb3Spatrick ///   - block size (32 bits)
49*3cab2bb3Spatrick ///   - block number (32 bits)
50*3cab2bb3Spatrick ///   - thread id (64 bits)
51*3cab2bb3Spatrick ///   - list of records:
52*3cab2bb3Spatrick ///     - function ids in leaf to root order, terminated by
53*3cab2bb3Spatrick ///       0 (32 bits per function id)
54*3cab2bb3Spatrick ///     - call count (64 bit)
55*3cab2bb3Spatrick ///     - cumulative local time (64 bit)
56*3cab2bb3Spatrick ///     - record delimiter (64 bit, 0x0)
57*3cab2bb3Spatrick ///
58*3cab2bb3Spatrick void serialize();
59*3cab2bb3Spatrick 
60*3cab2bb3Spatrick /// The reset function will clear out any internal memory held by the
61*3cab2bb3Spatrick /// service. The intent is to have the resetting be done in calls to the
62*3cab2bb3Spatrick /// initialization routine, or explicitly through the flush log API.
63*3cab2bb3Spatrick void reset();
64*3cab2bb3Spatrick 
65*3cab2bb3Spatrick /// This nextBuffer function is meant to implement the iterator functionality,
66*3cab2bb3Spatrick /// provided in the XRay API.
67*3cab2bb3Spatrick XRayBuffer nextBuffer(XRayBuffer B);
68*3cab2bb3Spatrick 
69*3cab2bb3Spatrick } // namespace profileCollectorService
70*3cab2bb3Spatrick 
71*3cab2bb3Spatrick } // namespace __xray
72*3cab2bb3Spatrick 
73*3cab2bb3Spatrick #endif // XRAY_XRAY_PROFILE_COLLECTOR_H
74