2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2019-12-12 22:01:06 +01:00
|
|
|
#include "Profile.h"
|
2019-12-14 18:44:29 +01:00
|
|
|
#include "ProfileTimelineWidget.h"
|
2020-02-06 20:33:02 +01:00
|
|
|
#include <LibGUI/Action.h>
|
|
|
|
#include <LibGUI/Application.h>
|
|
|
|
#include <LibGUI/BoxLayout.h>
|
|
|
|
#include <LibGUI/Menu.h>
|
|
|
|
#include <LibGUI/MenuBar.h>
|
2020-02-16 09:17:49 +01:00
|
|
|
#include <LibGUI/Model.h>
|
2020-04-12 10:57:44 +02:00
|
|
|
#include <LibGUI/Splitter.h>
|
2020-04-11 18:46:11 +02:00
|
|
|
#include <LibGUI/TableView.h>
|
2020-02-06 20:33:02 +01:00
|
|
|
#include <LibGUI/TreeView.h>
|
|
|
|
#include <LibGUI/Window.h>
|
2019-12-12 22:01:06 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
if (argc != 2) {
|
|
|
|
printf("usage: %s <profile-file>\n", argv[0]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-12-13 23:38:17 +01:00
|
|
|
const char* path = argv[1];
|
2020-02-22 10:05:03 +01:00
|
|
|
auto profile = Profile::load_from_perfcore_file(path);
|
2019-12-13 23:38:17 +01:00
|
|
|
|
2019-12-12 22:01:06 +01:00
|
|
|
if (!profile) {
|
2019-12-13 23:38:17 +01:00
|
|
|
fprintf(stderr, "Unable to load profile '%s'\n", path);
|
2019-12-12 22:01:06 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
GUI::Application app(argc, argv);
|
2019-12-12 22:01:06 +01:00
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
auto window = GUI::Window::construct();
|
2019-12-12 22:01:06 +01:00
|
|
|
window->set_title("ProfileViewer");
|
|
|
|
window->set_rect(100, 100, 800, 600);
|
|
|
|
|
2020-03-04 09:46:23 +01:00
|
|
|
auto& main_widget = window->set_main_widget<GUI::Widget>();
|
|
|
|
main_widget.set_fill_with_background_color(true);
|
|
|
|
main_widget.set_layout<GUI::VerticalBoxLayout>();
|
2019-12-14 18:44:29 +01:00
|
|
|
|
2020-03-04 19:07:55 +01:00
|
|
|
main_widget.add<ProfileTimelineWidget>(*profile);
|
2019-12-14 18:44:29 +01:00
|
|
|
|
2020-04-12 10:57:44 +02:00
|
|
|
auto& bottom_splitter = main_widget.add<GUI::VerticalSplitter>();
|
2020-04-11 18:46:11 +02:00
|
|
|
|
2020-04-12 10:57:44 +02:00
|
|
|
auto& tree_view = bottom_splitter.add<GUI::TreeView>();
|
2020-03-04 19:07:55 +01:00
|
|
|
tree_view.set_headers_visible(true);
|
|
|
|
tree_view.set_size_columns_to_fit_content(true);
|
|
|
|
tree_view.set_model(profile->model());
|
2019-12-12 22:01:06 +01:00
|
|
|
|
2020-04-12 10:57:44 +02:00
|
|
|
auto& disassembly_view = bottom_splitter.add<GUI::TableView>();
|
2020-04-11 18:46:11 +02:00
|
|
|
disassembly_view.set_size_columns_to_fit_content(true);
|
|
|
|
|
|
|
|
tree_view.on_selection = [&](auto& index) {
|
|
|
|
profile->set_disassembly_index(index);
|
|
|
|
disassembly_view.set_model(profile->disassembly_model());
|
|
|
|
};
|
|
|
|
|
2020-04-21 16:01:00 +02:00
|
|
|
auto menubar = GUI::MenuBar::construct();
|
2020-04-04 12:18:40 +02:00
|
|
|
auto& app_menu = menubar->add_menu("ProfileViewer");
|
|
|
|
app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app.quit(); }));
|
2019-12-15 22:55:11 +01:00
|
|
|
|
2020-04-04 12:18:40 +02:00
|
|
|
auto& view_menu = menubar->add_menu("View");
|
2020-02-02 15:07:41 +01:00
|
|
|
auto invert_action = GUI::Action::create("Invert tree", { Mod_Ctrl, Key_I }, [&](auto& action) {
|
2019-12-16 18:21:05 +01:00
|
|
|
action.set_checked(!action.is_checked());
|
|
|
|
profile->set_inverted(action.is_checked());
|
|
|
|
});
|
|
|
|
invert_action->set_checkable(true);
|
2019-12-16 23:46:39 -05:00
|
|
|
invert_action->set_checked(false);
|
2020-04-18 15:31:19 +02:00
|
|
|
view_menu.add_action(invert_action);
|
2019-12-16 18:21:05 +01:00
|
|
|
|
2020-03-02 21:56:03 +01:00
|
|
|
auto percent_action = GUI::Action::create("Show percentages", { Mod_Ctrl, Key_P }, [&](auto& action) {
|
|
|
|
action.set_checked(!action.is_checked());
|
|
|
|
profile->set_show_percentages(action.is_checked());
|
2020-03-04 19:07:55 +01:00
|
|
|
tree_view.update();
|
2020-04-12 15:22:17 +02:00
|
|
|
disassembly_view.update();
|
2020-03-02 21:56:03 +01:00
|
|
|
});
|
|
|
|
percent_action->set_checkable(true);
|
|
|
|
percent_action->set_checked(false);
|
2020-04-04 12:18:40 +02:00
|
|
|
view_menu.add_action(percent_action);
|
2019-12-16 18:21:05 +01:00
|
|
|
|
2019-12-15 22:55:11 +01:00
|
|
|
app.set_menubar(move(menubar));
|
|
|
|
|
2019-12-12 22:01:06 +01:00
|
|
|
window->show();
|
|
|
|
return app.exec();
|
|
|
|
}
|