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