81 int lastDot = globInputFile.find_last_of(
'.');
82 string suffix = globInputFile.substr(lastDot);
84 DEBUGCOUT(2) <<
"Checking to see if " << outputFile <<
" exists" << endl;
87 if (FileUtils::exists(outputFile))
92 if (isMergedFileCorrect(&outputFile))
95 cout <<
"Database file may be corrupted. Continuing" << endl;
103 if (!atLeastOneValidFile(directory))
119 vector<string> allPaths = FileUtils::getAllFilesInDir(directory);
120 vector<string> filteredFileNames;
121 vector<string>::iterator it;
122 for (it = allPaths.begin(); it != allPaths.end(); it++)
125 if (val.find(
".hpctrace") < string::npos)
126 filteredFileNames.push_back(val);
130 sort(filteredFileNames.begin(), filteredFileNames.end());
132 dos.writeInt(filteredFileNames.size());
134 Long num_metric_index = filteredFileNames.size()
136 FileOffset currentOffset = num_metric_header + num_metric_index;
146 vector<string>::iterator it2;
147 for (it2 = filteredFileNames.begin(); it2 < filteredFileNames.end(); it2++)
150 string Filename = *it2;
151 int last_pos_basic_name = Filename.length() - suffix.length();
152 string Basic_name = Filename.substr(FileUtils::combinePaths(directory,
"").length(),
153 last_pos_basic_name);
155 vector<string> tokens = splitString(Basic_name,
'-');
158 int num_tokens = tokens.size();
159 if (num_tokens < PROC_POS)
163 string Token_To_Parse = tokens[name_format + num_tokens - PROC_POS];
164 proc = atoi(Token_To_Parse.c_str());
165 if ((proc == 0) && (!FileUtils::stringActuallyZero(Token_To_Parse)))
169 string Token_To_Parse = tokens[name_format + num_tokens - PROC_POS];
170 proc = atoi(Token_To_Parse.c_str());
175 int Thread = atoi(tokens[name_format + num_tokens - THREAD_POS].c_str());
176 dos.writeInt(Thread);
179 dos.writeLong(currentOffset);
180 currentOffset += FileUtils::getFileSize(Filename);
185 ProgressBar prog(
"Merging database", filteredFileNames.size());
186 for (it2 = filteredFileNames.begin(); it2 < filteredFileNames.end(); it2++)
190 ifstream dis(i.c_str(), ios_base::binary | ios_base::in);
191 char data[PAGE_SIZE_GUESS];
192 dis.read(data, PAGE_SIZE_GUESS);
193 int bytesRead = dis.gcount();
194 while (bytesRead > 0)
196 dos.write(data, bytesRead);
197 dis.read(data, PAGE_SIZE_GUESS);
198 bytesRead = dis.gcount();
218 removeFiles(filteredFileNames);
228 bool MergeDataFiles::isMergedFileCorrect(
string* filename)
230 ifstream f(filename->c_str(), ios_base::binary | ios_base::in);
231 bool isCorrect =
false;
236 f.seekg(pos, ios_base::beg);
239 uint64_t marker = ByteUtilities::readLong(buffer);
241 isCorrect = (marker==MARKER_END_MERGED_FILE);
246 bool MergeDataFiles::removeFiles(vector<string> vect)
249 vector<string>::iterator it;
250 for (it = vect.begin(); it != vect.end(); ++it)
252 bool thisSuccess = (
remove(it->c_str()) == 0);
253 success &= thisSuccess;
257 bool MergeDataFiles::atLeastOneValidFile(
string dir)
259 vector<string> FileList = FileUtils::getAllFilesInDir(dir);
260 vector<string>::iterator it;
261 for (it = FileList.begin(); it != FileList.end(); ++it)
263 string filename = *it;
265 unsigned int l = filename.length();
267 string ending =
".hpctrace";
268 if (l < ending.length())
270 string supposedext = filename.substr(l - ending.length());
272 if (ending == supposedext)
280 vector<string> MergeDataFiles::splitString(
string toSplit,
char delimiter)
282 vector<string> toReturn;
283 stringstream ss(toSplit);
285 while (getline(ss, item, delimiter)) {
286 toReturn.push_back(item);
void incrementProgress(ulong tasks)