This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
#include "PackManager.h"
|
||||
#include "PackProfile.h"
|
||||
#include "EterLib/BufferPool.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
@@ -27,8 +30,16 @@ bool CPackManager::AddPack(const std::string& path)
|
||||
if (packPath.extension() == ".m2p")
|
||||
{
|
||||
std::shared_ptr<CM2Pack> pack = std::make_shared<CM2Pack>();
|
||||
const auto loadStart = std::chrono::steady_clock::now();
|
||||
if (!pack->Load(path))
|
||||
{
|
||||
RecordPackProfileMount(
|
||||
"m2p",
|
||||
path,
|
||||
false,
|
||||
0,
|
||||
static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::steady_clock::now() - loadStart).count()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -38,14 +49,29 @@ bool CPackManager::AddPack(const std::string& path)
|
||||
{
|
||||
m_m2_entries[entry.path] = std::make_pair(pack, entry);
|
||||
}
|
||||
RecordPackProfileMount(
|
||||
"m2p",
|
||||
path,
|
||||
true,
|
||||
index.size(),
|
||||
static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::steady_clock::now() - loadStart).count()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<CPack> pack = std::make_shared<CPack>();
|
||||
const auto loadStart = std::chrono::steady_clock::now();
|
||||
|
||||
if (!pack->Load(path))
|
||||
{
|
||||
RecordPackProfileMount(
|
||||
"pck",
|
||||
path,
|
||||
false,
|
||||
0,
|
||||
static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::steady_clock::now() - loadStart).count()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -55,6 +81,13 @@ bool CPackManager::AddPack(const std::string& path)
|
||||
{
|
||||
m_entries[entry.file_name] = std::make_pair(pack, entry);
|
||||
}
|
||||
RecordPackProfileMount(
|
||||
"pck",
|
||||
path,
|
||||
true,
|
||||
index.size(),
|
||||
static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::steady_clock::now() - loadStart).count()));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -73,16 +106,37 @@ bool CPackManager::GetFileWithPool(std::string_view path, TPackFile& result, CBu
|
||||
if (m_load_from_pack) {
|
||||
auto m2it = m_m2_entries.find(buf);
|
||||
if (m2it != m_m2_entries.end()) {
|
||||
return m2it->second.first->GetFileWithPool(m2it->second.second, result, pPool);
|
||||
const auto loadStart = std::chrono::steady_clock::now();
|
||||
const bool ok = m2it->second.first->GetFileWithPool(m2it->second.second, result, pPool);
|
||||
RecordPackProfileLoad(
|
||||
"m2p",
|
||||
m2it->second.first->GetSourcePath(),
|
||||
buf,
|
||||
ok,
|
||||
ok ? result.size() : 0,
|
||||
static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::steady_clock::now() - loadStart).count()));
|
||||
return ok;
|
||||
}
|
||||
|
||||
auto it = m_entries.find(buf);
|
||||
if (it != m_entries.end()) {
|
||||
return it->second.first->GetFileWithPool(it->second.second, result, pPool);
|
||||
const auto loadStart = std::chrono::steady_clock::now();
|
||||
const bool ok = it->second.first->GetFileWithPool(it->second.second, result, pPool);
|
||||
RecordPackProfileLoad(
|
||||
"pck",
|
||||
it->second.first->GetSourcePath(),
|
||||
buf,
|
||||
ok,
|
||||
ok ? result.size() : 0,
|
||||
static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::steady_clock::now() - loadStart).count()));
|
||||
return ok;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to disk (for files not in packs, like bgm folder)
|
||||
const auto loadStart = std::chrono::steady_clock::now();
|
||||
std::ifstream ifs(buf, std::ios::binary);
|
||||
if (ifs.is_open()) {
|
||||
ifs.seekg(0, std::ios::end);
|
||||
@@ -97,10 +151,27 @@ bool CPackManager::GetFileWithPool(std::string_view path, TPackFile& result, CBu
|
||||
}
|
||||
|
||||
if (ifs.read((char*)result.data(), size)) {
|
||||
RecordPackProfileLoad(
|
||||
"disk",
|
||||
"<disk>",
|
||||
buf,
|
||||
true,
|
||||
result.size(),
|
||||
static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::steady_clock::now() - loadStart).count()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
RecordPackProfileLoad(
|
||||
"disk",
|
||||
"<disk>",
|
||||
buf,
|
||||
false,
|
||||
0,
|
||||
static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::steady_clock::now() - loadStart).count()));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user