main.cpp 3.5 KB

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