Path: blob/main/contrib/llvm-project/compiler-rt/lib/xray/xray_profile_collector.h
35263 views
//===-- xray_profile_collector.h -------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of XRay, a dynamic runtime instrumentation system.9//10// This file defines the interface for a data collection service, for XRay11// profiling. What we implement here is an in-process service where12// FunctionCallTrie instances can be handed off by threads, to be13// consolidated/collected.14//15//===----------------------------------------------------------------------===//16#ifndef XRAY_XRAY_PROFILE_COLLECTOR_H17#define XRAY_XRAY_PROFILE_COLLECTOR_H1819#include "xray_function_call_trie.h"2021#include "xray/xray_log_interface.h"2223namespace __xray {2425/// The ProfileCollectorService implements a centralised mechanism for26/// collecting FunctionCallTrie instances, indexed by thread ID. On demand, the27/// ProfileCollectorService can be queried for the most recent state of the28/// data, in a form that allows traversal.29namespace profileCollectorService {3031/// Posts the FunctionCallTrie associated with a specific Thread ID. This32/// will:33///34/// Moves the collection of FunctionCallTrie, Allocators, and Buffers associated35/// with a thread's data to the queue. This takes ownership of the memory36/// associated with a thread, and manages those exclusively.37///38void post(BufferQueue *Q, FunctionCallTrie &&T,39FunctionCallTrie::Allocators &&A,40FunctionCallTrie::Allocators::Buffers &&B, tid_t TId);4142/// The serialize will process all FunctionCallTrie instances in memory, and43/// turn those into specifically formatted blocks, each describing the44/// function call trie's contents in a compact form. In memory, this looks45/// like the following layout:46///47/// - block size (32 bits)48/// - block number (32 bits)49/// - thread id (64 bits)50/// - list of records:51/// - function ids in leaf to root order, terminated by52/// 0 (32 bits per function id)53/// - call count (64 bit)54/// - cumulative local time (64 bit)55/// - record delimiter (64 bit, 0x0)56///57void serialize();5859/// The reset function will clear out any internal memory held by the60/// service. The intent is to have the resetting be done in calls to the61/// initialization routine, or explicitly through the flush log API.62void reset();6364/// This nextBuffer function is meant to implement the iterator functionality,65/// provided in the XRay API.66XRayBuffer nextBuffer(XRayBuffer B);6768} // namespace profileCollectorService6970} // namespace __xray7172#endif // XRAY_XRAY_PROFILE_COLLECTOR_H737475