1 #include "snapshot-interface.h"
13 #define MYBINARYNAME "model"
14 #define MYLIBRARYNAME "libmodel.so"
15 #define PROCNAME "/proc/*/maps"
19 typedef std::basic_string<char, std::char_traits<char>, MyAlloc<char> > MyString;
21 snapshotStack * snapshotObject;
23 /*This looks like it might leak memory... Subramanian should fix this. */
25 typedef std::basic_stringstream< char, std::char_traits< char >, MyAlloc< char > > MyStringStream;
26 std::vector< MyString, MyAlloc< MyString> > splitString( MyString input, char delim ){
27 std::vector< MyString, MyAlloc< MyString > > splits;
28 MyStringStream ss( input );
30 while( std::getline( ss, item, delim ) ){
31 splits.push_back( item );
36 bool checkPermissions( MyString permStr ){
37 return permStr.find("w") != MyString::npos;
39 static void takeSegmentSnapshot( const MyString & lineText ){
40 std::vector< MyString, MyAlloc< MyString > > firstSplit = splitString( lineText, ' ' );
41 if( checkPermissions( firstSplit[ 1 ] ) ){
42 std::vector< MyString, MyAlloc< MyString > > secondSplit = splitString( firstSplit[ 0 ], '-' );
43 size_t val1 = 0, val2 = 0;
44 sscanf( secondSplit[ 0 ].c_str(), "%zx", &val1 );
45 sscanf( secondSplit[ 1 ].c_str(), "%zx", &val2 );
46 size_t len = ( val2 - val1 ) / PAGESIZE;
48 addMemoryRegionToSnapShot( ( void * )val1, len );
52 void SnapshotGlobalSegments(){
53 MyString fn = PROCNAME;
54 static char sProcessSize[ 12 ] = { 0 };
55 std::pair< const char *, bool > dataSect[ 2 ];
56 dataSect[ 0 ] = std::make_pair( MYBINARYNAME, false );
57 dataSect[ 1 ] = std::make_pair( MYLIBRARYNAME, false );
58 static pid_t sProcID = 0;
61 sprintf( sProcessSize, "%d", sProcID );
63 fn.replace( REPLACEPOS, 1, sProcessSize );
64 std::ifstream procName( fn.c_str() );
65 if( procName.is_open() ){
67 while( procName.good() ){
68 getline( procName, line );
70 for( i = 0; i < 3; ++i ){
71 if( MyString::npos != line.find( dataSect[ i ].first ) ) break;
73 if( i >= 3 || dataSect[ i ].second == true ) continue;
74 dataSect[ i ].second = true;
75 if( !procName.good() )return;
76 getline( procName, line );
77 takeSegmentSnapshot( line );
82 //class definition of snapshotStack.....
83 //declaration of constructor....
84 snapshotStack::snapshotStack(){
85 SnapshotGlobalSegments();
89 snapshotStack::~snapshotStack(){
92 int snapshotStack::backTrackBeforeStep(int seqindex) {
94 if (stack->index<=seqindex) {
96 rollBack(stack->snapshotid);
99 struct stackEntry *tmp=stack;
105 void snapshotStack::snapshotStep(int seqindex) {
106 struct stackEntry *tmp=(struct stackEntry *)MYMALLOC(sizeof(struct stackEntry));
109 tmp->snapshotid=takeSnapshot();