1 #include "snapshot-interface.h"
10 #define MYBINARYNAME "model"
11 #define MYLIBRARYNAME "libmodel.so"
12 #define MYALLOCNAME "libmymemory.so"
13 #define PROCNAME "/proc/*/maps"
17 snapshotStack * snapshotObject;
19 /*This looks like it might leak memory... Subramanian should fix this. */
21 typedef std::basic_stringstream< char, std::char_traits< char >, MyAlloc< char > > MyStringStream;
22 std::vector< MyString, MyAlloc< MyString> > splitString( MyString input, char delim ){
23 std::vector< MyString, MyAlloc< MyString > > splits;
24 MyStringStream ss( input );
26 while( std::getline( ss, item, delim ) ){
27 splits.push_back( item );
32 bool checkPermissions( MyString permStr ){
33 return permStr.find("w") != MyString::npos;
35 static void takeSegmentSnapshot( const MyString & lineText ){
36 std::vector< MyString, MyAlloc< MyString > > firstSplit = splitString( lineText, ' ' );
37 if( checkPermissions( firstSplit[ 1 ] ) ){
38 std::vector< MyString, MyAlloc< MyString > > secondSplit = splitString( firstSplit[ 0 ], '-' );
39 size_t val1 = 0, val2 = 0;
40 sscanf( secondSplit[ 0 ].c_str(), "%zx", &val1 );
41 sscanf( secondSplit[ 1 ].c_str(), "%zx", &val2 );
42 size_t len = ( val2 - val1 ) / PAGESIZE;
44 addMemoryRegionToSnapShot( ( void * )val1, len );
48 void SnapshotGlobalSegments(){
49 MyString fn = PROCNAME;
50 static char sProcessSize[ 12 ] = { 0 };
51 std::pair< const char *, bool > dataSect[ 3 ];
52 dataSect[ 0 ] = std::make_pair( MYBINARYNAME, false );
53 dataSect[ 1 ] = std::make_pair( MYLIBRARYNAME, false );
54 dataSect[ 2 ] = std::make_pair( MYALLOCNAME, false );
55 static pid_t sProcID = 0;
58 sprintf( sProcessSize, "%d", sProcID );
60 fn.replace( REPLACEPOS, 1, sProcessSize );
61 std::ifstream procName( fn.c_str() );
62 if( procName.is_open() ){
64 while( procName.good() ){
65 getline( procName, line );
67 for( i = 0; i < 3; ++i ){
68 if( MyString::npos != line.find( dataSect[ i ].first ) ) break;
70 if( i >= 3 || dataSect[ i ].second == true ) continue;
71 dataSect[ i ].second = true;
72 if( !procName.good() )return;
73 getline( procName, line );
74 takeSegmentSnapshot( line );
79 //class definition of snapshotStack.....
80 //declaration of constructor....
81 snapshotStack::snapshotStack(){
82 SnapshotGlobalSegments();
86 snapshotStack::~snapshotStack(){
89 int snapshotStack::backTrackBeforeStep(int seqindex) {
91 if (stack->index<=seqindex) {
93 rollBack(stack->snapshotid);
96 struct stackEntry *tmp=stack;
102 void snapshotStack::snapshotStep(int seqindex) {
103 struct stackEntry *tmp=(struct stackEntry *)malloc(sizeof(struct stackEntry));
106 tmp->snapshotid=takeSnapshot();