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";
68 std::string timestamp;
70 mx::sys::timeStamp(timestamp, ts);
73 std::cerr << __FILE__ <<
" " << __LINE__ <<
" loading: " << lfn.
fullName() <<
" " << timestamp <<
"\n";
84 std::cerr << __FILE__ <<
" " << __LINE__ <<
" overlapping log files!\n";
90 std::cerr << __FILE__ <<
" " << __LINE__ <<
" added before!\n";
97 std::cerr << __FILE__ <<
" " << __LINE__ <<
" gonna append\n";
104 std::cerr << __FILE__ <<
" " << __LINE__ <<
" added after!\n";
110 std::cerr << __FILE__ <<
" " << __LINE__ <<
" Need to implement insert in the middle!\n";
112 std::cerr << startTime.
time_s <<
" " << startTime.
time_ns <<
"\n";
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)
136 const std::string & appName,
145 std::cerr << __FILE__ <<
" " << __LINE__ <<
"\n";
150 std::cerr << __FILE__ <<
" " << __LINE__ <<
" getPriorLog empty map\n";
155 std::cerr << __FILE__ <<
" " << __LINE__ <<
"\n";
165 std::cerr << __FILE__ <<
" " << __LINE__ <<
"\n";
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;
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";
291 std::cerr <<
"Event code not found.\n";
306 std::cerr <<
"*************************************\n\n";
307 std::cerr <<
"No files for " << appName <<
"\n";
308 std::cerr <<
"*************************************\n\n";
313 std::cerr << __FILE__ <<
" " << __LINE__ <<
"\n";
321 std::cerr <<
"good!\n";
326 std::cerr << __FILE__ <<
" " << __LINE__ <<
"\n";
332 std::cerr << __FILE__ <<
" " << __LINE__ <<
"\n";
344 while( first->timestamp() > startTime)
351 std::cerr <<
"open earlier files!\n";
354 for(
auto it=last; it != first; --it)
373 while( last->timestamp() < startTime)
380 std::cerr <<
"open later file for " << appName <<
"!\n";
381 for(
auto it=first; it != last; ++it)
391 std::cerr << __FILE__ <<
" " << __LINE__ <<
"\n";
398 if( !(before->timestamp() < startTime) )
405 std::cerr << __FILE__ <<
" " << __LINE__ <<
"\n";
410 std::cerr <<
"No files in range for " << appName <<
"\n";
415 std::cerr << __FILE__ <<
" " << __LINE__ <<
"\n";
421 std::cerr << __FILE__ <<
" " << __LINE__ <<
"\n";
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
int loadFile(logFileName const &lfn)
std::vector< char > m_memory
The buffer holding the log.
flatlogs::timespecX m_endTime
int getPriorLog(char *&logBefore, const std::string &appName, const flatlogs::eventCodeT &ev, const flatlogs::timespecX &ts, char *hint=0)
Get the log for an event code which is the first prior to the supplied time.
appToBufferMapT m_appToBufferMap
int getNextLog(char *&logAfter, char *logCurrent, const std::string &appName)
Get the next log with the same event code which is after the supplied time.
int loadFiles(const std::string &appName, const flatlogs::timespecX &startTime)
int loadAppToFileMap(const std::string &dir, const std::string &ext)
Get log file names in a directory and distribute them into the map by app-name.
appToFileMapT m_appToFileMap
A fixed-width timespec structure.
nanosecT time_ns
Nanoseconds.
secT time_s
Time since the Unix epoch.