IndividualSampleModel.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "IndividualSampleModel.h"
  7. #include "Profile.h"
  8. #include <AK/StringBuilder.h>
  9. #include <stdio.h>
  10. namespace Profiler {
  11. IndividualSampleModel::IndividualSampleModel(Profile& profile, size_t event_index)
  12. : m_profile(profile)
  13. , m_event_index(event_index)
  14. {
  15. }
  16. IndividualSampleModel::~IndividualSampleModel()
  17. {
  18. }
  19. int IndividualSampleModel::row_count(const GUI::ModelIndex&) const
  20. {
  21. auto& event = m_profile.events().at(m_event_index);
  22. return event.frames.size();
  23. }
  24. int IndividualSampleModel::column_count(const GUI::ModelIndex&) const
  25. {
  26. return Column::__Count;
  27. }
  28. String IndividualSampleModel::column_name(int column) const
  29. {
  30. switch (column) {
  31. case Column::Address:
  32. return "Address";
  33. case Column::ObjectName:
  34. return "Object";
  35. case Column::Symbol:
  36. return "Symbol";
  37. default:
  38. VERIFY_NOT_REACHED();
  39. }
  40. }
  41. GUI::Variant IndividualSampleModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
  42. {
  43. auto& event = m_profile.events().at(m_event_index);
  44. auto& frame = event.frames[event.frames.size() - index.row() - 1];
  45. if (role == GUI::ModelRole::Display) {
  46. if (index.column() == Column::Address)
  47. return String::formatted("{:p}", frame.address);
  48. if (index.column() == Column::Symbol) {
  49. return frame.symbol;
  50. }
  51. if (index.column() == Column::ObjectName) {
  52. return frame.object_name;
  53. }
  54. return {};
  55. }
  56. return {};
  57. }
  58. }