Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#include <fstream>
#include <base/Time.hpp>
#include "StreamDescription.hpp"
#include "FileStream.hpp"
// #include "FileStream.hpp"
#include <iostream>

namespace pocolog_cpp
{
Expand Down Expand Up @@ -87,7 +88,7 @@ class Index
bool firstAdd;
size_t curSampleNr;
IndexInfo curIndexInfo;
FileStream indexFile;
std::ifstream indexFile;
std::vector<IndexInfo> buildBuffer;
IndexPrologue prologue;
base::Time firstSampleTime;
Expand Down
4 changes: 2 additions & 2 deletions src/IndexFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ bool IndexFile::createIndexFile(std::string indexFileName, LogFile& logFile)
{
throw std::runtime_error("IndexFile: Error building Index, Unexpected stream index");
}
foundIndices.emplace_back(newStream, descPos);
//foundIndices.emplace_back(newStream, descPos);
break;
}
case DataBlockType:
Expand Down Expand Up @@ -203,7 +203,7 @@ bool IndexFile::createIndexFile(std::string indexFileName, LogFile& logFile)

off_t curProloguePos = sizeof(IndexFileHeader);
off_t curDataPos = foundIndices.size() * Index::getPrologueSize() + sizeof(IndexFileHeader);
for ( auto curIdx : foundIndices )
for ( auto &curIdx : foundIndices )
{
LOG_INFO_S << "Writing index for stream " << curIdx.getName() << " , num samples " << curIdx.getNumSamples();

Expand Down
8 changes: 7 additions & 1 deletion src/LogFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ namespace pocolog_cpp

LogFile::LogFile(const std::string& fileName, bool verbose) : filename(fileName)
{
logFile.rdbuf()->pubsetbuf(0,0);
logFile.open(fileName.c_str(), std::ifstream::binary | std::ifstream::in);

if (!logFile.good()){
std::cerr << "\ncould not load " << fileName.c_str() << std::endl;
perror("stat");
throw std::runtime_error("Error, empty File");
}

fileSize = logFile.tellg();
logFile.seekg( 0, std::ios::end );
fileSize = logFile.tellg() - fileSize;

// Initialize position attributes, read or create the log file
rewind();
IndexFile *indexFile = new IndexFile(*this);
Expand Down Expand Up @@ -234,7 +240,7 @@ bool LogFile::readSampleHeader()

bool LogFile::checkSampleComplete()
{
return (logFile.size() >= nextBlockHeaderPos);
return (fileSize >= nextBlockHeaderPos);
}

std::streampos LogFile::getSamplePos() const
Expand Down
6 changes: 4 additions & 2 deletions src/LogFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#include <optional>
#include "Stream.hpp"
#include "Format.hpp"
#include "FileStream.hpp"
// #include "FileStream.hpp"
#include <iostream>
#include "OwnedValue.hpp"

namespace pocolog_cpp
Expand All @@ -20,8 +21,9 @@ class LogFile
std::streampos nextBlockHeaderPos;
std::streampos curBlockHeaderPos;
std::streampos curSampleHeaderPos;
FileStream logFile;
std::ifstream logFile;
std::vector<IndexFile *> indexFiles;
std::streampos fileSize;

std::vector<Stream *> streams;
std::vector<StreamDescription> descriptions;
Expand Down
5 changes: 4 additions & 1 deletion src/Stream.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "Stream.hpp"
#include <base-logging/Logging.hpp>
#include <iostream>
#include <stdexcept>



pocolog_cpp::Stream::Stream(const pocolog_cpp::StreamDescription& desc, pocolog_cpp::Index& index) : desc(desc), index(index)
{
fileStream.rdbuf()->pubsetbuf(0,0);
fileStream.open(desc.getFileName().c_str(), std::ifstream::binary | std::ifstream::in);
if(!fileStream.good())
throw std::runtime_error("Error, could not open logfile for stream " + desc.getName());
Expand All @@ -25,6 +27,7 @@ bool pocolog_cpp::Stream::loadSampleHeader(std::streampos pos, SampleHeaderData

bool pocolog_cpp::Stream::getSampleData(std::vector< uint8_t >& result, size_t sampleNr)
{
printf("%s:%i %li \n", __PRETTY_FUNCTION__, __LINE__, sampleNr);
std::streampos samplePos = index.getSamplePos(sampleNr);
std::streampos sampleHeaderPos = samplePos;
sampleHeaderPos -= sizeof(SampleHeaderData);
Expand Down
11 changes: 8 additions & 3 deletions src/Stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include "Format.hpp"
#include "StreamDescription.hpp"
#include "Index.hpp"
#include "FileStream.hpp"
// #include "FileStream.hpp"

#include <iostream>

namespace pocolog_cpp
{
Expand All @@ -17,7 +19,10 @@ class Stream
const StreamDescription &desc;
Index &index;

FileStream fileStream;
//FileStream fileStream;
std::ifstream fileStream;
char ReadBuffer[16777216]; //16MB
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid having objects that large (potentially) on the stack.
Also, did you also try making blocksize of pocolog_cpp::FileStream configurable?


Stream(const StreamDescription &desc, Index &index);

bool loadSampleHeader(std::streampos pos, pocolog_cpp::SampleHeaderData& header);
Expand Down Expand Up @@ -75,7 +80,7 @@ class Stream
return index.getNumSamples();
}

const FileStream& getFileStream() const
const std::ifstream& getFileStream() const
{
return fileStream;
}
Expand Down
2 changes: 1 addition & 1 deletion src/StreamDescription.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <memory>

#include "Format.hpp"
#include "FileStream.hpp"
// #include "FileStream.hpp"
#include <typelib/typemodel.hh>

namespace pocolog_cpp
Expand Down