重构项目,现支持多线程操作
This commit is contained in:
87
src/main.cpp
Normal file
87
src/main.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
#include "expkg.h"
|
||||
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 2) {
|
||||
std::cout << "Usage: expkg path/to/file.pkg|file.tex [output_dir]" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::filesystem::path inputPath = argv[1];
|
||||
std::filesystem::path outDir = argc >= 3 ? argv[2] : "out";
|
||||
|
||||
PKG::ExtractPipeline pipeline;
|
||||
PKG::ExtractStats stats;
|
||||
auto result = pipeline.Run(inputPath, outDir, /*showProgress=*/true, &stats);
|
||||
|
||||
std::cout << std::endl; // 进度条换行后空一行
|
||||
|
||||
size_t total = stats.totalEntries.load();
|
||||
size_t ok = stats.succeeded.load();
|
||||
size_t fail = stats.failed.load();
|
||||
uint64_t outBytes = stats.totalOutputBytes.load();
|
||||
|
||||
// 完全失败(没有任何条目被处理):只打印错误,不显示统计面板
|
||||
if (!result && ok == 0 && fail == 0) {
|
||||
std::cerr << "错误: " << result.error.message << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 成功或部分成功:打印结果与统计
|
||||
if (result)
|
||||
std::cout << "提取完成" << std::endl;
|
||||
else
|
||||
std::cerr << "错误: " << result.error.message << std::endl;
|
||||
|
||||
double elapsed = stats.ElapsedSeconds();
|
||||
|
||||
std::cout << "──────────────────────────────" << std::endl;
|
||||
|
||||
// 文件总数
|
||||
std::cout << "文件总数: " << ok << " 个";
|
||||
if (fail > 0)
|
||||
std::cout << " (失败 " << fail << " 个)";
|
||||
if (total > ok + fail)
|
||||
std::cout << " / 共 " << total << " 个";
|
||||
std::cout << std::endl;
|
||||
|
||||
// 输出大小
|
||||
std::cout << "输出大小: " << PKG::FormatBytes(outBytes) << std::endl;
|
||||
|
||||
// 耗时与吞吐(仅在时间有效时打印)
|
||||
if (elapsed >= 0) {
|
||||
std::cout << "耗时: " << std::fixed << std::setprecision(2) << elapsed << " 秒";
|
||||
if (elapsed > 0 && ok > 0)
|
||||
std::cout << " (" << std::setprecision(1) << (ok / elapsed) << " 个/秒)";
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// 输入 → 输出对比(仅在输入大小有效时打印)
|
||||
if (stats.inputFileSize > 0 && stats.inputFileSize < 1ULL << 40) {
|
||||
std::cout << "输入文件: " << PKG::FormatBytes(stats.inputFileSize);
|
||||
if (outBytes > 0) {
|
||||
double ratio = static_cast<double>(outBytes) / stats.inputFileSize;
|
||||
std::cout << " → 输出 " << PKG::FormatBytes(outBytes)
|
||||
<< " (×" << std::setprecision(2) << ratio << ")";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// 各格式分布
|
||||
if (!stats.formatCounts.empty()) {
|
||||
std::cout << "格式分布:" << std::endl;
|
||||
for (const auto &[ext, count] : stats.formatCounts)
|
||||
std::cout << " ." << ext << " " << count << " 个" << std::endl;
|
||||
}
|
||||
|
||||
// 内存占用(峰值)
|
||||
size_t peakRss = PKG::GetPeakRssBytes();
|
||||
if (peakRss > 0)
|
||||
std::cout << "内存占用: " << PKG::FormatBytes(peakRss) << " (峰值)" << std::endl;
|
||||
|
||||
std::cout << "──────────────────────────────" << std::endl;
|
||||
|
||||
return result ? 0 : 1;
|
||||
}
|
||||
Reference in New Issue
Block a user