Serenity Operating System
at hosted 96 lines 3.6 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include "Profile.h" 28#include "ProfileTimelineWidget.h" 29#include <LibGUI/Action.h> 30#include <LibGUI/Application.h> 31#include <LibGUI/BoxLayout.h> 32#include <LibGUI/Menu.h> 33#include <LibGUI/MenuBar.h> 34#include <LibGUI/Model.h> 35#include <LibGUI/TreeView.h> 36#include <LibGUI/Window.h> 37#include <stdio.h> 38 39int main(int argc, char** argv) 40{ 41 if (argc != 2) { 42 printf("usage: %s <profile-file>\n", argv[0]); 43 return 0; 44 } 45 46 const char* path = argv[1]; 47 auto profile = Profile::load_from_perfcore_file(path); 48 49 if (!profile) { 50 fprintf(stderr, "Unable to load profile '%s'\n", path); 51 return 1; 52 } 53 54 GUI::Application app(argc, argv); 55 56 auto window = GUI::Window::construct(); 57 window->set_title("ProfileViewer"); 58 window->set_rect(100, 100, 800, 600); 59 60 auto& main_widget = window->set_main_widget<GUI::Widget>(); 61 main_widget.set_fill_with_background_color(true); 62 main_widget.set_layout<GUI::VerticalBoxLayout>(); 63 64 main_widget.add<ProfileTimelineWidget>(*profile); 65 66 auto& tree_view = main_widget.add<GUI::TreeView>(); 67 tree_view.set_headers_visible(true); 68 tree_view.set_size_columns_to_fit_content(true); 69 tree_view.set_model(profile->model()); 70 71 auto menubar = make<GUI::MenuBar>(); 72 auto& app_menu = menubar->add_menu("ProfileViewer"); 73 app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app.quit(); })); 74 75 auto& view_menu = menubar->add_menu("View"); 76 auto invert_action = GUI::Action::create("Invert tree", { Mod_Ctrl, Key_I }, [&](auto& action) { 77 action.set_checked(!action.is_checked()); 78 profile->set_inverted(action.is_checked()); 79 }); 80 invert_action->set_checkable(true); 81 invert_action->set_checked(false); 82 83 auto percent_action = GUI::Action::create("Show percentages", { Mod_Ctrl, Key_P }, [&](auto& action) { 84 action.set_checked(!action.is_checked()); 85 profile->set_show_percentages(action.is_checked()); 86 tree_view.update(); 87 }); 88 percent_action->set_checkable(true); 89 percent_action->set_checked(false); 90 view_menu.add_action(percent_action); 91 92 app.set_menubar(move(menubar)); 93 94 window->show(); 95 return app.exec(); 96}