SamplesModel.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "SamplesModel.h"
  7. #include "Profile.h"
  8. #include <AK/StringBuilder.h>
  9. namespace Profiler {
  10. SamplesModel::SamplesModel(Profile& profile)
  11. : m_profile(profile)
  12. {
  13. m_user_frame_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/inspector-object.png"));
  14. m_kernel_frame_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/inspector-object-red.png"));
  15. }
  16. SamplesModel::~SamplesModel()
  17. {
  18. }
  19. int SamplesModel::row_count(const GUI::ModelIndex&) const
  20. {
  21. return m_profile.filtered_event_indices().size();
  22. }
  23. int SamplesModel::column_count(const GUI::ModelIndex&) const
  24. {
  25. return Column::__Count;
  26. }
  27. String SamplesModel::column_name(int column) const
  28. {
  29. switch (column) {
  30. case Column::SampleIndex:
  31. return "#";
  32. case Column::Timestamp:
  33. return "Timestamp";
  34. case Column::ProcessID:
  35. return "PID";
  36. case Column::ThreadID:
  37. return "TID";
  38. case Column::ExecutableName:
  39. return "Executable";
  40. case Column::LostSamples:
  41. return "Lost Samples";
  42. case Column::InnermostStackFrame:
  43. return "Innermost Frame";
  44. default:
  45. VERIFY_NOT_REACHED();
  46. }
  47. }
  48. GUI::Variant SamplesModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
  49. {
  50. u32 event_index = m_profile.filtered_event_indices()[index.row()];
  51. auto& event = m_profile.events().at(event_index);
  52. if (role == GUI::ModelRole::Custom) {
  53. return event_index;
  54. }
  55. if (role == GUI::ModelRole::Display) {
  56. if (index.column() == Column::SampleIndex)
  57. return event_index;
  58. if (index.column() == Column::ProcessID)
  59. return event.pid;
  60. if (index.column() == Column::ThreadID)
  61. return event.tid;
  62. if (index.column() == Column::ExecutableName) {
  63. if (auto* process = m_profile.find_process(event.pid, event.serial))
  64. return process->executable;
  65. return "";
  66. }
  67. if (index.column() == Column::Timestamp) {
  68. return (u32)event.timestamp;
  69. }
  70. if (index.column() == Column::LostSamples) {
  71. return event.lost_samples;
  72. }
  73. if (index.column() == Column::InnermostStackFrame) {
  74. return event.frames.last().symbol;
  75. }
  76. return {};
  77. }
  78. return {};
  79. }
  80. }