1336817Sdim//===-- xray_profile_collector.h -------------------------------*- C++ -*-===// 2336817Sdim// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6336817Sdim// 7336817Sdim//===----------------------------------------------------------------------===// 8336817Sdim// 9336817Sdim// This file is a part of XRay, a dynamic runtime instrumentation system. 10336817Sdim// 11336817Sdim// This file defines the interface for a data collection service, for XRay 12336817Sdim// profiling. What we implement here is an in-process service where 13336817Sdim// FunctionCallTrie instances can be handed off by threads, to be 14336817Sdim// consolidated/collected. 15336817Sdim// 16336817Sdim//===----------------------------------------------------------------------===// 17336817Sdim#ifndef XRAY_XRAY_PROFILE_COLLECTOR_H 18336817Sdim#define XRAY_XRAY_PROFILE_COLLECTOR_H 19336817Sdim 20336817Sdim#include "xray_function_call_trie.h" 21336817Sdim 22336817Sdim#include "xray/xray_log_interface.h" 23336817Sdim 24336817Sdimnamespace __xray { 25336817Sdim 26336817Sdim/// The ProfileCollectorService implements a centralised mechanism for 27336817Sdim/// collecting FunctionCallTrie instances, indexed by thread ID. On demand, the 28336817Sdim/// ProfileCollectorService can be queried for the most recent state of the 29336817Sdim/// data, in a form that allows traversal. 30336817Sdimnamespace profileCollectorService { 31336817Sdim 32336817Sdim/// Posts the FunctionCallTrie associated with a specific Thread ID. This 33336817Sdim/// will: 34336817Sdim/// 35344779Sdim/// Moves the collection of FunctionCallTrie, Allocators, and Buffers associated 36344779Sdim/// with a thread's data to the queue. This takes ownership of the memory 37344779Sdim/// associated with a thread, and manages those exclusively. 38336817Sdim/// 39344779Sdimvoid post(BufferQueue *Q, FunctionCallTrie &&T, 40344779Sdim FunctionCallTrie::Allocators &&A, 41344779Sdim FunctionCallTrie::Allocators::Buffers &&B, tid_t TId); 42336817Sdim 43336817Sdim/// The serialize will process all FunctionCallTrie instances in memory, and 44336817Sdim/// turn those into specifically formatted blocks, each describing the 45336817Sdim/// function call trie's contents in a compact form. In memory, this looks 46336817Sdim/// like the following layout: 47336817Sdim/// 48336817Sdim/// - block size (32 bits) 49336817Sdim/// - block number (32 bits) 50336817Sdim/// - thread id (64 bits) 51336817Sdim/// - list of records: 52336817Sdim/// - function ids in leaf to root order, terminated by 53336817Sdim/// 0 (32 bits per function id) 54336817Sdim/// - call count (64 bit) 55336817Sdim/// - cumulative local time (64 bit) 56336817Sdim/// - record delimiter (64 bit, 0x0) 57336817Sdim/// 58336817Sdimvoid serialize(); 59336817Sdim 60336817Sdim/// The reset function will clear out any internal memory held by the 61336817Sdim/// service. The intent is to have the resetting be done in calls to the 62336817Sdim/// initialization routine, or explicitly through the flush log API. 63336817Sdimvoid reset(); 64336817Sdim 65336817Sdim/// This nextBuffer function is meant to implement the iterator functionality, 66336817Sdim/// provided in the XRay API. 67336817SdimXRayBuffer nextBuffer(XRayBuffer B); 68336817Sdim 69336817Sdim} // namespace profileCollectorService 70336817Sdim 71336817Sdim} // namespace __xray 72336817Sdim 73336817Sdim#endif // XRAY_XRAY_PROFILE_COLLECTOR_H 74