M module-audio/Audio/decoder/Decoder.cpp => module-audio/Audio/decoder/Decoder.cpp +4 -0
@@ 23,6 23,10 @@ namespace audio
return;
}
+ constexpr size_t streamBufferSize = 16 * 1024;
+ streamBuffer = std::make_unique<char[]>(streamBufferSize);
+ setvbuf(fd, streamBuffer.get(), _IOFBF, streamBufferSize);
+
std::fseek(fd, 0, SEEK_END);
fileSize = std::ftell(fd);
std::rewind(fd);
M module-audio/Audio/decoder/Decoder.hpp => module-audio/Audio/decoder/Decoder.hpp +1 -0
@@ 83,6 83,7 @@ namespace audio
uint32_t chanNumber = 0;
float position = 0;
std::FILE *fd = nullptr;
+ std::unique_ptr<char[]> streamBuffer;
uint32_t fileSize = 0;
std::string filePath;
M module-audio/Audio/encoder/Encoder.cpp => module-audio/Audio/encoder/Encoder.cpp +4 -1
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "Encoder.hpp"
@@ 19,6 19,9 @@ namespace audio
if (fd == NULL) {
return;
}
+ constexpr size_t streamBufferSize = 6;
+ streamBuffer = std::make_unique<char[]>(streamBufferSize);
+ setvbuf(fd, streamBuffer.get(), _IOFBF, streamBufferSize);
isInitialized = true;
}
M module-audio/Audio/encoder/Encoder.hpp => module-audio/Audio/encoder/Encoder.hpp +4 -4
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
@@ 40,8 40,9 @@ namespace audio
const Format format;
protected:
- float position = 0;
- std::FILE *fd = nullptr;
+ float position = 0;
+ std::FILE *fd = nullptr;
+ std::unique_ptr<char[]> streamBuffer;
uint32_t fileSize = 0;
std::string filePath;
@@ 49,4 50,3 @@ namespace audio
};
} // namespace audio
-
M module-db/Database/sqlite3vfs.cpp => module-db/Database/sqlite3vfs.cpp +6 -1
@@ 128,7 128,6 @@
#include <Utils.hpp>
#include <dirent.h>
-
/*
** Size of the write buffer used by journal files in bytes.
*/
@@ 152,6 151,7 @@ struct EcophoneFile
{
sqlite3_file base; /* Base class. Must be first. */
std::FILE *fd; /* File descriptor */
+ std::unique_ptr<char[]> streamBuffer;
char *aBuffer; /* Pointer to malloc'd buffer */
int nBuffer; /* Valid bytes of data in zBuffer */
@@ 317,6 317,7 @@ static int ecophoneClose(sqlite3_file *pFile)
EcophoneFile *p = (EcophoneFile *)pFile;
rc = ecophoneFlushBuffer(p);
sqlite3_free(p->aBuffer);
+ p->streamBuffer.reset();
std::fclose(p->fd);
return rc;
@@ 616,6 617,10 @@ static int ecophoneOpen(sqlite3_vfs *pVfs, /* VFS */
sqlite3_free(aBuf);
return SQLITE_CANTOPEN;
}
+ // set as 16 kB instead 64kB as it is allocated for each open db file
+ constexpr size_t streamBufferSize = 16 * 1024;
+ p->streamBuffer = std::make_unique<char[]>(streamBufferSize);
+ setvbuf(p->fd, p->streamBuffer.get(), _IOFBF, streamBufferSize);
p->aBuffer = aBuf;
if (pOutFlags) {
M module-services/service-desktop/endpoints/backup/BackupRestore.cpp => module-services/service-desktop/endpoints/backup/BackupRestore.cpp +20 -5
@@ 56,7 56,13 @@ static bool copyFile(const std::filesystem::path &from, const std::filesystem::p
std::unique_ptr<unsigned char[]> buffer = std::make_unique<unsigned char[]>(purefs::buffer::tar_buf);
size_t bytes;
- while ((bytes = std::fread(buffer.get(), 1, purefs::buffer::tar_buf, fromFp)) != 0) {
+ constexpr size_t streamBufferSize = 64 * 1024;
+ auto streamBufferFrom = std::make_unique<char[]>(streamBufferSize);
+ auto streamBufferTo = std::make_unique<char[]>(streamBufferSize);
+ setvbuf(fromFp, streamBufferFrom.get(), _IOFBF, streamBufferSize);
+ setvbuf(toFp, streamBufferTo.get(), _IOFBF, streamBufferSize);
+
+ while ((bytes = std::fread(buffer.get(), purefs::buffer::tar_buf, 1, fromFp)) != 0) {
if (std::fwrite(buffer.get(), 1, bytes, toFp) != bytes) {
return false;
}
@@ 220,14 226,16 @@ bool BackupRestore::PackUserFiles(std::filesystem::path &path)
LOG_INFO("opening tar file...");
int ret = mtar_open(&tarFile, tarFilePath.c_str(), "w");
-
if (ret != MTAR_ESUCCESS) {
LOG_ERROR("opening tar file failed, quitting...");
BackupRestore::RemoveBackupDir(path);
return false;
}
- auto buffer = std::make_unique<unsigned char[]>(purefs::buffer::tar_buf);
+ auto buffer = std::make_unique<unsigned char[]>(purefs::buffer::tar_buf);
+ constexpr size_t streamBufferSize = 64 * 1024;
+ auto streamBuffer = std::make_unique<char[]>(streamBufferSize);
+ setvbuf(tarFile.stream, streamBuffer.get(), _IOFBF, streamBufferSize);
std::error_code e;
for (auto &direntry : std::filesystem::directory_iterator(path)) {
@@ 356,7 364,10 @@ bool BackupRestore::UnpackBackupFile(const std::filesystem::path &tarFilePath)
return false;
}
- auto buffer = std::make_unique<unsigned char[]>(purefs::buffer::tar_buf);
+ auto buffer = std::make_unique<unsigned char[]>(purefs::buffer::tar_buf);
+ constexpr size_t streamBufferSize = 64 * 1024;
+ auto streamBuffer = std::make_unique<char[]>(streamBufferSize);
+ setvbuf(tarFile.stream, streamBuffer.get(), _IOFBF, streamBufferSize);
do {
ret = mtar_read_header(&tarFile, &tarHeader);
@@ 374,6 385,10 @@ bool BackupRestore::UnpackBackupFile(const std::filesystem::path &tarFilePath)
return false;
}
+ constexpr size_t streamBufferSize = 16 * 1024;
+ auto streamBuffer = std::make_unique<char[]>(streamBufferSize);
+ setvbuf(file, streamBuffer.get(), _IOFBF, streamBufferSize);
+
uint32_t loopcount = (tarHeader.size / purefs::buffer::tar_buf) + 1u;
uint32_t readsize = 0u;
@@ 394,7 409,7 @@ bool BackupRestore::UnpackBackupFile(const std::filesystem::path &tarFilePath)
return false;
}
- if (std::fwrite(buffer.get(), 1, readsize, file) != readsize) {
+ if (std::fwrite(buffer.get(), readsize, 1, file) != readsize) {
LOG_ERROR("writting file failed, quitting...");
mtar_close(&tarFile);
std::fclose(file);
M module-services/service-desktop/endpoints/filesystem/FileContext.cpp => module-services/service-desktop/endpoints/filesystem/FileContext.cpp +1 -1
@@ 17,7 17,7 @@ FileContext::FileContext(
throw std::runtime_error("File open error");
}
- constexpr size_t streamBufferSize = 16384;
+ constexpr size_t streamBufferSize = 64 * 1024;
streamBuffer = std::make_unique<char[]>(streamBufferSize);
setvbuf(file, streamBuffer.get(), _IOFBF, streamBufferSize);
M module-services/service-desktop/endpoints/include/endpoints/filesystem/FileContext.hpp => module-services/service-desktop/endpoints/include/endpoints/filesystem/FileContext.hpp +1 -1
@@ 39,11 39,11 @@ class FileContext
protected:
std::filesystem::path path{};
std::FILE *file{};
+ std::unique_ptr<char[]> streamBuffer;
std::size_t size{};
std::size_t offset{};
std::size_t chunkSize{};
CRC32 runningCrc32Digest;
- std::unique_ptr<char[]> streamBuffer;
};
class FileReadContext : public FileContext
M module-utils/log/Logger.cpp => module-utils/log/Logger.cpp +6 -2
@@ 68,8 68,8 @@ namespace Log
void Logger::init(Application app, size_t fileSize)
{
- application = std::move(app);
- maxFileSize = fileSize;
+ application = std::move(app);
+ maxFileSize = fileSize;
#if LOG_USE_COLOR == 1
enableColors(true);
#else
@@ 157,6 157,10 @@ namespace Log
status = -EIO;
}
+ constexpr size_t streamBufferSize = 64 * 1024;
+ auto streamBuffer = std::make_unique<char[]>(streamBufferSize);
+ logFile.rdbuf()->pubsetbuf(streamBuffer.get(), streamBufferSize);
+
if (firstDump) {
addFileHeader(logFile);
}