mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:27:44 +00:00
UserspaceEmulator: Use Core::Stream
for writing profiling data
This looks like it should compile, but UserspaceEmulator is currently broken on any non-i686 platform anyways, so I can't test that.
This commit is contained in:
parent
173cc5e6e0
commit
9d7606b8de
4 changed files with 25 additions and 30 deletions
|
@ -9,7 +9,6 @@
|
||||||
#include "MmapRegion.h"
|
#include "MmapRegion.h"
|
||||||
#include "SimpleRegion.h"
|
#include "SimpleRegion.h"
|
||||||
#include "SoftCPU.h"
|
#include "SoftCPU.h"
|
||||||
#include <AK/FileStream.h>
|
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <AK/LexicalPath.h>
|
#include <AK/LexicalPath.h>
|
||||||
#include <AK/StringUtils.h>
|
#include <AK/StringUtils.h>
|
||||||
|
@ -501,7 +500,7 @@ void Emulator::dump_backtrace()
|
||||||
dump_backtrace(raw_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())
|
if (!is_in_region_of_interest())
|
||||||
return;
|
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.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.join(',', raw_backtrace());
|
||||||
builder.append("]}\n"sv);
|
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;
|
StringBuilder builder;
|
||||||
timeval tv {};
|
timeval tv {};
|
||||||
gettimeofday(&tv, nullptr);
|
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.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');
|
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)
|
DeprecatedString Emulator::create_instruction_line(FlatPtr address, X86::Instruction const& insn)
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include "RangeAllocator.h"
|
#include "RangeAllocator.h"
|
||||||
#include "Report.h"
|
#include "Report.h"
|
||||||
#include "SoftMMU.h"
|
#include "SoftMMU.h"
|
||||||
#include <AK/FileStream.h>
|
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
#include <LibCore/MappedFile.h>
|
#include <LibCore/MappedFile.h>
|
||||||
#include <LibDebug/DebugInfo.h>
|
#include <LibDebug/DebugInfo.h>
|
||||||
|
@ -33,7 +32,7 @@ public:
|
||||||
|
|
||||||
Emulator(DeprecatedString const& executable_path, Vector<StringView> const& arguments, Vector<DeprecatedString> const& environment);
|
Emulator(DeprecatedString const& executable_path, Vector<StringView> const& arguments, Vector<DeprecatedString> const& environment);
|
||||||
|
|
||||||
void set_profiling_details(bool should_dump_profile, size_t instruction_interval, OutputFileStream* profile_stream, NonnullOwnPtrVector<DeprecatedString>* profiler_strings, Vector<int>* profiler_string_id_map)
|
void set_profiling_details(bool should_dump_profile, size_t instruction_interval, Core::Stream::Stream* profile_stream, NonnullOwnPtrVector<DeprecatedString>* profiler_strings, Vector<int>* profiler_string_id_map)
|
||||||
{
|
{
|
||||||
m_is_profiling = should_dump_profile;
|
m_is_profiling = should_dump_profile;
|
||||||
m_profile_instruction_interval = instruction_interval;
|
m_profile_instruction_interval = instruction_interval;
|
||||||
|
@ -47,7 +46,7 @@ public:
|
||||||
m_is_in_region_of_interest = value;
|
m_is_in_region_of_interest = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputFileStream& profile_stream() { return *m_profile_stream; }
|
Core::Stream::Stream& profile_stream() { return *m_profile_stream; }
|
||||||
NonnullOwnPtrVector<DeprecatedString>& profiler_strings() { return *m_profiler_strings; }
|
NonnullOwnPtrVector<DeprecatedString>& profiler_strings() { return *m_profiler_strings; }
|
||||||
Vector<int>& profiler_string_id_map() { return *m_profiler_string_id_map; }
|
Vector<int>& profiler_string_id_map() { return *m_profiler_string_id_map; }
|
||||||
|
|
||||||
|
@ -140,8 +139,8 @@ private:
|
||||||
|
|
||||||
void send_signal(int);
|
void send_signal(int);
|
||||||
|
|
||||||
void emit_profile_sample(AK::OutputStream&);
|
void emit_profile_sample(Core::Stream::Stream&);
|
||||||
void emit_profile_event(AK::OutputStream&, StringView event_name, DeprecatedString const& contents);
|
void emit_profile_event(Core::Stream::Stream&, StringView event_name, DeprecatedString const& contents);
|
||||||
|
|
||||||
int virt$accept4(FlatPtr);
|
int virt$accept4(FlatPtr);
|
||||||
u32 virt$allocate_tls(FlatPtr, size_t);
|
u32 virt$allocate_tls(FlatPtr, size_t);
|
||||||
|
@ -296,7 +295,7 @@ private:
|
||||||
|
|
||||||
RangeAllocator m_range_allocator;
|
RangeAllocator m_range_allocator;
|
||||||
|
|
||||||
OutputFileStream* m_profile_stream { nullptr };
|
Core::Stream::Stream* m_profile_stream { nullptr };
|
||||||
Vector<int>* m_profiler_string_id_map { nullptr };
|
Vector<int>* m_profiler_string_id_map { nullptr };
|
||||||
NonnullOwnPtrVector<DeprecatedString>* m_profiler_strings { nullptr };
|
NonnullOwnPtrVector<DeprecatedString>* m_profiler_strings { nullptr };
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#include "SimpleRegion.h"
|
#include "SimpleRegion.h"
|
||||||
#include "SoftCPU.h"
|
#include "SoftCPU.h"
|
||||||
#include <AK/Debug.h>
|
#include <AK/Debug.h>
|
||||||
#include <AK/FileStream.h>
|
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <Kernel/API/SyscallString.h>
|
#include <Kernel/API/SyscallString.h>
|
||||||
#include <alloca.h>
|
#include <alloca.h>
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Emulator.h"
|
#include "Emulator.h"
|
||||||
#include <AK/FileStream.h>
|
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <AK/LexicalPath.h>
|
#include <AK/LexicalPath.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
|
@ -24,7 +23,6 @@ int main(int argc, char** argv, char** env)
|
||||||
Vector<StringView> arguments;
|
Vector<StringView> arguments;
|
||||||
bool pause_on_startup { false };
|
bool pause_on_startup { false };
|
||||||
DeprecatedString profile_dump_path;
|
DeprecatedString profile_dump_path;
|
||||||
FILE* profile_output_file { nullptr };
|
|
||||||
bool enable_roi_mode { false };
|
bool enable_roi_mode { false };
|
||||||
bool dump_profile { false };
|
bool dump_profile { false };
|
||||||
unsigned profile_instruction_interval { 0 };
|
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())
|
if (dump_profile && profile_dump_path.is_empty())
|
||||||
profile_dump_path = DeprecatedString::formatted("{}.{}.profile", LexicalPath(executable_path).basename(), getpid());
|
profile_dump_path = DeprecatedString::formatted("{}.{}.profile", LexicalPath(executable_path).basename(), getpid());
|
||||||
|
|
||||||
OwnPtr<OutputFileStream> profile_stream;
|
OwnPtr<Core::Stream::Stream> profile_stream;
|
||||||
OwnPtr<NonnullOwnPtrVector<DeprecatedString>> profile_strings;
|
OwnPtr<NonnullOwnPtrVector<DeprecatedString>> profile_strings;
|
||||||
OwnPtr<Vector<int>> profile_string_id_map;
|
OwnPtr<Vector<int>> profile_string_id_map;
|
||||||
|
|
||||||
if (dump_profile) {
|
if (dump_profile) {
|
||||||
profile_output_file = fopen(profile_dump_path.characters(), "w+");
|
auto profile_stream_or_error = Core::Stream::File::open(profile_dump_path, Core::Stream::OpenMode::Write);
|
||||||
if (profile_output_file == nullptr) {
|
if (profile_stream_or_error.is_error()) {
|
||||||
char const* error_string = strerror(errno);
|
warnln("Failed to open '{}' for writing: {}", profile_dump_path, profile_stream_or_error.error());
|
||||||
warnln("Failed to open '{}' for writing: {}", profile_dump_path, error_string);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
profile_stream = make<OutputFileStream>(profile_output_file);
|
profile_stream = profile_stream_or_error.release_value();
|
||||||
profile_strings = make<NonnullOwnPtrVector<DeprecatedString>>();
|
profile_strings = make<NonnullOwnPtrVector<DeprecatedString>>();
|
||||||
profile_string_id_map = make<Vector<int>>();
|
profile_string_id_map = make<Vector<int>>();
|
||||||
|
|
||||||
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 {};
|
timeval tv {};
|
||||||
gettimeofday(&tv, nullptr);
|
gettimeofday(&tv, nullptr);
|
||||||
profile_stream->write_or_error(
|
profile_stream->write_entire_buffer(
|
||||||
DeprecatedString::formatted(
|
DeprecatedString::formatted(
|
||||||
R"~({{"type": "process_create", "parent_pid": 1, "executable": "{}", "pid": {}, "tid": {}, "timestamp": {}, "lost_samples": 0, "stack": []}})~",
|
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)
|
executable_path, getpid(), gettid(), tv.tv_sec * 1000 + tv.tv_usec / 1000)
|
||||||
.bytes());
|
.bytes())
|
||||||
|
.release_value_but_fixme_should_propagate_errors();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<DeprecatedString> environment;
|
Vector<DeprecatedString> environment;
|
||||||
|
@ -116,13 +114,13 @@ int main(int argc, char** argv, char** env)
|
||||||
rc = emulator.exec();
|
rc = emulator.exec();
|
||||||
|
|
||||||
if (dump_profile) {
|
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()) {
|
if (emulator.profiler_strings().size()) {
|
||||||
for (size_t i = 0; i < emulator.profiler_strings().size() - 1; ++i)
|
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_entire_buffer(DeprecatedString::formatted("\"{}\", ", emulator.profiler_strings().at(i)).bytes()).release_value_but_fixme_should_propagate_errors();
|
||||||
emulator.profile_stream().write_or_error(DeprecatedString::formatted("\"{}\"", emulator.profiler_strings().last()).bytes());
|
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;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue