| The Gaudi Framework v32r1 (f65d50dc)

Classes | Public Types | Public Member Functions | Public Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
FileInfo Class Reference
Collaboration diagram for FileInfo:
[legend]

## Classes
struct | CacheItem
struct | CacheItemComparator

## Public Types
typedef int | Offset

## Public Member Functions
| FileInfo (void)
| FileInfo (const std::string &name, bool useGdb)
const char * | symbolByOffset (Offset offset)
Offset | next (Offset offset)

## Public Attributes
std::string | NAME

## Private Types
typedef std::vector< CacheItem > | SymbolCache

## Private Member Functions
void | createOffsetMap (void)

## Private Attributes
SymbolCache | m_symbolCache

## Detailed Description

Definition at line 143 of file pfm_gen_analysis.cpp.

## Member Typedef Documentation

## ◆ Offset

typedef int FileInfo::Offset

Definition at line 145 of file pfm_gen_analysis.cpp.

## ◆ SymbolCache

typedef std::vector<CacheItem> FileInfo::SymbolCache
| private

Definition at line 178 of file pfm_gen_analysis.cpp.

## Constructor & Destructor Documentation

## ◆ FileInfo() [1/2]

FileInfo::FileInfo | ( | void |  | ) |
| inline

Definition at line 147 of file pfm_gen_analysis.cpp.

147 : NAME( "<dynamically generated>" ) {}
FileInfo::NAME
std::string NAME
Definition: pfm_gen_analysis.cpp:146

## ◆ FileInfo() [2/2]

FileInfo::FileInfo | ( | const std::string & | name,
|  | bool | useGdb
| ) |  |
| inline

Definition at line 148 of file pfm_gen_analysis.cpp.

148 : NAME( name ) {
149 if ( useGdb ) { this->createOffsetMap(); }
150 }
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
FileInfo::NAME
std::string NAME
Definition: pfm_gen_analysis.cpp:146
FileInfo::createOffsetMap
void createOffsetMap(void)
Definition: pfm_gen_analysis.cpp:186

## Member Function Documentation

## ◆ createOffsetMap()

void FileInfo::createOffsetMap | ( | void |  | ) |
| inline private

Definition at line 186 of file pfm_gen_analysis.cpp.

