1 #include "snapshot-interface.h"
10 #define MYBINARYNAME "model"
11 #define MYLIBRARYNAME "libmodel.so"
12 #define PROCNAME "/proc/*/maps"
16 snapshotStack * snapshotObject;
18 /*This looks like it might leak memory... Subramanian should fix this. */
20 typedef std::basic_stringstream< char, std::char_traits< char >, MyAlloc< char > > MyStringStream;
21 std::vector< MyString, MyAlloc< MyString> > splitString( MyString input, char delim ){
22 std::vector< MyString, MyAlloc< MyString > > splits;
23 MyStringStream ss( input );
25 while( std::getline( ss, item, delim ) ){
26 splits.push_back( item );
31 bool checkPermissions( MyString permStr ){
32 return permStr.find("w") != MyString::npos;
34 static void takeSegmentSnapshot( const MyString & lineText ){
35 std::vector< MyString, MyAlloc< MyString > > firstSplit = splitString( lineText, ' ' );
36 if( checkPermissions( firstSplit[ 1 ] ) ){
37 std::vector< MyString, MyAlloc< MyString > > secondSplit = splitString( firstSplit[ 0 ], '-' );
38 size_t val1 = 0, val2 = 0;
39 sscanf( secondSplit[ 0 ].c_str(), "%zx", &val1 );
40 sscanf( secondSplit[ 1 ].c_str(), "%zx", &val2 );
41 size_t len = ( val2 - val1 ) / PAGESIZE;
43 addMemoryRegionToSnapShot( ( void * )val1, len );
47 void SnapshotGlobalSegments(){
48 MyString fn = PROCNAME;
49 static char sProcessSize[ 12 ] = { 0 };
50 std::pair< const char *, bool > dataSect[ 2 ];
51 dataSect[ 0 ] = std::make_pair( MYBINARYNAME, false );
52 dataSect[ 1 ] = std::make_pair( MYLIBRARYNAME, false );
53 static pid_t sProcID = 0;
56 sprintf( sProcessSize, "%d", sProcID );
58 fn.replace( REPLACEPOS, 1, sProcessSize );
59 std::ifstream procName( fn.c_str() );
60 if( procName.is_open() ){
62 while( procName.good() ){
63 getline( procName, line );
65 for( i = 0; i < 3; ++i ){
66 if( MyString::npos != line.find( dataSect[ i ].first ) ) break;
68 if( i >= 3 || dataSect[ i ].second == true ) continue;
69 dataSect[ i ].second = true;
70 if( !procName.good() )return;
71 getline( procName, line );
72 takeSegmentSnapshot( line );
77 //class definition of snapshotStack.....
78 //declaration of constructor....
79 snapshotStack::snapshotStack(){
80 SnapshotGlobalSegments();
84 snapshotStack::~snapshotStack(){
87 int snapshotStack::backTrackBeforeStep(int seqindex) {
89 if (stack->index<=seqindex) {
91 rollBack(stack->snapshotid);
94 struct stackEntry *tmp=stack;
100 void snapshotStack::snapshotStep(int seqindex) {
101 struct stackEntry *tmp=(struct stackEntry *)MYMALLOC(sizeof(struct stackEntry));
104 tmp->snapshotid=takeSnapshot();