Permalink
Browse files

Fixed bugs in stringstream execution

Fixed bug in error logging function.
Added start time and execution time to error log
  • Loading branch information...
1 parent 7ee1821 commit 2013b28ff11c59c516ea8c6cf8a029a77bfe0ea1 @kpmooney committed May 24, 2012
Showing with 11 additions and 0 deletions.
  1. +11 −0 particle_filter.cpp
View
@@ -61,6 +61,7 @@ void log_error(string message)
pthread_mutex_lock( &mutex1 );
error_file.open("error.log", ios::app);
error_file << message << endl;
+ error_file.close();
pthread_mutex_unlock( &mutex1 );
}
@@ -694,12 +695,16 @@ int main(int argc, char *argv[])
cout << "Program requires one file name arguement." << endl;
exit(1);
}
+ int time0 = clock();
int numCPU = sysconf( _SC_NPROCESSORS_ONLN );
cout << "I detect " << numCPU << " CPUs..." << endl;
string filename = argv[1];
cout << "Loading data from file " << filename << "..." << endl;
+ time_t rawtime;
+ time( &rawtime );
stringstream ss;
+ ss << "Program called at " << ctime(&rawtime);
ss << "Detected " << numCPU << " CPUs...\n";
ss << "Loading data from file " << filename << "..." << endl;
log_error( ss.str() );
@@ -914,6 +919,12 @@ int main(int argc, char *argv[])
predicted_voltage(V_p, V_e, I, particles, p);
cout << "Measured: " << V_m[ t.size() - 1] << endl;
cout << "Predicted: " << V_p << endl;
+ cout << "Program took " << float(clock() - time0) / CLOCKS_PER_SEC
+ << " sec to run." << endl;
+ ss.str( string() );
+ ss << "Program took " << float(clock() - time0) / CLOCKS_PER_SEC
+ << " sec to run." << endl;
+ log_error( ss.str() );
pthread_exit(NULL);
return 0;

0 comments on commit 2013b28

Please sign in to comment.