Profiler: Port to Core::Stream

This commit is contained in:
Sam Atkins 2022-09-12 21:10:39 +01:00 committed by Tim Flynn
parent 183b054695
commit 68032d2724
Notes: sideshowbarker 2024-07-17 06:49:20 +09:00
2 changed files with 18 additions and 13 deletions

View file

@ -15,8 +15,8 @@
#include <AK/QuickSort.h>
#include <AK/RefPtr.h>
#include <AK/Try.h>
#include <LibCore/File.h>
#include <LibCore/MappedFile.h>
#include <LibCore/Stream.h>
#include <LibELF/Image.h>
#include <LibSymbolication/Symbolication.h>
#include <sys/stat.h>
@ -236,9 +236,9 @@ OwnPtr<Debug::DebugInfo> g_kernel_debug_info;
ErrorOr<NonnullOwnPtr<Profile>> 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)");

View file

@ -7,7 +7,7 @@
#include "SourceModel.h"
#include "Gradient.h"
#include "Profile.h"
#include <LibCore/File.h>
#include <LibCore/Stream.h>
#include <LibDebug/DebugInfo.h>
#include <LibGfx/Font/FontDatabase.h>
#include <LibSymbolication/Symbolication.h>
@ -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<void> {
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<u8, 1024> 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)