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