ITK  6.0.0
Insight Toolkit
itkSmapsFileParser.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkSmapsFileParser_h
19#define itkSmapsFileParser_h
20
21#include "itkMacro.h"
22#include "itkIntTypes.h"
23
24#include <string>
25#include <vector>
26#include <map>
27#include <istream>
28#include <iostream>
29
30namespace itk
31{
38class ITKCommon_EXPORT MapRecord
39{
40public:
42 virtual ~MapRecord();
45 void
47
50 std::string m_RecordName{};
51
56 std::map<std::string, MemoryLoadType> m_Tokens{};
57};
58
65class ITKCommon_EXPORT SmapsRecord : public MapRecord
66{
83 friend ITKCommon_EXPORT std::istream &
84 operator>>(std::istream & in, SmapsRecord & record);
85};
86
93class ITKCommon_EXPORT VMMapSummaryRecord : public MapRecord
94{
100 friend ITKCommon_EXPORT std::istream &
101 operator>>(std::istream & in, VMMapSummaryRecord & record);
102};
103
110class ITKCommon_EXPORT VMMapRecord : public MapRecord
111{
117 friend ITKCommon_EXPORT std::istream &
118 operator>>(std::istream & in, VMMapRecord & record);
119};
120
129class ITKCommon_EXPORT MapData
130{
131public:
134 // todo delete records
135 virtual ~MapData();
136
138 virtual MemoryLoadType
140
142 virtual MemoryLoadType
144
146 virtual MemoryLoadType
148
150 virtual MemoryLoadType
151 GetMemoryUsage(const char * filter, const char * token);
152
154 bool
156
157protected:
159 void
161
162protected:
163 using MapRecordVectorType = std::vector<MapRecord *>;
164
167};
168
174class ITKCommon_EXPORT SmapsData_2_6 : public MapData
175{
176public:
178
179 ~SmapsData_2_6() override;
180
183 GetHeapUsage() override;
184
187 GetStackUsage() override;
188
190 friend ITKCommon_EXPORT std::istream &
191 operator>>(std::istream & smapsStream, SmapsData_2_6 & data);
192
193protected:
194 bool m_HeapRecordFound{};
195};
196
205class ITKCommon_EXPORT VMMapData_10_2 : public MapData
206{
207public:
210 ~VMMapData_10_2() override;
211
214 GetHeapUsage() override;
215
218 GetStackUsage() override;
219
221 friend ITKCommon_EXPORT std::istream &
222 operator>>(std::istream & stream, VMMapData_10_2 & data);
223
224protected:
225 bool m_UsingSummary{ false };
226};
227
235template <typename TMapData>
236class ITK_TEMPLATE_EXPORT MapFileParser
237{
238public:
239 using MemoryLoadType = typename TMapData::MemoryLoadType;
240
241 virtual ~MapFileParser() = default;
246 virtual void
247 ReadFile(const std::string & mapFileLocation = "") = 0;
248
252 bool
254
260
266
272
277 GetMemoryUsage(const char * filter, const char * token = "Size");
278
279protected:
280 std::string m_MapFilePath{}; // location of the last loaded Map file
281 TMapData m_MapData{}; // data of the loaded smap file
282};
283
290template <typename TSmapsDataType>
291class ITK_TEMPLATE_EXPORT SmapsFileParser : public MapFileParser<TSmapsDataType>
292{
293public:
294 virtual ~SmapsFileParser() = default;
300 virtual void
301 ReadFile(const std::string & mapFileLocation = "");
302};
303
309template <typename TVMMapDataType>
310class ITK_TEMPLATE_EXPORT VMMapFileParser : public MapFileParser<TVMMapDataType>
311{
312public:
313 virtual ~VMMapFileParser() = default;
317 virtual void
318 ReadFile(const std::string & mapFileLocation = "");
319};
320} // end namespace itk
321
322#ifndef ITK_MANUAL_INSTANTIATION
323# include "itkSmapsFileParser.hxx"
324#endif
325
326#endif // itkSmapsFileParser_h
Base class for map data containers.
virtual MemoryLoadType GetTotalMemoryUsage()
virtual MemoryLoadType GetStackUsage()=0
virtual MemoryLoadType GetMemoryUsage(const char *filter, const char *token)
virtual ~MapData()
virtual MemoryLoadType GetHeapUsage()=0
SizeValueType MemoryLoadType
std::vector< MapRecord * > MapRecordVectorType
virtual ~MapFileParser()=default
typename TMapData::MemoryLoadType MemoryLoadType
MemoryLoadType GetStackUsage()
MemoryLoadType GetTotalMemoryUsage()
virtual void ReadFile(const std::string &mapFileLocation="")=0
MemoryLoadType GetHeapUsage()
MemoryLoadType GetMemoryUsage(const char *filter, const char *token="Size")
MapRecord class.
SizeValueType MemoryLoadType
virtual ~MapRecord()
Read a smaps stream and return the memory usage information. Smaps files have been added since the li...
~SmapsData_2_6() override
friend ITKCommon_EXPORT std::istream & operator>>(std::istream &smapsStream, SmapsData_2_6 &data)
MemoryLoadType GetHeapUsage() override
MemoryLoadType GetStackUsage() override
Read a smap file (typically located in /proc/PID/smaps) and extract the memory usage information....
virtual ~SmapsFileParser()=default
virtual void ReadFile(const std::string &mapFileLocation="")
An entry in a smaps file.
friend ITKCommon_EXPORT std::istream & operator>>(std::istream &in, SmapsRecord &record)
friend ITKCommon_EXPORT std::istream & operator>>(std::istream &stream, VMMapData_10_2 &data)
MemoryLoadType GetHeapUsage() override
MemoryLoadType GetStackUsage() override
~VMMapData_10_2() override
Read the output of a vmmap command and extract the memory usage information. Used for MAC OS X machin...
virtual ~VMMapFileParser()=default
virtual void ReadFile(const std::string &mapFileLocation="")
Contains an entry in a smaps file.
friend ITKCommon_EXPORT std::istream & operator>>(std::istream &in, VMMapRecord &record)
Contains an entry in a smaps file.
friend ITKCommon_EXPORT std::istream & operator>>(std::istream &in, VMMapSummaryRecord &record)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition: itkIntTypes.h:86