1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:27:45 +00:00

Profiler: Add source code view

This adds a new view mode to profiler which displays source lines and
samples that occured at those lines. This view can be opened via the
menu or by pressing CTRL-S.

It does this by mapping file names from DWARF to "/usr/src/serenity/..."
i.e. source code should be copied to /usr/src/serenity/Userland and
/usr/src/serenity/Kernel to be visible in this mode.

Currently *all* files contributing to the selected function are loaded
completely which could be a lot of data when dealing with lots of
inlined code.
This commit is contained in:
Stephan Unverwerth 2021-12-27 01:25:58 +01:00 committed by Andreas Kling
parent e6df1c9988
commit cf8427b7b4
6 changed files with 315 additions and 0 deletions

View file

@ -153,8 +153,21 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}
};
auto source_view = TRY(bottom_splitter->try_add<GUI::TableView>());
source_view->set_visible(false);
auto update_source_model = [&] {
if (source_view->is_visible() && !tree_view->selection().is_empty()) {
profile->set_source_index(tree_view->selection().first());
source_view->set_model(profile->source_model());
} else {
source_view->set_model(nullptr);
}
};
tree_view->on_selection_change = [&] {
update_disassembly_model();
update_source_model();
};
auto disassembly_action = GUI::Action::create_checkable("Show &Disassembly", { Mod_Ctrl, Key_D }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/x86.png").release_value_but_fixme_should_propagate_errors(), [&](auto& action) {
@ -162,6 +175,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
update_disassembly_model();
});
auto source_action = GUI::Action::create_checkable("Show &Source", { Mod_Ctrl, Key_S }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/x86.png").release_value_but_fixme_should_propagate_errors(), [&](auto& action) {
source_view->set_visible(action.is_checked());
update_source_model();
});
auto samples_tab = TRY(tab_widget->try_add_tab<GUI::Widget>("Samples"));
samples_tab->set_layout<GUI::VerticalBoxLayout>();
samples_tab->layout()->set_margins(4);
@ -255,11 +273,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
profile->set_show_percentages(action.is_checked());
tree_view->update();
disassembly_view->update();
source_view->update();
});
percent_action->set_checked(false);
TRY(view_menu->try_add_action(percent_action));
TRY(view_menu->try_add_action(disassembly_action));
TRY(view_menu->try_add_action(source_action));
auto help_menu = TRY(window->try_add_menu("&Help"));
TRY(help_menu->try_add_action(GUI::CommonActions::make_help_action([](auto&) {