diff --git a/Userland/DevTools/UserspaceEmulator/Emulator.cpp b/Userland/DevTools/UserspaceEmulator/Emulator.cpp index 7c0cb551bb..a094621550 100644 --- a/Userland/DevTools/UserspaceEmulator/Emulator.cpp +++ b/Userland/DevTools/UserspaceEmulator/Emulator.cpp @@ -9,7 +9,6 @@ #include "MmapRegion.h" #include "SimpleRegion.h" #include "SoftCPU.h" -#include #include #include #include @@ -501,7 +500,7 @@ void Emulator::dump_backtrace() dump_backtrace(raw_backtrace()); } -void Emulator::emit_profile_sample(AK::OutputStream& output) +void Emulator::emit_profile_sample(Core::Stream::Stream& output) { if (!is_in_region_of_interest()) return; @@ -511,17 +510,17 @@ void Emulator::emit_profile_sample(AK::OutputStream& output) builder.appendff(R"~(, {{"type": "sample", "pid": {}, "tid": {}, "timestamp": {}, "lost_samples": 0, "stack": [)~", getpid(), gettid(), tv.tv_sec * 1000 + tv.tv_usec / 1000); builder.join(',', raw_backtrace()); builder.append("]}\n"sv); - output.write_or_error(builder.string_view().bytes()); + output.write_entire_buffer(builder.string_view().bytes()).release_value_but_fixme_should_propagate_errors(); } -void Emulator::emit_profile_event(AK::OutputStream& output, StringView event_name, DeprecatedString const& contents) +void Emulator::emit_profile_event(Core::Stream::Stream& output, StringView event_name, DeprecatedString const& contents) { StringBuilder builder; timeval tv {}; gettimeofday(&tv, nullptr); builder.appendff(R"~(, {{"type": "{}", "pid": {}, "tid": {}, "timestamp": {}, "lost_samples": 0, "stack": [], {}}})~", event_name, getpid(), gettid(), tv.tv_sec * 1000 + tv.tv_usec / 1000, contents); builder.append('\n'); - output.write_or_error(builder.string_view().bytes()); + output.write_entire_buffer(builder.string_view().bytes()).release_value_but_fixme_should_propagate_errors(); } DeprecatedString Emulator::create_instruction_line(FlatPtr address, X86::Instruction const& insn) diff --git a/Userland/DevTools/UserspaceEmulator/Emulator.h b/Userland/DevTools/UserspaceEmulator/Emulator.h index 3ba4225ec2..4bb731a70e 100644 --- a/Userland/DevTools/UserspaceEmulator/Emulator.h +++ b/Userland/DevTools/UserspaceEmulator/Emulator.h @@ -11,7 +11,6 @@ #include "RangeAllocator.h" #include "Report.h" #include "SoftMMU.h" -#include #include #include #include @@ -33,7 +32,7 @@ public: Emulator(DeprecatedString const& executable_path, Vector const& arguments, Vector const& environment); - void set_profiling_details(bool should_dump_profile, size_t instruction_interval, OutputFileStream* profile_stream, NonnullOwnPtrVector* profiler_strings, Vector* profiler_string_id_map) + void set_profiling_details(bool should_dump_profile, size_t instruction_interval, Core::Stream::Stream* profile_stream, NonnullOwnPtrVector* profiler_strings, Vector* profiler_string_id_map) { m_is_profiling = should_dump_profile; m_profile_instruction_interval = instruction_interval; @@ -47,7 +46,7 @@ public: m_is_in_region_of_interest = value; } - OutputFileStream& profile_stream() { return *m_profile_stream; } + Core::Stream::Stream& profile_stream() { return *m_profile_stream; } NonnullOwnPtrVector& profiler_strings() { return *m_profiler_strings; } Vector& profiler_string_id_map() { return *m_profiler_string_id_map; } @@ -140,8 +139,8 @@ private: void send_signal(int); - void emit_profile_sample(AK::OutputStream&); - void emit_profile_event(AK::OutputStream&, StringView event_name, DeprecatedString const& contents); + void emit_profile_sample(Core::Stream::Stream&); + void emit_profile_event(Core::Stream::Stream&, StringView event_name, DeprecatedString const& contents); int virt$accept4(FlatPtr); u32 virt$allocate_tls(FlatPtr, size_t); @@ -296,7 +295,7 @@ private: RangeAllocator m_range_allocator; - OutputFileStream* m_profile_stream { nullptr }; + Core::Stream::Stream* m_profile_stream { nullptr }; Vector* m_profiler_string_id_map { nullptr }; NonnullOwnPtrVector* m_profiler_strings { nullptr }; diff --git a/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp b/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp index f4dbe20730..93909afc52 100644 --- a/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp +++ b/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp @@ -10,7 +10,6 @@ #include "SimpleRegion.h" #include "SoftCPU.h" #include -#include #include #include #include diff --git a/Userland/DevTools/UserspaceEmulator/main.cpp b/Userland/DevTools/UserspaceEmulator/main.cpp index f62b1f2b2a..181699e0ce 100644 --- a/Userland/DevTools/UserspaceEmulator/main.cpp +++ b/Userland/DevTools/UserspaceEmulator/main.cpp @@ -5,7 +5,6 @@ */ #include "Emulator.h" -#include #include #include #include @@ -24,7 +23,6 @@ int main(int argc, char** argv, char** env) Vector arguments; bool pause_on_startup { false }; DeprecatedString profile_dump_path; - FILE* profile_output_file { nullptr }; bool enable_roi_mode { false }; bool dump_profile { false }; unsigned profile_instruction_interval { 0 }; @@ -58,29 +56,29 @@ int main(int argc, char** argv, char** env) if (dump_profile && profile_dump_path.is_empty()) profile_dump_path = DeprecatedString::formatted("{}.{}.profile", LexicalPath(executable_path).basename(), getpid()); - OwnPtr profile_stream; + OwnPtr profile_stream; OwnPtr> profile_strings; OwnPtr> profile_string_id_map; if (dump_profile) { - profile_output_file = fopen(profile_dump_path.characters(), "w+"); - if (profile_output_file == nullptr) { - char const* error_string = strerror(errno); - warnln("Failed to open '{}' for writing: {}", profile_dump_path, error_string); + auto profile_stream_or_error = Core::Stream::File::open(profile_dump_path, Core::Stream::OpenMode::Write); + if (profile_stream_or_error.is_error()) { + warnln("Failed to open '{}' for writing: {}", profile_dump_path, profile_stream_or_error.error()); return 1; } - profile_stream = make(profile_output_file); + profile_stream = profile_stream_or_error.release_value(); profile_strings = make>(); profile_string_id_map = make>(); - profile_stream->write_or_error(R"({"events":[)"sv.bytes()); + profile_stream->write_entire_buffer(R"({"events":[)"sv.bytes()).release_value_but_fixme_should_propagate_errors(); timeval tv {}; gettimeofday(&tv, nullptr); - profile_stream->write_or_error( - DeprecatedString::formatted( - R"~({{"type": "process_create", "parent_pid": 1, "executable": "{}", "pid": {}, "tid": {}, "timestamp": {}, "lost_samples": 0, "stack": []}})~", - executable_path, getpid(), gettid(), tv.tv_sec * 1000 + tv.tv_usec / 1000) - .bytes()); + profile_stream->write_entire_buffer( + DeprecatedString::formatted( + R"~({{"type": "process_create", "parent_pid": 1, "executable": "{}", "pid": {}, "tid": {}, "timestamp": {}, "lost_samples": 0, "stack": []}})~", + executable_path, getpid(), gettid(), tv.tv_sec * 1000 + tv.tv_usec / 1000) + .bytes()) + .release_value_but_fixme_should_propagate_errors(); } Vector environment; @@ -116,13 +114,13 @@ int main(int argc, char** argv, char** env) rc = emulator.exec(); if (dump_profile) { - emulator.profile_stream().write_or_error("], \"strings\": ["sv.bytes()); + emulator.profile_stream().write_entire_buffer("], \"strings\": ["sv.bytes()).release_value_but_fixme_should_propagate_errors(); if (emulator.profiler_strings().size()) { for (size_t i = 0; i < emulator.profiler_strings().size() - 1; ++i) - emulator.profile_stream().write_or_error(DeprecatedString::formatted("\"{}\", ", emulator.profiler_strings().at(i)).bytes()); - emulator.profile_stream().write_or_error(DeprecatedString::formatted("\"{}\"", emulator.profiler_strings().last()).bytes()); + emulator.profile_stream().write_entire_buffer(DeprecatedString::formatted("\"{}\", ", emulator.profiler_strings().at(i)).bytes()).release_value_but_fixme_should_propagate_errors(); + emulator.profile_stream().write_entire_buffer(DeprecatedString::formatted("\"{}\"", emulator.profiler_strings().last()).bytes()).release_value_but_fixme_should_propagate_errors(); } - emulator.profile_stream().write_or_error("]}"sv.bytes()); + emulator.profile_stream().write_entire_buffer("]}"sv.bytes()).release_value_but_fixme_should_propagate_errors(); } return rc; }