diff --git a/Userland/DevTools/Profiler/Profile.cpp b/Userland/DevTools/Profiler/Profile.cpp index d4acc406d8..f9f7c8c369 100644 --- a/Userland/DevTools/Profiler/Profile.cpp +++ b/Userland/DevTools/Profiler/Profile.cpp @@ -15,8 +15,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -236,9 +236,9 @@ OwnPtr g_kernel_debug_info; ErrorOr> Profile::load_from_perfcore_file(StringView path) { - auto file = TRY(Core::File::open(path, Core::OpenMode::ReadOnly)); + auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read)); - auto json = JsonValue::from_string(file->read_all()); + auto json = JsonValue::from_string(TRY(file->read_all())); if (json.is_error() || !json.value().is_object()) return Error::from_string_literal("Invalid perfcore format (not a JSON object)"); diff --git a/Userland/DevTools/Profiler/SourceModel.cpp b/Userland/DevTools/Profiler/SourceModel.cpp index 912d4a2ce2..29f374de65 100644 --- a/Userland/DevTools/Profiler/SourceModel.cpp +++ b/Userland/DevTools/Profiler/SourceModel.cpp @@ -7,7 +7,7 @@ #include "SourceModel.h" #include "Gradient.h" #include "Profile.h" -#include +#include #include #include #include @@ -24,21 +24,26 @@ public: static constexpr StringView source_root_path = "/usr/src/serenity/"sv; -public: SourceFile(StringView filename) { String source_file_name = filename.replace("../../"sv, source_root_path, ReplaceMode::FirstOnly); - auto maybe_file = Core::File::open(source_file_name, Core::OpenMode::ReadOnly); - if (maybe_file.is_error()) { - dbgln("Could not map source file \"{}\". Tried {}. {} (errno={})", filename, source_file_name, maybe_file.error().string_literal(), maybe_file.error().code()); + auto try_read_lines = [&]() -> ErrorOr { + auto unbuffered_file = TRY(Core::Stream::File::open(source_file_name, Core::Stream::OpenMode::Read)); + auto file = TRY(Core::Stream::BufferedFile::create(move(unbuffered_file))); + + Array buffer; + while (!file->is_eof()) + m_lines.append({ TRY(file->read_line(buffer)), 0 }); + + return {}; + }; + + auto maybe_error = try_read_lines(); + if (maybe_error.is_error()) { + dbgln("Could not map source file \"{}\". Tried {}. {} (errno={})", filename, source_file_name, maybe_error.error().string_literal(), maybe_error.error().code()); return; } - - auto file = maybe_file.value(); - - while (!file->eof()) - m_lines.append({ file->read_line(1024), 0 }); } void try_add_samples(size_t line, size_t samples)