[MIPS GlobalISel] Lower call for callee that is register
[llvm-complete.git] / tools / llvm-xray / xray-account.h
blob9c9f86c8fcf7f9da739fa859b28a923fa06ef057
1 //===- xray-account.h - XRay Function Call Accounting ---------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the interface for performing some basic function call
10 // accounting from an XRay trace.
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_TOOLS_LLVM_XRAY_XRAY_ACCOUNT_H
14 #define LLVM_TOOLS_LLVM_XRAY_XRAY_ACCOUNT_H
16 #include <map>
17 #include <utility>
18 #include <vector>
20 #include "func-id-helper.h"
21 #include "llvm/Support/Program.h"
22 #include "llvm/Support/raw_ostream.h"
23 #include "llvm/XRay/XRayRecord.h"
25 namespace llvm {
26 namespace xray {
28 class LatencyAccountant {
29 public:
30 typedef std::map<int32_t, std::vector<uint64_t>> FunctionLatencyMap;
31 typedef std::map<llvm::sys::procid_t, std::pair<uint64_t, uint64_t>>
32 PerThreadMinMaxTSCMap;
33 typedef std::map<uint8_t, std::pair<uint64_t, uint64_t>> PerCPUMinMaxTSCMap;
34 typedef std::vector<std::pair<int32_t, uint64_t>> FunctionStack;
35 typedef std::map<llvm::sys::procid_t, FunctionStack>
36 PerThreadFunctionStackMap;
38 private:
39 PerThreadFunctionStackMap PerThreadFunctionStack;
40 FunctionLatencyMap FunctionLatencies;
41 PerThreadMinMaxTSCMap PerThreadMinMaxTSC;
42 PerCPUMinMaxTSCMap PerCPUMinMaxTSC;
43 FuncIdConversionHelper &FuncIdHelper;
45 bool DeduceSiblingCalls = false;
46 uint64_t CurrentMaxTSC = 0;
48 void recordLatency(int32_t FuncId, uint64_t Latency) {
49 FunctionLatencies[FuncId].push_back(Latency);
52 public:
53 explicit LatencyAccountant(FuncIdConversionHelper &FuncIdHelper,
54 bool DeduceSiblingCalls)
55 : FuncIdHelper(FuncIdHelper), DeduceSiblingCalls(DeduceSiblingCalls) {}
57 const FunctionLatencyMap &getFunctionLatencies() const {
58 return FunctionLatencies;
61 const PerThreadMinMaxTSCMap &getPerThreadMinMaxTSC() const {
62 return PerThreadMinMaxTSC;
65 const PerCPUMinMaxTSCMap &getPerCPUMinMaxTSC() const {
66 return PerCPUMinMaxTSC;
69 /// Returns false in case we fail to account the provided record. This happens
70 /// in the following cases:
71 ///
72 /// - An exit record does not match any entry records for the same function.
73 /// If we've been set to deduce sibling calls, we try walking up the stack
74 /// and recording times for the higher level functions.
75 /// - A record has a TSC that's before the latest TSC that has been
76 /// recorded. We still record the TSC for the min-max.
77 ///
78 bool accountRecord(const XRayRecord &Record);
80 const FunctionStack *getThreadFunctionStack(llvm::sys::procid_t TId) const {
81 auto I = PerThreadFunctionStack.find(TId);
82 if (I == PerThreadFunctionStack.end())
83 return nullptr;
84 return &I->second;
87 const PerThreadFunctionStackMap &getPerThreadFunctionStack() const {
88 return PerThreadFunctionStack;
91 // Output Functions
92 // ================
94 void exportStatsAsText(raw_ostream &OS, const XRayFileHeader &Header) const;
95 void exportStatsAsCSV(raw_ostream &OS, const XRayFileHeader &Header) const;
97 private:
98 // Internal helper to implement common parts of the exportStatsAs...
99 // functions.
100 template <class F> void exportStats(const XRayFileHeader &Header, F fn) const;
103 } // namespace xray
104 } // namespace llvm
106 #endif // LLVM_TOOLS_LLVM_XRAY_XRAY_ACCOUNT_H