ITK  5.2.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  * http://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 
30 namespace itk
31 {
38 class ITKCommon_EXPORT MapRecord
39 {
40 public:
42  virtual ~MapRecord();
45  void
46  Reset();
47 
50  std::string m_RecordName;
51 
56  std::map<std::string, MemoryLoadType> m_Tokens;
57 };
58 
65 class ITKCommon_EXPORT SmapsRecord : public MapRecord
66 {
83  friend ITKCommon_EXPORT std::istream &
84  operator>>(std::istream & in, SmapsRecord & record);
85 };
86 
93 class ITKCommon_EXPORT VMMapSummaryRecord : public MapRecord
94 {
100  friend ITKCommon_EXPORT std::istream &
101  operator>>(std::istream & in, VMMapSummaryRecord & record);
102 };
103 
110 class ITKCommon_EXPORT VMMapRecord : public MapRecord
111 {
117  friend ITKCommon_EXPORT std::istream &
118  operator>>(std::istream & in, VMMapRecord & record);
119 };
120 
129 class ITKCommon_EXPORT MapData
130 {
131 public:
134  // todo delete records
135  virtual ~MapData();
136 
138  virtual MemoryLoadType
139  GetHeapUsage() = 0;
140 
142  virtual MemoryLoadType
143  GetStackUsage() = 0;
144 
146  virtual MemoryLoadType
147  GetTotalMemoryUsage();
148 
150  virtual MemoryLoadType
151  GetMemoryUsage(const char * filter, const char * token);
152 
154  bool
155  Empty();
156 
157 protected:
159  void
160  Reset();
161 
162 protected:
163  using MapRecordVectorType = std::vector<MapRecord *>;
164 
167 };
168 
174 class ITKCommon_EXPORT SmapsData_2_6 : public MapData
175 {
176 public:
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 
193 protected:
195 };
196 
205 class ITKCommon_EXPORT VMMapData_10_2 : public MapData
206 {
207 public:
209  VMMapData_10_2();
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 
224 protected:
225  bool m_UsingSummary{ false };
226 };
227 
235 template <typename TMapData>
236 class ITK_TEMPLATE_EXPORT MapFileParser
237 {
238 public:
239  using MemoryLoadType = typename TMapData::MemoryLoadType;
240 
241  virtual ~MapFileParser() = default;
246  virtual void
247  ReadFile(const std::string & mapFileLocation = "") = 0;
248 
252  bool
253  Update();
254 
259  GetHeapUsage();
260 
265  GetStackUsage();
266 
271  GetTotalMemoryUsage();
272 
277  GetMemoryUsage(const char * filter, const char * token = "Size");
278 
279 protected:
280  std::string m_MapFilePath; //< location of the last loaded Map file
281  TMapData m_MapData; //< data of the loaded smap file
282 };
283 
290 template <typename TSmapsDataType>
291 class ITK_TEMPLATE_EXPORT SmapsFileParser : public MapFileParser<TSmapsDataType>
292 {
293 public:
294  virtual ~SmapsFileParser() = default;
300  virtual void
301  ReadFile(const std::string & mapFileLocation = "");
302 };
303 
309 template <typename TVMMapDataType>
310 class ITK_TEMPLATE_EXPORT VMMapFileParser : public MapFileParser<TVMMapDataType>
311 {
312 public:
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
itk::MapData::m_Records
MapRecordVectorType m_Records
Definition: itkSmapsFileParser.h:166
itk::MapRecord::m_Tokens
std::map< std::string, MemoryLoadType > m_Tokens
Definition: itkSmapsFileParser.h:56
itk::MapRecord::MemoryLoadType
SizeValueType MemoryLoadType
Definition: itkSmapsFileParser.h:41
itk::MapRecord
MapRecord class.
Definition: itkSmapsFileParser.h:38
itk::MapData
Base class for map data containers.
Definition: itkSmapsFileParser.h:129
itk::VMMapRecord
Contains an entry in a smaps file.
Definition: itkSmapsFileParser.h:110
itk::MapData::MemoryLoadType
SizeValueType MemoryLoadType
Definition: itkSmapsFileParser.h:133
itkMacro.h
itk::MapFileParser< TSmapsDataType >::MemoryLoadType
typename TSmapsDataType ::MemoryLoadType MemoryLoadType
Definition: itkSmapsFileParser.h:239
itk::MapData::MapRecordVectorType
std::vector< MapRecord * > MapRecordVectorType
Definition: itkSmapsFileParser.h:163
itk::operator>>
std::istream & operator>>(std::istream &is, Point< T, NPointDimension > &vct)
itk::VMMapFileParser
Read the output of a vmmap command and extract the memory usage information. Used for MAC OS X machin...
Definition: itkSmapsFileParser.h:310
itk::SmapsRecord
An entry in a smaps file.
Definition: itkSmapsFileParser.h:65
itkIntTypes.h
itk::MapRecord::m_RecordName
std::string m_RecordName
Definition: itkSmapsFileParser.h:50
itk::SmapsData_2_6
Read a smaps stream and return the memory usage information. Smaps files have been added since the li...
Definition: itkSmapsFileParser.h:174
itk::VMMapSummaryRecord
Contains an entry in a smaps file.
Definition: itkSmapsFileParser.h:93
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::MapFileParser
TODO.
Definition: itkSmapsFileParser.h:236
itk::VMMapData_10_2
TODO.
Definition: itkSmapsFileParser.h:205
itk::SmapsFileParser
Read a smap file (typically located in /proc/PID/smaps) and extract the memory usage information....
Definition: itkSmapsFileParser.h:291
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::MapFileParser::m_MapData
TMapData m_MapData
Definition: itkSmapsFileParser.h:281
itk::MapFileParser::m_MapFilePath
std::string m_MapFilePath
Definition: itkSmapsFileParser.h:280
itk::SmapsData_2_6::m_HeapRecordFound
bool m_HeapRecordFound
Definition: itkSmapsFileParser.h:194