libclues
Linux C++ Tracing Library
Loading...
Searching...
No Matches
process.hxx
1#pragma once
2
3// cosmos
4#include <cosmos/proc/process.hxx>
5#include <cosmos/proc/ResourceUsage.hxx>
6#include <cosmos/proc/types.hxx>
7#include <cosmos/thread/thread.hxx>
8
9// clues
10#include <clues/items/items.hxx>
11#include <clues/SystemCallItem.hxx>
12
13namespace clues::item {
14
15class CLUES_API ProcessIDItem :
16 public SystemCallItem {
17public: // functions
18
19 explicit ProcessIDItem(const ItemType type, const std::string_view desc) :
20 SystemCallItem{type, "pid", desc} {
21 }
22
23 auto pid() const { return m_pid; }
24
25 std::string str() const override {
26 if (m_pid == cosmos::ProcessID::INVALID)
27 return "-1";
28
29 return SystemCallItem::str();
30 }
31
32protected: // functions
33
34 void processValue(const Tracee&) override {
36 }
37
38protected: // data
39
40 cosmos::ProcessID m_pid = cosmos::ProcessID::INVALID;
41};
42
43class CLUES_API ThreadIDItem :
44 public SystemCallItem {
45public: // functions
46
47 explicit ThreadIDItem(const ItemType type, const std::string_view desc = "thread id") :
48 SystemCallItem{type, "tid", desc} {
49 }
50
51 auto tid() const { return m_tid; }
52
53protected: // functions
54
55 void processValue(const Tracee&) override {
57 }
58
59protected: // data
60
61 cosmos::ThreadID m_tid = cosmos::ThreadID::INVALID;
62};
63
64class CLUES_API ExitStatusItem :
65 public SystemCallItem {
66public: // functions
67
68 explicit ExitStatusItem(const ItemType type, const std::string_view desc) :
69 SystemCallItem{type, "status", desc} {
70 }
71
72 auto status() const { return m_status; }
73
74protected: // functions
75
76 void processValue(const Tracee&) override {
77 m_status = valueAs<cosmos::ExitStatus>();
78 }
79
80protected: // data
81
82 cosmos::ExitStatus m_status = cosmos::ExitStatus::INVALID;
83};
84
85class CLUES_API WaitOptionsItem :
86 public ValueInParameter {
87public: // functions
88
89 explicit WaitOptionsItem() :
90 ValueInParameter{"options", "wait options"} {
91 }
92
93 auto options() const {
94 return m_options;
95 }
96
97 std::string str() const override;
98
99protected: // functions
100
101 void processValue(const Tracee&) override {
102 m_options = cosmos::WaitFlags{valueAs<int>()};
103 }
104
105protected: // data
106
107 cosmos::WaitFlags m_options;
108};
109
111class CLUES_API ResourceUsageItem :
112 public PointerOutValue {
113public: // functions
114
115 explicit ResourceUsageItem() :
116 PointerOutValue{"rusage", "resource usage"} {
117 }
118
119 std::string str() const override;
120
121 std::optional<const cosmos::ResourceUsage> usage() const {
122 if (!m_rusage)
123 return {};
124 return *m_rusage;
125 }
126
127protected: // types
128
130 public cosmos::ResourceUsage {
131
132 struct rusage& raw() {
133 return m_ru;
134 }
135
136 using cosmos::ResourceUsage::raw;
137 };
138
139protected: // functions
140
141 void processValue(const Tracee &) override {
142 m_rusage.reset();
143 }
144
145 void updateData(const Tracee &proc) override;
146
147protected: // data
148
149 std::optional<ResourceUsage> m_rusage;
150};
151
153class CLUES_API WaitStatusItem :
154 public PointerToScalar<int> {
155public: // functions
156
157 explicit WaitStatusItem() :
158 PointerToScalar{"wstatus", "wait status"} {
159 }
160
161 const std::optional<cosmos::WaitStatus>& status() const {
162 return m_status;
163 }
164
165protected: // functions
166
167 std::string scalarToString() const override;
168
169 void processValue(const Tracee &tracee) override {
170 m_status.reset();
172 }
173
174 void updateData(const Tracee &tracee) override {
176 if (m_val) {
177 m_status = cosmos::WaitStatus{*m_val};
178 }
179 }
180
181protected: // data
182
183 std::optional<cosmos::WaitStatus> m_status;
184};
185
186} // end ns
virtual std::string str() const
Returns a human readable string representation of the item.
OTHER valueAs() const
Helper to cast the strongly typed Word m_val to other strong enum types.
SystemCallItem(const ItemType type, const std::string_view short_name={}, const std::string_view long_name={})
Constructs a new SystemCallItem.
Base class for traced processes.
Definition Tracee.hxx:39
void processValue(const Tracee &) override
Processes the value stored in m_val acc. to the actual item type.
Definition process.hxx:76
void updateData(const Tracee &tracee) override
Called upon exit of the system call to update possible out parameters.
Definition items.hxx:245
void processValue(const Tracee &tracee) override
Processes the value stored in m_val acc. to the actual item type.
Definition items.hxx:235
std::string str() const override
Returns a human readable string representation of the item.
Definition process.hxx:25
void processValue(const Tracee &) override
Processes the value stored in m_val acc. to the actual item type.
Definition process.hxx:34
void processValue(const Tracee &) override
Processes the value stored in m_val acc. to the actual item type.
Definition process.hxx:141
std::string str() const override
Returns a human readable string representation of the item.
Definition process.cxx:31
void processValue(const Tracee &) override
Processes the value stored in m_val acc. to the actual item type.
Definition process.hxx:55
std::string str() const override
Returns a human readable string representation of the item.
Definition process.cxx:9
void processValue(const Tracee &) override
Processes the value stored in m_val acc. to the actual item type.
Definition process.hxx:101
void updateData(const Tracee &tracee) override
Called upon exit of the system call to update possible out parameters.
Definition process.hxx:174
void processValue(const Tracee &tracee) override
Processes the value stored in m_val acc. to the actual item type.
Definition process.hxx:169
ItemType
Basic type of a SystemCallItem.