Serenity Operating System
at portability 93 lines 3.4 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 = GUI::Widget::construct(); 61 window->set_main_widget(main_widget); 62 main_widget->set_fill_with_background_color(true); 63 main_widget->set_layout(make<GUI::VerticalBoxLayout>()); 64 65 auto timeline_widget = main_widget->add<ProfileTimelineWidget>(*profile); 66 67 auto tree_view = main_widget->add<GUI::TreeView>(); 68 tree_view->set_headers_visible(true); 69 tree_view->set_size_columns_to_fit_content(true); 70 tree_view->set_model(profile->model()); 71 72 auto menubar = make<GUI::MenuBar>(); 73 auto app_menu = GUI::Menu::construct("ProfileViewer"); 74 app_menu->add_action(GUI::CommonActions::make_quit_action([&](auto&) { app.quit(); })); 75 76 menubar->add_menu(move(app_menu)); 77 78 auto view_menu = GUI::Menu::construct("View"); 79 auto invert_action = GUI::Action::create("Invert tree", { Mod_Ctrl, Key_I }, [&](auto& action) { 80 action.set_checked(!action.is_checked()); 81 profile->set_inverted(action.is_checked()); 82 }); 83 invert_action->set_checkable(true); 84 invert_action->set_checked(false); 85 view_menu->add_action(invert_action); 86 87 menubar->add_menu(move(view_menu)); 88 89 app.set_menubar(move(menubar)); 90 91 window->show(); 92 return app.exec(); 93}