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