Serenity Operating System
at master 92 lines 2.3 kB view raw
1/* 2 * Copyright (c) 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 "SignpostsModel.h" 9#include "Profile.h" 10#include <AK/StringBuilder.h> 11 12namespace Profiler { 13 14SignpostsModel::SignpostsModel(Profile& profile) 15 : m_profile(profile) 16{ 17} 18 19int SignpostsModel::row_count(GUI::ModelIndex const&) const 20{ 21 return m_profile.filtered_signpost_indices().size(); 22} 23 24int SignpostsModel::column_count(GUI::ModelIndex const&) const 25{ 26 return Column::__Count; 27} 28 29DeprecatedString SignpostsModel::column_name(int column) const 30{ 31 switch (column) { 32 case Column::SignpostIndex: 33 return "#"; 34 case Column::Timestamp: 35 return "Timestamp"; 36 case Column::ProcessID: 37 return "PID"; 38 case Column::ThreadID: 39 return "TID"; 40 case Column::ExecutableName: 41 return "Executable"; 42 case Column::SignpostString: 43 return "String"; 44 case Column::SignpostArgument: 45 return "Argument"; 46 default: 47 VERIFY_NOT_REACHED(); 48 } 49} 50 51GUI::Variant SignpostsModel::data(GUI::ModelIndex const& index, GUI::ModelRole role) const 52{ 53 u32 event_index = m_profile.filtered_signpost_indices()[index.row()]; 54 auto const& event = m_profile.events().at(event_index); 55 56 if (role == GUI::ModelRole::Custom) { 57 return event_index; 58 } 59 60 if (role == GUI::ModelRole::Display) { 61 if (index.column() == Column::SignpostIndex) 62 return event_index; 63 64 if (index.column() == Column::ProcessID) 65 return event.pid; 66 67 if (index.column() == Column::ThreadID) 68 return event.tid; 69 70 if (index.column() == Column::ExecutableName) { 71 if (auto const* process = m_profile.find_process(event.pid, event.serial)) 72 return process->executable; 73 return ""; 74 } 75 76 if (index.column() == Column::Timestamp) { 77 return (u32)event.timestamp; 78 } 79 80 if (index.column() == Column::SignpostString) { 81 return event.data.get<Profile::Event::SignpostData>().string; 82 } 83 84 if (index.column() == Column::SignpostArgument) { 85 return event.data.get<Profile::Event::SignpostData>().arg; 86 } 87 return {}; 88 } 89 return {}; 90} 91 92}