24 int fd = open(lfn.
fullName().c_str(), O_RDONLY );
26 off_t fsz = mx::ioutils::fileSize(fd);
28 std::vector<char> memory(fsz);
30 ssize_t nrd = read(fd, memory.data(), memory.size());
36 std::cerr << __FILE__ <<
" " << __LINE__ <<
" logInMemory::loadFile(" << lfn.
fullName() <<
") did not read all bytes\n";
46 while(st < memory.size())
52 if(st != memory.size())
54 std::cerr << __FILE__ <<
" " << __LINE__ <<
" Possibly corrupt logfile.\n";
62 if(m_memory.size() == 0)
64 m_memory.swap(memory);
65 m_startTime = startTime;
68 std::string timestamp;
70 mx::sys::timeStamp(timestamp, ts);
73 std::cerr << __FILE__ <<
" " << __LINE__ <<
" loading: " << lfn.
fullName() <<
" " << timestamp <<
"\n";
79 if(startTime < m_startTime)
82 if(endTime >= m_startTime)
84 std::cerr << __FILE__ <<
" " << __LINE__ <<
" overlapping log files!\n";
88 m_memory.insert(m_memory.begin(), memory.begin(), memory.end());
89 m_startTime = startTime;
90 std::cerr << __FILE__ <<
" " << __LINE__ <<
" added before!\n";
94 if(startTime > m_endTime)
97 std::cerr << __FILE__ <<
" " << __LINE__ <<
" gonna append\n";
100 m_memory.insert(m_memory.end(), memory.begin(), memory.end());
104 std::cerr << __FILE__ <<
" " << __LINE__ <<
" added after!\n";
110 std::cerr << __FILE__ <<
" " << __LINE__ <<
" Need to implement insert in the middle!\n";
111 std::cerr << m_startTime.time_s <<
" " << m_startTime.time_ns <<
"\n";
117 int logMap::loadAppToFileMap(
const std::string & dir,
118 const std::string & ext
121 std::vector<std::string> flist = mx::ioutils::getFileNames(dir,
"",
"", ext);
123 for(
size_t n=0;n<flist.size(); ++n)
129 m_appToFileMap[lfn.
appName()].insert(lfn);
135 int logMap::getPriorLog(
char * &logBefore,
136 const std::string & appName,
145 std::cerr << __FILE__ <<
" " << __LINE__ <<
"\n";
148 if(m_appToFileMap[appName].size() == 0)
150 std::cerr << __FILE__ <<
" " << __LINE__ <<
" getPriorLog empty map\n";
155 std::cerr << __FILE__ <<
" " << __LINE__ <<
"\n";
165 std::cerr << __FILE__ <<
" " << __LINE__ <<
"\n";
168 if(loadFiles(appName, ts) < 0)
170 std::cerr << __FILE__ <<
" " << __LINE__ <<
" error returned from loadfiles\n";
175 char* buffer, *priorBuffer;
185 priorBuffer = buffer;
190 priorBuffer = buffer;
198 std::cerr << __FILE__ <<
" " << __LINE__ <<
" Event code not found.\n";
208 std::cerr << __FILE__ <<
" " << __LINE__ <<
" attempt to read too mach data, possible log corruption.\n";
214 std::cerr << __FILE__ <<
" " << __LINE__ <<
" did not find following log for " << appName <<
" -- need to load more data.\n";
219 priorBuffer = buffer;
229 std::cerr << __FILE__ <<
" " << __LINE__ <<
" attempt to read too mach data, possible log corruption.\n";
235 std::cerr << __FILE__ <<
" " << __LINE__ <<
" did not find following log for " << appName <<
" -- need to load more data.\n";
247 logBefore = priorBuffer;
252 int logMap::getNextLog(
char * &logAfter,
254 const std::string & appName
270 std::cerr << __FILE__ <<
" " << __LINE__ <<
" Reached end of data for " << appName <<
" -- need to load more data\n";
282 std::cerr << __FILE__ <<
" " << __LINE__ <<
" Reached end of data for " << appName <<
"-- need to load more data\n";
300 int logMap::loadFiles(
const std::string & appName,
304 if(m_appToFileMap[appName].size() == 0)
306 std::cerr <<
"*************************************\n\n";
307 std::cerr <<
"No files for " << appName <<
"\n";
308 std::cerr <<
"*************************************\n\n";
313 std::cerr << __FILE__ <<
" " << __LINE__ <<
"\n";
317 if(m_appToBufferMap[appName].m_memory.size() > 0)
319 if( m_appToBufferMap[appName].m_startTime <= startTime && m_appToBufferMap[appName].m_endTime >= startTime)
326 std::cerr << __FILE__ <<
" " << __LINE__ <<
"\n";
329 if( m_appToBufferMap[appName].m_startTime > startTime )
332 std::cerr << __FILE__ <<
" " << __LINE__ <<
"\n";
335 auto last = m_appToFileMap[appName].begin();
336 while( last->timestamp() < m_appToBufferMap[appName].m_startTime)
339 if(last == m_appToFileMap[appName].end())
break;
344 while( first->timestamp() > startTime)
347 if(first == m_appToFileMap[appName].begin())
break;
354 for(
auto it=last;
it != first; --
it)
356 m_appToBufferMap[appName].loadFile(*
it);
363 auto first = m_appToFileMap[appName].end();
366 while( first->timestamp() > m_appToBufferMap[appName].m_endTime)
369 if(first == m_appToFileMap[appName].begin())
break;
373 while( last->timestamp() < startTime)
376 if(last == m_appToFileMap[appName].end())
break;
380 std::cerr <<
"open later file for " << appName <<
"!\n";
381 for(
auto it=first;
it != last; ++
it)
383 m_appToBufferMap[appName].loadFile(*
it);
391 std::cerr << __FILE__ <<
" " << __LINE__ <<
"\n";
394 auto before = m_appToFileMap[appName].begin();
396 for(; before != m_appToFileMap[appName].end(); ++before)
398 if( !(before->timestamp() < startTime) )
405 std::cerr << __FILE__ <<
" " << __LINE__ <<
"\n";
408 if(before == m_appToFileMap[appName].begin())
410 std::cerr <<
"No files in range for " << appName <<
"\n";
415 std::cerr << __FILE__ <<
" " << __LINE__ <<
"\n";
418 m_appToBufferMap.emplace(std::pair<std::string, logInMemory>(appName,
logInMemory()));
421 std::cerr << __FILE__ <<
" " << __LINE__ <<
"\n";
424 m_appToBufferMap[appName].loadFile(*before);
425 if(++before != m_appToFileMap[appName].end())
427 m_appToBufferMap[appName].loadFile(*before);
431 std::cerr << __FILE__ <<
" " << __LINE__ <<
"\n";
Organize and analyze the name of a log or telemetry file.
int fullName(const std::string &fullName)
Sets the full name.
std::string appName() const
Get the current value of m_appName.
uint16_t eventCodeT
The type of an event code (16-bit unsigned int).
static int eventCode(bufferPtrT &logBuffer, const eventCodeT &ec)
Set the event code of a log entry.
static size_t totalSize(bufferPtrT &logBuffer)
Get the total size of the log entry, including the message buffer.
static int timespec(bufferPtrT &logBuffer, const timespecX &ts)
Set the timespec of a log entry.
Declares and defines the logMap class and related classes.
Structure to hold a log file in memory, tracking when a new file needs to be opened.
flatlogs::timespecX m_startTime
std::vector< char > m_memory
The buffer holding the log.
flatlogs::timespecX m_endTime
A fixed-width timespec structure.
nanosecT time_ns
Nanoseconds.
secT time_s
Time since the Unix epoch.