| # Gaudi Framework, version v22r2 |

Home |  | Generated: Tue May 10 2011

Classes | Public Types | Public Member Functions | Public Attributes | Private Types | Private Member Functions | Private Attributes

# FileInfo Class Reference

Collaboration diagram for FileInfo:
[legend]

List of all members.

## 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 163 of file pfm_gen_analysis.cpp.

## Member Typedef Documentation

typedef int FileInfo::Offset

Definition at line 166 of file pfm_gen_analysis.cpp.

typedef std::vector<CacheItem> FileInfo::SymbolCache`[private]`

Definition at line 218 of file pfm_gen_analysis.cpp.

## Constructor & Destructor Documentation

FileInfo::FileInfo | ( | void | ) | `[inline]`

Definition at line 168 of file pfm_gen_analysis.cpp.

    : NAME("<dynamically generated>") {}

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

Definition at line 169 of file pfm_gen_analysis.cpp.

                                                   : NAME(name)
      {
       if(useGdb)
       {
        this->createOffsetMap();
       }
      }

## Member Function Documentation

void FileInfo::createOffsetMap | ( | void | ) | `[inline, private]`

Definition at line 233 of file pfm_gen_analysis.cpp.

      {
       std::string commandLine = "objdump -p " + NAME;
       PipeReader objdump(commandLine.c_str());
       std::string oldname;
       std::string suffix;
       int vmbase = 0;
       bool matched = false;
       while(objdump.output())
       {
        // Checks the following regexp
        //
        //    LOAD\\s+off\\s+(0x[0-9A-Fa-f]+)\\s+vaddr\\s+(0x[0-9A-Fa-f]+)
        //
        // and sets vmbase to be $2 - $1 of the first matched entry.

        std::string line;
        std::getline(objdump.output(), line);

        if(!objdump.output()) break;
        if(line.empty()) continue;
        const char *lineptr = line.c_str();
        if(!skipWhitespaces(lineptr, &lineptr)) continue;
        if(!skipString("LOAD", lineptr, &lineptr)) continue;
        if(!skipWhitespaces(lineptr, &lineptr)) continue;
        if(!skipString("off", lineptr, &lineptr))  continue;
        char *endptr = 0;
        int initialBase = strtol(lineptr, &endptr, 16);
        if(lineptr == endptr) continue;
        lineptr = endptr;
        if(!skipWhitespaces(lineptr, &lineptr)) continue;
        if(!skipString("vaddr", lineptr, &lineptr)) continue;
        if(!skipWhitespaces(lineptr, &lineptr)) continue;
        int finalBase = strtol(lineptr, &endptr, 16);
        if(lineptr == endptr) continue;
        vmbase=finalBase - initialBase;
        matched = true;
        break;
       }
       if(!matched)
       {
        fprintf(stderr, "Cannot determine VM base address for %s\n", NAME.c_str());
        fprintf(stderr, "Error while running `objdump -p %s`\n", NAME.c_str());
        exit(1);
       }
       std::string commandLine2 = "nm -t d -n " + NAME;
       PipeReader nm(commandLine2.c_str());
       while(nm.output())
       {
        std::string line;
        std::getline(nm.output(), line);
        if(!nm.output()) break;
        if(line.empty()) continue;
        // If line does not match "^(\\d+)[ ]\\S[ ](\S+)$", exit.
        const char *begin = line.c_str();
        char *endptr = 0;
        int address = strtol(begin, &endptr, 10);
        if(endptr == begin) continue;
        if(*endptr++ != ' ') continue;
        if(isspace(*endptr++)) continue;
        if(*endptr++ != ' ') continue;
        char *symbolName = endptr;
        while(*endptr && !isspace(*endptr)) endptr++;
        if(*endptr != 0) continue;
        // If line starts with '.' forget about it.
        if(symbolName[0] == '.') continue;
        // Create a new symbol with the given fileoffset.
        // The symbol is automatically saved in the FileInfo cache by offset.
        // If a symbol with the same offset is already there, the new one
        // replaces the old one.
        int offset = address-vmbase;
        if(m_symbolCache.size() && (m_symbolCache.back().OFFSET == offset)) m_symbolCache.back().NAME = symbolName;
        else m_symbolCache.push_back(CacheItem(address-vmbase, symbolName));
       }
      }

Offset FileInfo::next | ( | Offset | offset ) | `[inline]`

Definition at line 200 of file pfm_gen_analysis.cpp.

      {
       SymbolCache::iterator i = upper_bound(m_symbolCache.begin(), m_symbolCache.end(), offset, CacheItemComparator());
       if(i == m_symbolCache.end())
       {
        return 0;
       }
       return i->OFFSET;
      }

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

Definition at line 177 of file pfm_gen_analysis.cpp.

      {
       if(m_symbolCache.empty())
       {
        return 0;
       }

       SymbolCache::iterator i = lower_bound(m_symbolCache.begin(), m_symbolCache.end(), offset, CacheItemComparator());
       if(i->OFFSET == offset)
       {
        return i->NAME.c_str();
       }

       if(i == m_symbolCache.begin())
       {
        return m_symbolCache.begin()->NAME.c_str();
       }

       --i;

       return i->NAME.c_str();
      }

## Member Data Documentation

SymbolCache FileInfo::m_symbolCache`[private]`

Definition at line 219 of file pfm_gen_analysis.cpp.

std::string FileInfo::NAME

Definition at line 167 of file pfm_gen_analysis.cpp.

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

- /afs/.cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v22r2/GaudiProfiling/src/app/pfm_gen_analysis.cpp

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines