SamplesModel.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. #include <stdio.h>
  10. SamplesModel::SamplesModel(Profile& profile)
  11. : m_profile(profile)
  12. {
  13. m_user_frame_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/inspector-object.png"));
  14. m_kernel_frame_icon.set_bitmap_for_size(16, Gfx::Bitmap::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::InnermostStackFrame:
  41. return "Innermost Frame";
  42. default:
  43. VERIFY_NOT_REACHED();
  44. }
  45. }
  46. GUI::Variant SamplesModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
  47. {
  48. u32 event_index = m_profile.filtered_event_indices()[index.row()];
  49. auto& event = m_profile.events().at(event_index);
  50. if (role == GUI::ModelRole::Custom) {
  51. return event_index;
  52. }
  53. if (role == GUI::ModelRole::Display) {
  54. if (index.column() == Column::SampleIndex)
  55. return event_index;
  56. if (index.column() == Column::ProcessID)
  57. return event.pid;
  58. if (index.column() == Column::ThreadID)
  59. return event.tid;
  60. if (index.column() == Column::ExecutableName) {
  61. if (auto* process = m_profile.find_process(event.pid, event.timestamp))
  62. return process->executable;
  63. return "";
  64. }
  65. if (index.column() == Column::Timestamp) {
  66. return (u32)event.timestamp;
  67. }
  68. if (index.column() == Column::InnermostStackFrame) {
  69. return event.frames.last().symbol;
  70. }
  71. return {};
  72. }
  73. return {};
  74. }
  75. void SamplesModel::update()
  76. {
  77. did_update(Model::InvalidateAllIndexes);
  78. }