HPCToolkit
PCProfile.cpp
Go to the documentation of this file.
1 // -*-Mode: C++;-*-
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 //***************************************************************************
48 //
49 // File:
50 // PCProfile.C
51 //
52 // Purpose:
53 // [The purpose of this file]
54 //
55 // Description:
56 // [The set of functions, macros, etc. defined in the file]
57 //
58 //***************************************************************************
59 
60 //************************* System Include Files ****************************
61 
62 #include <iostream>
63 
64 //*************************** User Include Files ****************************
65 
66 #include "PCProfile.hpp"
67 
68 //*************************** Forward Declarations ***************************
69 
70 using std::endl;
71 using std::hex;
72 using std::dec;
73 
74 //****************************************************************************
75 // PCProfileMetricSet
76 //****************************************************************************
77 
79  : isa(isa_)
80 {
81  metricVec.reserve(16);
82  isa->attach();
83 }
84 
86 {
87  for (unsigned int i = 0; i < GetSz(); i++) {
88  delete metricVec[i];
89  }
90  metricVec.clear();
91  isa->detach();
92 }
93 
94 int
96 {
97  for (unsigned int i = 0; i < GetSz(); i++) {
98  const PCProfileMetric* m = Index(i);
99  if (m->Find(pc, opIndex) != PCProfileDatum_NIL) {
100  return (int)i; // this cast should never be a problem
101  }
102  }
103  return -1;
104 }
105 
108 {
110 
111  for (unsigned int i = 0; i < GetSz(); i++) {
112  PCProfileMetric* m = metricVec[i];
113  if ( (*filter)(m) ) {
114  s->Add(m);
115  }
116  }
117  return s;
118 }
119 
120 void
121 PCProfileMetricSet::dump(std::ostream& o)
122 {
123  o << "'PCProfileMetricSet' --\n";
124  o << " vec size: " << GetSz() << "\n";
125  for (unsigned int i = 0; i < GetSz(); i++) {
126  metricVec[i]->dump(o);
127  }
128 }
129 
130 void
132 {
133  dump(std::cerr);
134 }
135 
136 
137 //****************************************************************************
138 // PCProfile
139 //****************************************************************************
140 
141 PCProfile::PCProfile(ISA* isa_, unsigned int sz)
142  : PCProfileMetricSet(isa_, sz)
143 {
144  pcVec.reserve(1024);
145 }
146 
148 {
149  pcVec.clear();
150 }
151 
152 void
154 {
155  if (pcVec.size() == pcVec.capacity()) {
156  pcVec.reserve(pcVec.capacity() * 2);
157  }
158  VMA oppc = GetISA()->convertVMAToOpVMA(pc, opIndex);
159  pcVec.push_back(oppc);
160 }
161 
162 void
163 PCProfile::dump(std::ostream& o)
164 {
165  o << "'PCProfile' --\n";
166  o << " file: " << profiledFile << "\n";
167  o << " header info:\n" << fHdrInfo;
169 }
170 
171 void
173 {
174  dump(std::cerr);
175 }
176 
177 //****************************************************************************
178 // PCProfileVec
179 //****************************************************************************
180 
182  : datum(0), vec(sz, PCProfileDatum_NIL)
183 {
184 }
185 
186 bool
188 {
189  for (ulong i = 0; i < vec.size(); i++) {
190  if (vec[i] != PCProfileDatum_NIL) { return false; }
191  }
192  return true; // every entry is '0'
193 }
194 
195 void
196 PCProfileVec::dump(std::ostream& o)
197 {
198  o << "'PCProfileVec' --\n";
199  o << " datum=" << datum << endl;
200  o << " vec=[";
201  for (unsigned int i = 0; i < vec.size(); i++) {
202  if (i != 0) { o << ", "; }
203  o << vec[i];
204  }
205  o << "]" << endl;
206 }
207 
208 void
210 {
211  dump(std::cerr);
212 }
std::vector< PCProfileDatum > vec
Definition: PCProfile.hpp:349
void ddump()
Definition: PCProfile.cpp:172
virtual VMA convertVMAToOpVMA(VMA vma, ushort GCC_ATTR_UNUSED opIndex) const
Definition: ISA.hpp:471
PCProfileDatum Find(VMA pc, ushort opIndex) const
void ddump()
Definition: PCProfile.cpp:209
void dump(std::ostream &o=std::cerr)
Definition: PCProfile.cpp:196
PCProfileMetricSet * Filter(MetricFilter *filter) const
Definition: PCProfile.cpp:107
bfd_vma VMA
Definition: ISATypes.hpp:79
void Add(const PCProfileMetric *m)
Definition: PCProfile.hpp:124
PCProfileMetricSet(ISA *isa_, unsigned int sz=16)
virtual ~PCProfile()
Definition: PCProfile.cpp:147
void dump(std::ostream &o=std::cerr)
Definition: PCProfile.cpp:121
bool IsZeroed()
Definition: PCProfile.cpp:187
unsigned long int ulong
Definition: uint.h:128
unsigned short int ushort
Definition: uint.h:120
std::string fHdrInfo
Definition: PCProfile.hpp:271
Definition: ISA.hpp:106
int DataExists(VMA pc, ushort opIndex) const
Definition: PCProfile.cpp:95
void dump(std::ostream &o=std::cerr)
Definition: PCProfile.cpp:163
PCVec pcVec
Definition: PCProfile.hpp:273
ISA * GetISA() const
Definition: PCProfile.hpp:136
virtual ~PCProfileMetricSet()
Definition: PCProfile.cpp:85
std::string profiledFile
Definition: PCProfile.hpp:270
PCProfile(ISA *isa_, unsigned int sz=16)
Definition: PCProfile.cpp:141
void AddPC(VMA pc, ushort opIndex)
Definition: PCProfile.cpp:153
uint64_t datum
Definition: PCProfile.hpp:348
#define PCProfileDatum_NIL