main.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #include "Profile.h"
  27. #include "ProfileTimelineWidget.h"
  28. #include <LibGUI/Action.h>
  29. #include <LibGUI/Application.h>
  30. #include <LibGUI/BoxLayout.h>
  31. #include <LibGUI/Menu.h>
  32. #include <LibGUI/MenuBar.h>
  33. #include <LibGUI/Model.h>
  34. #include <LibGUI/TreeView.h>
  35. #include <LibGUI/Window.h>
  36. #include <stdio.h>
  37. int main(int argc, char** argv)
  38. {
  39. if (argc != 2) {
  40. printf("usage: %s <profile-file>\n", argv[0]);
  41. return 0;
  42. }
  43. const char* path = argv[1];
  44. auto profile = Profile::load_from_perfcore_file(path);
  45. if (!profile) {
  46. fprintf(stderr, "Unable to load profile '%s'\n", path);
  47. return 1;
  48. }
  49. GUI::Application app(argc, argv);
  50. auto window = GUI::Window::construct();
  51. window->set_title("ProfileViewer");
  52. window->set_rect(100, 100, 800, 600);
  53. auto& main_widget = window->set_main_widget<GUI::Widget>();
  54. main_widget.set_fill_with_background_color(true);
  55. main_widget.set_layout<GUI::VerticalBoxLayout>();
  56. auto timeline_widget = main_widget.add<ProfileTimelineWidget>(*profile);
  57. auto tree_view = main_widget.add<GUI::TreeView>();
  58. tree_view->set_headers_visible(true);
  59. tree_view->set_size_columns_to_fit_content(true);
  60. tree_view->set_model(profile->model());
  61. auto menubar = make<GUI::MenuBar>();
  62. auto app_menu = GUI::Menu::construct("ProfileViewer");
  63. app_menu->add_action(GUI::CommonActions::make_quit_action([&](auto&) { app.quit(); }));
  64. menubar->add_menu(move(app_menu));
  65. auto view_menu = GUI::Menu::construct("View");
  66. auto invert_action = GUI::Action::create("Invert tree", { Mod_Ctrl, Key_I }, [&](auto& action) {
  67. action.set_checked(!action.is_checked());
  68. profile->set_inverted(action.is_checked());
  69. });
  70. invert_action->set_checkable(true);
  71. invert_action->set_checked(false);
  72. view_menu->add_action(invert_action);
  73. auto percent_action = GUI::Action::create("Show percentages", { Mod_Ctrl, Key_P }, [&](auto& action) {
  74. action.set_checked(!action.is_checked());
  75. profile->set_show_percentages(action.is_checked());
  76. tree_view->update();
  77. });
  78. percent_action->set_checkable(true);
  79. percent_action->set_checked(false);
  80. view_menu->add_action(percent_action);
  81. menubar->add_menu(move(view_menu));
  82. app.set_menubar(move(menubar));
  83. window->show();
  84. return app.exec();
  85. }