mirror of
https://github.com/RGBCube/serenity
synced 2025-05-15 07:34:59 +00:00

This turns the perfcore format into more a log than it was before, which lets us properly log process, thread and region creation/destruction. This also makes it unnecessary to dump the process' regions every time it is scheduled like we did before. Incidentally this also fixes 'profile -c' because we previously ended up incorrectly dumping the parent's region map into the profile data. Log-based mmap support enables profiling shared libraries which are loaded at runtime, e.g. via dlopen(). This enables profiling both the parent and child process for programs which use execve(). Previously we'd discard the profiling data for the old process. The Profiler tool has been updated to not treat thread IDs as process IDs anymore. This enables support for processes with more than one thread. Also, there's a new widget to filter which process should be displayed.
93 lines
2.3 KiB
C++
93 lines
2.3 KiB
C++
/*
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include "SamplesModel.h"
|
|
#include "Profile.h"
|
|
#include <AK/StringBuilder.h>
|
|
#include <stdio.h>
|
|
|
|
SamplesModel::SamplesModel(Profile& profile)
|
|
: m_profile(profile)
|
|
{
|
|
m_user_frame_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/inspector-object.png"));
|
|
m_kernel_frame_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/inspector-object-red.png"));
|
|
}
|
|
|
|
SamplesModel::~SamplesModel()
|
|
{
|
|
}
|
|
|
|
int SamplesModel::row_count(const GUI::ModelIndex&) const
|
|
{
|
|
return m_profile.filtered_event_indices().size();
|
|
}
|
|
|
|
int SamplesModel::column_count(const GUI::ModelIndex&) const
|
|
{
|
|
return Column::__Count;
|
|
}
|
|
|
|
String SamplesModel::column_name(int column) const
|
|
{
|
|
switch (column) {
|
|
case Column::SampleIndex:
|
|
return "#";
|
|
case Column::Timestamp:
|
|
return "Timestamp";
|
|
case Column::ProcessID:
|
|
return "PID";
|
|
case Column::ThreadID:
|
|
return "TID";
|
|
case Column::ExecutableName:
|
|
return "Executable";
|
|
case Column::InnermostStackFrame:
|
|
return "Innermost Frame";
|
|
default:
|
|
VERIFY_NOT_REACHED();
|
|
}
|
|
}
|
|
|
|
GUI::Variant SamplesModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
|
|
{
|
|
u32 event_index = m_profile.filtered_event_indices()[index.row()];
|
|
auto& event = m_profile.events().at(event_index);
|
|
|
|
if (role == GUI::ModelRole::Custom) {
|
|
return event_index;
|
|
}
|
|
|
|
if (role == GUI::ModelRole::Display) {
|
|
if (index.column() == Column::SampleIndex)
|
|
return event_index;
|
|
|
|
if (index.column() == Column::ProcessID)
|
|
return event.pid;
|
|
|
|
if (index.column() == Column::ThreadID)
|
|
return event.tid;
|
|
|
|
if (index.column() == Column::ExecutableName) {
|
|
if (auto* process = m_profile.find_process(event.pid, event.timestamp))
|
|
return process->executable;
|
|
return "";
|
|
}
|
|
|
|
if (index.column() == Column::Timestamp) {
|
|
return (u32)event.timestamp;
|
|
}
|
|
|
|
if (index.column() == Column::InnermostStackFrame) {
|
|
return event.frames.last().symbol;
|
|
}
|
|
return {};
|
|
}
|
|
return {};
|
|
}
|
|
|
|
void SamplesModel::update()
|
|
{
|
|
did_update(Model::InvalidateAllIndexes);
|
|
}
|