Add pack runtime profiling hooks
Some checks failed
build / Windows Build (push) Has been cancelled

This commit is contained in:
server
2026-04-15 16:22:10 +02:00
parent ef7cdf2809
commit ba6af8115b
12 changed files with 696 additions and 3 deletions

View File

@@ -1,5 +1,8 @@
#include "Pack.h"
#include "PackProfile.h"
#include "EterLib/BufferPool.h"
#include <chrono>
#include <zstd.h>
static thread_local ZSTD_DCtx* g_zstdDCtx = nullptr;
@@ -20,6 +23,7 @@ void CPack::DecryptData(uint8_t* data, size_t len, const uint8_t* nonce)
bool CPack::Load(const std::string& path)
{
m_source_path = path;
std::error_code ec;
m_file.map(path, ec);
@@ -68,7 +72,15 @@ bool CPack::GetFileWithPool(const TPackFileEntry& entry, TPackFile& result, CBuf
switch (entry.encryption)
{
case 0: {
const auto decompressStart = std::chrono::steady_clock::now();
size_t decompressed_size = ZSTD_decompressDCtx(dctx, result.data(), result.size(), m_file.data() + offset, entry.compressed_size);
RecordPackProfileStage(
"pck",
"zstd_decompress",
entry.compressed_size,
ZSTD_isError(decompressed_size) ? 0 : decompressed_size,
static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::steady_clock::now() - decompressStart).count()));
if (decompressed_size != entry.file_size) {
return false;
}
@@ -83,9 +95,25 @@ bool CPack::GetFileWithPool(const TPackFileEntry& entry, TPackFile& result, CBuf
memcpy(compressed_data.data(), m_file.data() + offset, entry.compressed_size);
const auto decryptStart = std::chrono::steady_clock::now();
DecryptData(compressed_data.data(), entry.compressed_size, entry.nonce);
RecordPackProfileStage(
"pck",
"xchacha20_decrypt",
entry.compressed_size,
entry.compressed_size,
static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::steady_clock::now() - decryptStart).count()));
const auto decompressStart = std::chrono::steady_clock::now();
size_t decompressed_size = ZSTD_decompressDCtx(dctx, result.data(), result.size(), compressed_data.data(), compressed_data.size());
RecordPackProfileStage(
"pck",
"zstd_decompress",
compressed_data.size(),
ZSTD_isError(decompressed_size) ? 0 : decompressed_size,
static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::steady_clock::now() - decompressStart).count()));
if (pPool) {
pPool->Release(std::move(compressed_data));