186 {
187 std::string commandLine = "objdump -p " + NAME;
188 PipeReader objdump( commandLine.c_str() );
189 std::string oldname;
190 std::string suffix;
191 int vmbase = 0;
192 bool matched = false;
193 while ( objdump.output() ) {
194 // Checks the following regexp
195 //
196 // LOAD\\s+off\\s+(0x[0-9A-Fa-f]+)\\s+vaddr\\s+(0x[0-9A-Fa-f]+)
197 //
198 // and sets vmbase to be $2 - $1 of the first matched entry.
199
200 std::string line;
201 std::getline( objdump.output(), line );
202
203 if ( !objdump.output() ) break;
204 if ( line.empty() ) continue;
205 const char* lineptr = line.c_str();
206 if ( !skipWhitespaces( lineptr, &lineptr ) ) continue;
207 if ( !skipString( "LOAD", lineptr, &lineptr ) ) continue;
208 if ( !skipWhitespaces( lineptr, &lineptr ) ) continue;
209 if ( !skipString( "off", lineptr, &lineptr ) ) continue;
210 char* endptr = 0;
211 int initialBase = strtol( lineptr, &endptr, 16 );
212 if ( lineptr == endptr ) continue;
213 lineptr = endptr;
214 if ( !skipWhitespaces( lineptr, &lineptr ) ) continue;
215 if ( !skipString( "vaddr", lineptr, &lineptr ) ) continue;
216 if ( !skipWhitespaces( lineptr, &lineptr ) ) continue;
217 int finalBase = strtol( lineptr, &endptr, 16 );
218 if ( lineptr == endptr ) continue;
219 vmbase = finalBase - initialBase;
220 matched = true;
221 break;
222 }
223 if ( !matched ) {
224 fprintf( stderr, "Cannot determine VM base address for %s\n", NAME.c_str() );
225 fprintf( stderr, "Error while running `objdump -p %s`\n", NAME.c_str() );
226 exit( 1 );
227 }
228 std::string commandLine2 = "nm -t d -n " + NAME;
229 PipeReader nm( commandLine2.c_str() );
230 while ( nm.output() ) {
231 std::string line;
232 std::getline( nm.output(), line );
233 if ( !nm.output() ) break;
234 if ( line.empty() ) continue;
235 // If line does not match "^(\\d+)[ ]\\S[ ](\S+)$", exit.
236 const char* begin = line.c_str();
237 char* endptr = 0;
238 int address = strtol( begin, &endptr, 10 );
239 if ( endptr == begin ) continue;
240 if ( *endptr++ != ' ' ) continue;
241 if ( isspace( *endptr++ ) ) continue;
242 if ( *endptr++ != ' ' ) continue;
243 char* symbolName = endptr;
244 while ( *endptr && !isspace( *endptr ) ) endptr++;
245 if ( *endptr != 0 ) continue;
246 // If line starts with '.' forget about it.
247 if ( symbolName[0] == '.' ) continue;
248 // Create a new symbol with the given fileoffset.
249 // The symbol is automatically saved in the FileInfo cache by offset.
250 // If a symbol with the same offset is already there, the new one
251 // replaces the old one.
252 int offset = address - vmbase;
253 if ( m_symbolCache.size() && ( m_symbolCache.back().OFFSET == offset ) )
254 m_symbolCache.back().NAME = symbolName;
255 else
256 m_symbolCache.push_back( CacheItem( address - vmbase, symbolName ) );
257 }
258 }
skipString
bool skipString(const char *strptr, const char *srcbuffer, const char **dstbuffer)
Definition: pfm_gen_analysis.cpp:137
std::getline
T getline(T... args)
FileInfo::NAME
std::string NAME
Definition: pfm_gen_analysis.cpp:146
std::string
STL class.
std::vector::push_back
T push_back(T... args)
PipeReader
Definition: pfm_gen_analysis.cpp:89
std::exit
T exit(T... args)
Gaudi::Units::nm
constexpr double nm
Definition: SystemOfUnits.h:81
std::vector::size
T size(T... args)
FileInfo::CacheItem::NAME
std::string NAME
Definition: pfm_gen_analysis.cpp:175
FileInfo::m_symbolCache
SymbolCache m_symbolCache
Definition: pfm_gen_analysis.cpp:179
std::string::c_str
T c_str(T... args)
std::strtol
T strtol(T... args)
FileInfo::CacheItem::OFFSET
Offset OFFSET
Definition: pfm_gen_analysis.cpp:173
std::vector::back
T back(T... args)
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition: AttribStringParser.h:120
skipWhitespaces
bool skipWhitespaces(const char *srcbuffer, const char **destbuffer)
Definition: pfm_gen_analysis.cpp:123
std::fprintf
T fprintf(T... args)
std::isspace
T isspace(T... args)
plotSpeedupsPyRoot.line
line
Definition: plotSpeedupsPyRoot.py:170

## ◆ next()

Offset FileInfo::next | ( | Offset | offset | ) |
| inline

Definition at line 165 of file pfm_gen_analysis.cpp.

165 {
166 SymbolCache::iterator i = upper_bound( m_symbolCache.begin(), m_symbolCache.end(), offset, CacheItemComparator() );
167 if ( i == m_symbolCache.end() ) { return 0; }
168 return i->OFFSET;
169 }
std::upper_bound
T upper_bound(T... args)
std::vector::end
T end(T... args)
std::vector::begin
T begin(T... args)
FileInfo::m_symbolCache
SymbolCache m_symbolCache
Definition: pfm_gen_analysis.cpp:179

## ◆ symbolByOffset()

const char* FileInfo::symbolByOffset | ( | Offset | offset | ) |
| inline

Definition at line 152 of file pfm_gen_analysis.cpp.

152 {
153 if ( m_symbolCache.empty() ) { return 0; }
154
155 SymbolCache::iterator i = lower_bound( m_symbolCache.begin(), m_symbolCache.end(), offset, CacheItemComparator() );
156 if ( i->OFFSET == offset ) { return i->NAME.c_str(); }
157
158 if ( i == m_symbolCache.begin() ) { return m_symbolCache.begin()->NAME.c_str(); }
159
160 --i;
161
162 return i->NAME.c_str();
163 }
std::vector::empty
T empty(T... args)
std::vector::end
T end(T... args)
std::lower_bound
T lower_bound(T... args)
FileInfo::CacheItem::NAME
std::string NAME
Definition: pfm_gen_analysis.cpp:175
std::vector::begin
T begin(T... args)
FileInfo::m_symbolCache
SymbolCache m_symbolCache
Definition: pfm_gen_analysis.cpp:179
std::string::c_str
T c_str(T... args)

## Member Data Documentation

## ◆ m_symbolCache

SymbolCache FileInfo::m_symbolCache
| private

Definition at line 179 of file pfm_gen_analysis.cpp.

## ◆ NAME

std::string FileInfo::NAME

Definition at line 146 of file pfm_gen_analysis.cpp.

The documentation for this class was generated from the following file:

- GaudiProfiling/src/app/pfm_gen_analysis.cpp