ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkSmapsFileParser.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 Reset();
46 
49  std::string m_RecordName;
50 
55  std::map< std::string, MemoryLoadType > m_Tokens;
56 };
57 
64 class ITKCommon_EXPORT SmapsRecord:public MapRecord
65 {
82  friend ITKCommon_EXPORT std::istream & operator>>(std::istream & in, SmapsRecord & record);
83 };
84 
91 class ITKCommon_EXPORT VMMapSummaryRecord:public MapRecord
92 {
98  friend ITKCommon_EXPORT std::istream & operator>>(std::istream & in, VMMapSummaryRecord & record);
99 };
100 
107 class ITKCommon_EXPORT VMMapRecord:public MapRecord
108 {
114  friend ITKCommon_EXPORT std::istream & operator>>(std::istream & in, VMMapRecord & record);
115 };
116 
125 class ITKCommon_EXPORT MapData
126 {
127 public:
130  //todo delete records
131  virtual ~MapData();
132 
134  virtual MemoryLoadType GetHeapUsage() = 0;
135 
137  virtual MemoryLoadType GetStackUsage() = 0;
138 
140  virtual MemoryLoadType GetTotalMemoryUsage();
141 
143  virtual MemoryLoadType GetMemoryUsage(const char *filter, const char *token);
144 
146  bool Empty();
147 
148 protected:
150  void Reset();
151 
152 protected:
153  using MapRecordVectorType = std::vector< MapRecord * >;
154 
157 };
158 
164 class ITKCommon_EXPORT SmapsData_2_6:public MapData
165 {
166 public:
168 
169  ~SmapsData_2_6() override;
170 
172  MemoryLoadType GetHeapUsage() override;
173 
175  MemoryLoadType GetStackUsage() override;
176 
178  friend ITKCommon_EXPORT std::istream & operator>>(std::istream & smapsStream,
179  SmapsData_2_6 & data);
180 
181 protected:
183 };
184 
193 class ITKCommon_EXPORT VMMapData_10_2:public MapData
194 {
195 public:
197  VMMapData_10_2();
198  ~VMMapData_10_2() override;
199 
201  MemoryLoadType GetHeapUsage() override;
202 
204  MemoryLoadType GetStackUsage() override;
205 
207  friend ITKCommon_EXPORT std::istream & operator>>(std::istream & stream,
208  VMMapData_10_2 & data);
209 
210 protected:
211  bool m_UsingSummary{false};
212 };
213 
221 template< typename TMapData >
222 class ITK_TEMPLATE_EXPORT MapFileParser
223 {
224 public:
225  using MemoryLoadType = typename TMapData::MemoryLoadType;
226 
227  virtual ~MapFileParser() = default;
232  virtual void ReadFile(const std::string & mapFileLocation = "") = 0;
233 
237  bool Update();
238 
242  MemoryLoadType GetHeapUsage();
243 
247  MemoryLoadType GetStackUsage();
248 
252  MemoryLoadType GetTotalMemoryUsage();
253 
257  MemoryLoadType GetMemoryUsage(const char *filter, const char *token = "Size");
258 
259 protected:
260  std::string m_MapFilePath; //< location of the last loaded Map file
261  TMapData m_MapData; //< data of the loaded smap file
262 };
263 
270 template< typename TSmapsDataType >
271 class ITK_TEMPLATE_EXPORT SmapsFileParser:public MapFileParser< TSmapsDataType >
272 {
273 public:
274  virtual ~SmapsFileParser() = default;
280  virtual void ReadFile(const std::string & mapFileLocation = "");
281 };
282 
288 template< typename TVMMapDataType >
289 class ITK_TEMPLATE_EXPORT VMMapFileParser:public MapFileParser< TVMMapDataType >
290 {
291 public:
292  virtual ~VMMapFileParser() = default;
296  virtual void ReadFile(const std::string & mapFileLocation = "");
297 };
298 } // end namespace itk
299 
300 #ifndef ITK_MANUAL_INSTANTIATION
301 #include "itkSmapsFileParser.hxx"
302 #endif
303 
304 #endif // itkSmapsFileParser_h
Base class for map data containers.
std::string m_RecordName
std::istream & operator>>(std::istream &is, Point< T, NPointDimension > &v)
unsigned long SizeValueType
Definition: itkIntTypes.h:83
std::vector< MapRecord * > MapRecordVectorType
MapRecord class.
Read the output of a vmmap command and extract the memory usage information. Used for MAC OS X machin...
std::map< std::string, MemoryLoadType > m_Tokens
An entry in a smaps file.
Contains an entry in a smaps file.
Read a smaps stream and return the memory usage information. Smaps files have been added since the li...
Contains an entry in a smaps file.
SizeValueType MemoryLoadType
Read a smap file (typically located in /proc/PID/smaps) and extract the memory usage information...
MapRecordVectorType m_Records
typename TSmapsDataType::MemoryLoadType MemoryLoadType
SizeValueType MemoryLoadType