26 return tolower(static_cast<int>(a)) == tolower(static_cast<int>(b));
48 std::string headerline;
49 std::getline( in, headerline);
51 if (headerline.empty())
57 std::istringstream stream(headerline);
58 std::string address, perms, offset, device;
62 if (!stream.good()) itkGenericExceptionMacro( <<
"bad address: " << address );
64 if (!stream.good()) itkGenericExceptionMacro( <<
"bad perms: " << perms );
66 if (!stream.good()) itkGenericExceptionMacro( <<
"bad offset: " << offset );
68 if (!stream.good()) itkGenericExceptionMacro( <<
"bad device: " << device );
77 std::streampos lastPos = in.tellg();
79 while ( std::getline(in,token,
':').good() )
82 if ( token.find(
' ') != std::string::npos )
84 in.seekg (lastPos, std::ios::beg);
89 std::getline(in,token);
90 if ( token !=
" kB" || !in.good()) itkGenericExceptionMacro( <<
"bad size: " << record.
m_Tokens[token] );
98 itkGenericExceptionMacro( <<
"The smaps header is corrupted" );
120 itkGenericExceptionMacro( <<
"Bad record name: " << record.
m_RecordName );
125 while ( (in>>bracket).good() && bracket.find(
"[",0) == std::string::npos )
130 if (!in.good() || bracket.find(
"[",0) == std::string::npos )
132 itkGenericExceptionMacro( <<
"For record: " << record.
m_RecordName
133 <<
", bad left bracket: " << bracket );
140 itkGenericExceptionMacro( <<
"For record: " << record.
m_RecordName
141 <<
", bad size: " << record.
m_Tokens[
"Size"] );
148 itkGenericExceptionMacro( <<
"For record: " << record.
m_RecordName
149 <<
", bad right bracket: " << bracket );
156 itkGenericExceptionMacro( <<
"The smaps header is corrupted" );
181 bool submapFound =
false;
182 bool recordHasNoName =
false;
198 itkGenericExceptionMacro( <<
"Bad record name: " << record.
m_RecordName );
204 in.getline(line,256);
221 itkGenericExceptionMacro( <<
"For record: " << record.
m_RecordName
222 <<
", bad address: " << address );
226 if ( address.find(
"[",0) != std::string::npos )
228 in.getline(line,256);
229 recordHasNoName =
true;
233 recordHasNoName =
false;
237 }
while(submapFound || recordHasNoName);
241 while ( (in>>bracket).good() && bracket.find(
"[",0) == std::string::npos )
248 if (!in.good() || bracket.find(
"[",0) == std::string::npos )
250 itkGenericExceptionMacro( <<
"For record: " << record.
m_RecordName
251 <<
", bad left bracket: " << bracket );
253 if ( bracket.length() > 1 )
255 record.
m_Tokens[
"Size"] = atoi(bracket.substr(1,bracket.length()-3).c_str());
263 itkGenericExceptionMacro( <<
"For record: " << record.
m_RecordName
264 <<
", bad size: " << record.
m_Tokens[
"Size"] );
266 in.getline(line,256);
269 itkGenericExceptionMacro( <<
"For record: " << record.
m_RecordName
270 <<
", bad end of line: " << line );
277 itkGenericExceptionMacro( <<
"The smaps header is corrupted" );
287 template<
class TFirstType>
296 std::map<std::string,unsigned int>::const_iterator it = second->
m_Tokens.find(
m_Token);
297 return first + ((it!=second->
m_Tokens.end())?it->second:0);
305 template<
class TFirstType>
376 while( smapsStream >> *record )
387 itkGenericExceptionMacro( <<
"The Smaps stream contains errors, can't read the memory records." );
398 if ( heapUsage == 0 )
416 :m_UsingSummary(false)
434 std::streampos startPos = stream.tellg();
436 while( std::getline(stream,line).good() )
438 if ( line.find(
"==== Summary for process",0) != std::string::npos )
442 while( std::getline(stream,line).good() )
444 if ( line.find(
"REGION TYPE",0) != std::string::npos )
448 if ( !std::getline(stream,line).good() )
454 stream.seekg(0,std::ios_base::beg);
456 while( std::getline(stream,line).good() )
458 if ( line.find(
"==== Writable regions for process",0) != std::string::npos )
463 itkGenericExceptionMacro( <<
"Can't find the \"Writable regions\" section, can't read the memory records." );
475 while( stream >> *dynamic_cast<VMMapSummaryRecord *>(record) )
489 while( stream >> *dynamic_cast<VMMapRecord* >(record) )
505 itkGenericExceptionMacro( <<
"The VMMap stream contains errors, can't read the memory records." );