2022-02-17 21:26:20 +00:00
|
|
|
/*
|
2023-08-25 21:47:42 +00:00
|
|
|
* Copyright (c) 2022-2023, Jakub Berkop <jakub.berkop@gmail.com>
|
2022-02-17 21:26:20 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
#include <AK/ByteString.h>
|
2022-02-17 21:26:20 +00:00
|
|
|
#include <AK/Function.h>
|
|
|
|
#include <AK/LexicalPath.h>
|
2023-08-25 21:47:42 +00:00
|
|
|
#include <AK/Time.h>
|
2022-02-17 21:26:20 +00:00
|
|
|
#include <LibGUI/Model.h>
|
|
|
|
|
|
|
|
namespace Profiler {
|
|
|
|
|
|
|
|
class Profile;
|
|
|
|
|
|
|
|
class FileEventNode : public RefCounted<FileEventNode> {
|
|
|
|
public:
|
2023-12-16 14:19:34 +00:00
|
|
|
static NonnullRefPtr<FileEventNode> create(ByteString const& path, FileEventNode* parent = nullptr)
|
2022-02-17 21:26:20 +00:00
|
|
|
{
|
|
|
|
return adopt_ref(*new FileEventNode(path, parent));
|
|
|
|
}
|
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
FileEventNode& find_or_create_node(ByteString const&);
|
2022-02-17 21:26:20 +00:00
|
|
|
|
|
|
|
Vector<NonnullRefPtr<FileEventNode>>& children() { return m_children; }
|
|
|
|
Vector<NonnullRefPtr<FileEventNode>> const& children() const { return m_children; }
|
|
|
|
|
2023-07-08 02:48:11 +00:00
|
|
|
FileEventNode* parent() { return m_parent; }
|
2022-02-17 21:26:20 +00:00
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
FileEventNode& create_recursively(ByteString);
|
2022-02-17 21:26:20 +00:00
|
|
|
|
|
|
|
void for_each_parent_node(Function<void(FileEventNode&)> callback);
|
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
ByteString const& path() const { return m_path; }
|
2022-02-17 21:26:20 +00:00
|
|
|
|
2023-08-25 21:47:42 +00:00
|
|
|
u64 total_count() const;
|
|
|
|
Duration total_duration() const;
|
2022-02-17 21:26:20 +00:00
|
|
|
|
2023-08-25 21:47:42 +00:00
|
|
|
struct FileEventType {
|
|
|
|
u64 count = 0;
|
|
|
|
Duration duration = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
FileEventType& open() { return m_open; }
|
|
|
|
FileEventType& close() { return m_close; }
|
|
|
|
FileEventType& readv() { return m_readv; }
|
|
|
|
FileEventType& read() { return m_read; }
|
|
|
|
FileEventType& pread() { return m_pread; }
|
2022-02-17 21:26:20 +00:00
|
|
|
|
|
|
|
private:
|
2023-12-16 14:19:34 +00:00
|
|
|
FileEventNode(ByteString const& path, FileEventNode* parent = nullptr)
|
2022-02-17 21:26:20 +00:00
|
|
|
: m_path(path)
|
|
|
|
, m_parent(parent) {};
|
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
ByteString m_path;
|
2023-08-25 21:47:42 +00:00
|
|
|
|
|
|
|
FileEventType m_open;
|
|
|
|
FileEventType m_close;
|
|
|
|
FileEventType m_readv;
|
|
|
|
FileEventType m_read;
|
|
|
|
FileEventType m_pread;
|
2022-02-17 21:26:20 +00:00
|
|
|
|
|
|
|
Vector<NonnullRefPtr<FileEventNode>> m_children;
|
|
|
|
FileEventNode* m_parent = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
class FileEventModel final : public GUI::Model {
|
|
|
|
public:
|
|
|
|
static NonnullRefPtr<FileEventModel> create(Profile& profile)
|
|
|
|
{
|
|
|
|
return adopt_ref(*new FileEventModel(profile));
|
|
|
|
}
|
|
|
|
|
|
|
|
enum Column {
|
|
|
|
Path,
|
2023-08-25 21:47:42 +00:00
|
|
|
TotalCount,
|
|
|
|
TotalDuration,
|
|
|
|
OpenCount,
|
|
|
|
OpenDuration,
|
|
|
|
CloseCount,
|
|
|
|
CloseDuration,
|
|
|
|
ReadvCount,
|
|
|
|
ReadvDuration,
|
|
|
|
ReadCount,
|
|
|
|
ReadDuration,
|
|
|
|
PreadCount,
|
|
|
|
PreadDuration,
|
2022-02-17 21:26:20 +00:00
|
|
|
__Count
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual ~FileEventModel() override;
|
|
|
|
|
|
|
|
virtual int row_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override;
|
|
|
|
virtual int column_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override;
|
2023-06-13 15:30:15 +00:00
|
|
|
virtual ErrorOr<String> column_name(int) const override;
|
2022-02-17 21:26:20 +00:00
|
|
|
virtual GUI::Variant data(GUI::ModelIndex const&, GUI::ModelRole) const override;
|
|
|
|
virtual GUI::ModelIndex index(int row, int column, GUI::ModelIndex const& parent = GUI::ModelIndex()) const override;
|
|
|
|
virtual GUI::ModelIndex parent_index(GUI::ModelIndex const&) const override;
|
|
|
|
virtual int tree_column() const override { return Column::Path; }
|
|
|
|
virtual bool is_column_sortable(int) const override { return false; }
|
|
|
|
virtual bool is_searchable() const override { return true; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit FileEventModel(Profile&);
|
|
|
|
|
|
|
|
Profile& m_profile;
|
|
|
|
|
|
|
|
GUI::Icon m_user_frame_icon;
|
|
|
|
GUI::Icon m_kernel_frame_icon;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|