1 #define MYBINARYNAME "model"
2 #define MYLIBRARYNAME "libmodel.so"
3 #define MYALLOCNAME "libmymemory.so"
4 #define PROCNAME "/proc/*/maps"
7 #include "snapshot-interface.h"
11 #include <sys/types.h>
16 /*This looks like it might leak memory... Subramanian should fix this. */
18 typedef std::basic_stringstream< char, std::char_traits< char >, MyAlloc< char > > MyStringStream;
19 std::vector< MyString, MyAlloc< MyString> > splitString( MyString input, char delim ){
20 std::vector< MyString, MyAlloc< MyString > > splits;
21 MyStringStream ss( input );
23 while( std::getline( ss, item, delim ) ){
24 splits.push_back( item );
29 bool checkPermissions( MyString permStr ){
30 return permStr.find("w") != MyString::npos;
32 static void takeSegmentSnapshot( const MyString & lineText ){
33 std::vector< MyString, MyAlloc< MyString > > firstSplit = splitString( lineText, ' ' );
34 if( checkPermissions( firstSplit[ 1 ] ) ){
35 std::vector< MyString, MyAlloc< MyString > > secondSplit = splitString( firstSplit[ 0 ], '-' );
36 size_t val1 = 0, val2 = 0;
37 sscanf( secondSplit[ 0 ].c_str(), "%zx", &val1 );
38 sscanf( secondSplit[ 1 ].c_str(), "%zx", &val2 );
39 size_t len = ( val2 - val1 ) / PAGESIZE;
41 addMemoryRegionToSnapShot( ( void * )val1, len );
45 void SnapshotGlobalSegments(){
46 MyString fn = PROCNAME;
47 static char sProcessSize[ 12 ] = { 0 };
48 std::pair< const char *, bool > dataSect[ 3 ];
49 dataSect[ 0 ] = std::make_pair( MYBINARYNAME, false );
50 dataSect[ 1 ] = std::make_pair( MYLIBRARYNAME, false );
51 dataSect[ 2 ] = std::make_pair( MYALLOCNAME, false );
52 static pid_t sProcID = 0;
55 sprintf( sProcessSize, "%d", sProcID );
57 fn.replace( REPLACEPOS, 1, sProcessSize );
58 std::ifstream procName( fn.c_str() );
59 if( procName.is_open() ){
61 while( procName.good() ){
62 getline( procName, line );
64 for( i = 0; i < 3; ++i ){
65 if( MyString::npos != line.find( dataSect[ i ].first ) ) break;
67 if( i >= 3 || dataSect[ i ].second == true ) continue;
68 dataSect[ i ].second = true;
69 if( !procName.good() )return;
70 getline( procName, line );
71 takeSegmentSnapshot( line );
76 //class definition of snapshotStack.....
77 //declaration of constructor....
78 snapshotStack::snapshotStack(){
79 SnapshotGlobalSegments();
80 AddUserHeapToSnapshot();
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 *)malloc(sizeof(struct stackEntry));
104 tmp->snapshotid=takeSnapshot();