99 const string& ext,
uint extLen)
102 uint nmLen = strlen(entry->d_name);
103 if (nmLen > extLen) {
104 int cmpbeg = (nmLen - extLen);
105 return (strncmp(&entry->d_name[cmpbeg], ext.c_str(), extLen) == 0);
115 static const uint extLen = ext.length();
123 hpctraceFileFilter(
const struct dirent* entry)
126 static const uint extLen = ext.length();
143 static const int bufSZ = 32;
144 char buf[bufSZ] = {
'\0' };
147 is->read(buf, bufSZ);
183 for (StringVec::const_iterator it = inPaths.begin();
184 it != inPaths.end(); ++it) {
185 std::string path = *it;
188 if (path[path.length() - 1] !=
'/') {
192 struct dirent** dirEntries =
NULL;
193 int dirEntriesSz = scandir(path.c_str(), &dirEntries,
195 if (dirEntriesSz < 0) {
196 DIAG_Throw(
"could not read directory: " << path);
200 for (
int i = 0; i < dirEntriesSz; ++i) {
201 string nm = path + dirEntries[i]->d_name;
203 out.
paths->push_back(nm);
213 out.
paths->push_back(path);
244 size_t in = arg.find_first_of(
'=');
245 size_t indexOfEqual = 0;
247 int numBackslashesBeforeTrueEqual = 0;
249 size_t trailingIn = 0;
251 while (in != arg.npos) {
252 if (arg[in-1] !=
'\\') {
254 trueArg += arg.substr(trailingIn, in - trailingIn + 1);
258 if (indexOfEqual == 0) {
259 numBackslashesBeforeTrueEqual++;
264 trueArg += arg.substr(trailingIn, in - trailingIn - 1);
269 in = arg.find_first_of(
'=', (in + 1));
273 if (numEquals == 1) {
274 trueArg += arg.substr(arg.find_last_of(
'=') + 1);
275 indexOfEqual -= numBackslashesBeforeTrueEqual;
277 string oldVal = trueArg.substr(0, indexOfEqual);
278 string newVal = trueArg.substr(indexOfEqual + 1);
319 const string* unknownProcNm)
321 using namespace Prof;
327 Struct::File::demand(lmStrct, Struct::Tree::UnknownFileNm);
329 const string* unkProcNm =
330 (unknownProcNm) ? unknownProcNm : &Struct::Tree::UnknownProcNm;
333 Struct::Proc::demand(fileStrct, *unkProcNm);
336 Struct::Tree::UnknownLine,
356 std::map<string, string>& processedFiles,
358 const string& dstDir);
379 const string& dstDir)
382 std::map<string, string> processedFiles;
392 const string& fnm_orig =
408 if (!fnm_new.empty()) {
425 static std::pair<int, string>
434 std::map<string, string>& processedFiles,
436 const string& dstDir)
440 std::map<string, string>::iterator it = processedFiles.find(fnm_orig);
441 if (it != processedFiles.end()) {
442 fnm_new = it->second;
460 if (fnm_new.empty()) {
461 DIAG_WMsg(2,
"lost: " << fnm_orig);
464 DIAG_Msg(2,
" cp:" << fnm_orig <<
" -> " << fnm_new);
466 processedFiles.insert(make_pair(fnm_orig, fnm_new));
480 static std::pair<int, string>
493 for (
uint i = 0; i < pathVec.size(); i++) {
495 const string& curPath = pathVec[i].first;
496 string realPath(curPath);
500 realPath =
RealPath(realPath.c_str());
501 int realPathLn = realPath.length();
505 string tmpFile(filenm);
506 char* curFile =
const_cast<char*
>(tmpFile.c_str());
507 if (filenm[0] ==
'/') {
508 if (strncmp(curFile, realPath.c_str(), realPathLn) == 0) {
509 curFile = &curFile[realPathLn];
510 while (curFile[0] ==
'/') { ++curFile; }
522 if (foundIndex < 0) {
525 else if ((foundIndex >= 0) && (realPathLn > foundPathLn)) {
531 foundPathLn = realPathLn;
536 return make_pair(foundIndex, foundFnm);
548 const string& fnm_fnd = filenm;
549 const string& viewnm = pathTpl.second;
552 string fnm_new =
"./" + viewnm + fnm_fnd;
555 if (dstDir[0] !=
'/') {
558 fnm_to = fnm_to + dstDir +
"/" + viewnm + fnm_fnd;
559 string dir_to(fnm_to);
561 for (end = dir_to.length() - 1; dir_to[end] !=
'/'; end--) { }
567 DIAG_DevMsgIf(0,
"cp " << fnm_to);
590 for (std::set<string>::iterator it = srcFiles.begin();
591 it != srcFiles.end(); ++it) {
593 const string& x = *it;
596 const string& srcFnm2 = x;
606 bool copyDone =
false;
609 DIAG_Msg(2,
"trace (mv): '" << srcFnm1 <<
"' -> '" << dstFnm <<
"'");
614 DIAG_Msg(2,
"trace mv failed, trying cp");
620 DIAG_Msg(2,
"trace (cp): '" << srcFnm1 <<
"' -> '" << dstFnm <<
"'");
626 << srcFnm1 <<
"' -> '" << dstFnm <<
"']:" << ex.
message());
633 DIAG_Msg(2,
"trace (cp): '" << srcFnm2 <<
"' -> '" << dstFnm <<
"'");
638 << srcFnm2 <<
"' -> '" << dstFnm <<
"']:" << ex.
message());
static const char HPCRUN_FMT_Magic[]
void CloseStream(std::istream *s)
static int isRecursivePath(const char *path)
static const int HPCMETRICDB_FMT_MagicLen
static const int HPCTRACE_FMT_MagicLen
static int fileExtensionFilter(const struct dirent *entry, const string &ext, uint extLen)
NormalizeProfileArgs_t normalizeProfileArgs(const StringVec &inPaths)
static PathFindMgr & singleton()
void MONITOR_EXT_WRAP_NAME() free(void *ptr)
std::istream * OpenIStream(const char *filenm)
int parseReplacePath(const std::string &arg)
Prof::Struct::Stmt * makeStructureSimple(Prof::Struct::LM *lmStrct, BinUtil::LM *lm, VMA vma, const string *unknownProcNm)
const char * pathfind(const char *pathList, const char *name, const char *mode)
static std::pair< int, string > matchFileWithPath(const string &filenm, const Analysis::PathTupleVec &pathVec)
Analysis::Util::ProfType_t getProfileType(const std::string &filenm)
void copy(const char *dst,...)
bool isReadable(const char *path)
static const char HPCRUN_TraceFnmSfx[]
int remove(const char *file)
void move(const char *dst, const char *src)
static const char HPCRUN_ProfileFnmSfx[]
#define HPCRUNFLAT_FMT_Magic
static const char HPCMETRICDB_FMT_Magic[]
void copySourceFiles(Prof::Struct::Root *structure, const Analysis::PathTupleVec &pathVec, const string &dstDir)
void addPath(const std::string &oldPath, const std::string &newPath)
Prof::Struct::Stmt * demandStmtStructure(Prof::Struct::LM *lmStrct, Prof::Struct::Proc *procStrct, SrcFile::ln line, VMA begVMA, VMA endVMA)
bool isDir(const char *path)
virtual std::string message() const
static PathReplacementMgr & singleton()
void copyTraceFiles(const std::string &dstDir, const std::set< string > &srcFiles)
Prof::Struct::ACodeNode * demandStructure(VMA vma, Prof::Struct::LM *lmStrct, BinUtil::LM *lm, bool useStruct, const string *unknownProcNm)
static string copySourceFile(const string &filenm, const string &dstDir, const Analysis::PathTuple &pathTpl)
static const int HPCRUN_FMT_MagicLen
virtual const std::string & name() const
const std::string DefaultPathTupleTarget
std::vector< PathTuple > PathTupleVec
static const int RecursivePathSfxLn
static string copySourceFileMain(const string &fnm_orig, std::map< string, string > &processedFiles, const Analysis::PathTupleVec &pathVec, const string &dstDir)
static const char HPCPROF_TmpFnmSfx[]
#define DIAG_Msg(level,...)
int mkdir(const char *dir)
const char * RealPath(const char *nm)
static int hpcrunFileFilter(const struct dirent *entry)
#define HPCRUNFLAT_FMT_MagicLen
ACodeNode * findByVMA(VMA vma) const
virtual NonUniformDegreeTreeNode * Current() const
string basename(const char *fName)
static const char HPCTRACE_FMT_Magic[]
static bool Flat_Filter(const Prof::Struct::ANode &x, long GCC_ATTR_UNUSED type)
std::pair< std::string, std::string > PathTuple
std::vector< std::string > StringVec