4
4
#include < array>
5
5
#include < cassert>
6
6
#include < charconv>
7
- #include < deque>
8
7
#include < execution>
9
8
#include < filesystem>
10
- #include < fstream>
11
- #include < iostream>
12
9
#include < mutex>
13
10
#include < ranges>
14
11
#include < string>
@@ -26,28 +23,6 @@ using namespace ev;
26
23
namespace py = pybind11;
27
24
namespace fs = std::filesystem;
28
25
29
- // Read a whole file in at once
30
- std::string slurp (const fs::path &Path) {
31
- // Open first to help ensure that we get the correct file size
32
- std::ifstream File (Path);
33
-
34
- std::string Result;
35
- Result.resize (fs::file_size (Path));
36
-
37
- File.read (Result.data (), Result.size ());
38
- // In case there's anything left over
39
- while (File) {
40
- static constexpr std::size_t BufSize = 1024 ;
41
- std::array<char , BufSize> Buffer;
42
- File.read (Buffer.data (), Buffer.size ());
43
- Result.insert (Result.end (), Buffer.begin (), Buffer.end ());
44
- }
45
-
46
- Result.erase (Result.find (' \0 ' ), Result.size ());
47
-
48
- return Result;
49
- }
50
-
51
26
static constexpr std::string_view RegionNameEv =
52
27
R"( "event_id": "ProcessDag", "name": ")" ;
53
28
static const std::boyer_moore_horspool_searcher
@@ -331,7 +306,8 @@ void ev::defParse(py::module &Mod) {
331
306
}
332
307
auto Logs = std::make_shared<ev::Logs>();
333
308
Logs->LogFile = std::move (Path);
334
- Logs->RawLog = ::slurp (Logs->LogFile );
309
+ Logs->MMap = mio::mmap_source (Logs->LogFile .string ());
310
+ Logs->RawLog = std::string_view (Logs->MMap .data (), Logs->MMap .size ());
335
311
const std::string_view File = Logs->RawLog ;
336
312
337
313
const std::vector<BenchmarkRegion> BenchmarkSections =
@@ -363,7 +339,8 @@ void ev::defParse(py::module &Mod) {
363
339
std::string_view BenchmarkName) {
364
340
auto Logs = std::make_shared<ev::Logs>();
365
341
Logs->LogFile = std::move (Path);
366
- Logs->RawLog = ::slurp (Logs->LogFile );
342
+ Logs->MMap = mio::mmap_source (Logs->LogFile .string ());
343
+ Logs->RawLog = std::string_view (Logs->MMap .data (), Logs->MMap .size ());
367
344
const std::string_view File = Logs->RawLog ;
368
345
369
346
Logs->Benchmarks .push_back (
0 commit comments