Beispiel #1
0
		boost::posix_time::time_duration Service::GetTimeOfDay( const boost::posix_time::time_duration& value )
		{
			return
				value >= DAY_DURATION ?
				time_duration(value.hours() % 24, value.minutes(), value.seconds()) :
				value
			;
		}
Beispiel #2
0
 //! Convert a time_duration to a tm structure truncating any fractional seconds and zeroing fields for date components 
 inline
 std::tm to_tm(const boost::posix_time::time_duration& td) {
   std::tm timetm = {};
   timetm.tm_hour = date_time::absolute_value(td.hours());
   timetm.tm_min = date_time::absolute_value(td.minutes());
   timetm.tm_sec = date_time::absolute_value(td.seconds());
   timetm.tm_isdst = -1; // -1 used when dst info is unknown
   return timetm;
 }
Beispiel #3
0
    std::string durationToStr(const boost::posix_time::time_duration &duration)
    {
        std::stringstream ss;

        ss << std::setfill('0') << std::setw(2) << duration.hours() << ":"
           << std::setfill('0') << std::setw(2) << duration.minutes() << ":"
           << std::setfill('0') << std::setw(2) << duration.seconds();
        return ss.str();
    }
 //! Convert a time_duration to a tm structure truncating any fractional seconds and zeroing fields for date components
 inline
 std::tm to_tm(const boost::posix_time::time_duration& td) {
   std::tm timetm;
   std::memset(&timetm, 0, sizeof(timetm));
   timetm.tm_hour = static_cast<int>(date_time::absolute_value(td.hours()));
   timetm.tm_min = static_cast<int>(date_time::absolute_value(td.minutes()));
   timetm.tm_sec = static_cast<int>(date_time::absolute_value(td.seconds()));
   timetm.tm_isdst = -1; // -1 used when dst info is unknown
   return timetm;
 }
value_visitor::result_type
value_visitor::operator()(const date_t& value)
{
	static const date_t EPOCH(boost::gregorian::date(1970, 1, 1));
	const boost::posix_time::time_duration duration = value - EPOCH;
	if (duration.seconds() == 0 && duration.fractional_seconds() == 0)
	{
		push_back<std::int8_t>('K');
		push_back<std::int32_t>(duration.total_seconds() / 60);
	}
	else
	{
		push_back<std::int8_t>('J');
		push_back<std::int64_t>(duration.total_milliseconds());
	}
}
Beispiel #6
0
string current_time_string()  {

  stringstream sstream;
  
  boost::posix_time::ptime now = boost::posix_time::
    microsec_clock::local_time();

    const boost::posix_time::time_duration td = now.time_of_day();
    const long hours        = td.hours();
    const long minutes      = td.minutes();
    const long seconds      = td.seconds();
    const long milliseconds = td.total_milliseconds() -
                              ((hours * 3600 + minutes * 60 + seconds) *
			       1000);
    char buf[40];
    sprintf(buf, "%02ld:%02ld:%02ld.%03ld", 
        hours, minutes, seconds, milliseconds);

    return string(buf);
}
Beispiel #7
0
int main(int argc, const char* argv[])
{
	properties.parse_args(argc, argv);

	stldb::timer_configuration config;
	config.enabled_percent = properties.getProperty("timing_percent", 0.0);
	config.report_interval_seconds = properties.getProperty("report_freq", 60);
	config.reset_after_print = properties.getProperty("report_reset", true);
	stldb::timer::configure( config );
	stldb::tracing::set_trace_level(stldb::fine_e);

	const int thread_count = properties.getProperty("threads", 4);
	const int loopsize = properties.getProperty("loopsize", 100);
	const int ops_per_txn = properties.getProperty("ops_per_txn", 10);

	g_db_dir = properties.getProperty<std::string>("rootdir", std::string("."));
	g_checkpoint_dir = g_db_dir + "/checkpoint";
	g_log_dir = g_db_dir + "/log";

	g_num_db = properties.getProperty("databases", 4);
	g_maps_per_db = properties.getProperty("maps_per_db", 4);
	g_max_key = properties.getProperty("max_key", 10000);
	g_avg_val_length = properties.getProperty("avg_val_length", 1000);
	g_max_wait = boost::posix_time::millisec(properties.getProperty("max_wait", 10000));
	g_checkpoint_interval = boost::posix_time::millisec(properties.getProperty("checkpoint_interval", 0));
	g_invalidation_interval = boost::posix_time::millisec(properties.getProperty("invalidation_interval", 0));

	// The loop that the running threads will execute
	test_loop loop(loopsize);
	CRUD_transaction main_op(ops_per_txn);
	loop.add( &main_op, 100 );

	// Start the threads which are going to run operations:
	boost::thread **workers = new boost::thread *[thread_count];
	for (int i=0; i<thread_count; i++) {
		workers[i] = new boost::thread( loop );
	}
	// start a thread which does periodic checkpointing
	boost::thread *checkpointor = NULL, *invalidator = NULL;
	if ( g_checkpoint_interval.seconds() > 0 ) {
		checkpointor = new boost::thread( checkpoint_operation(g_checkpoint_interval.seconds()) );
	}
	if ( g_invalidation_interval.seconds() > 0 ) {
		// start a thread which does periodic invalidation, forcing recovery to be done
		invalidator = new boost::thread( set_invalid_operation(g_invalidation_interval.seconds()) );
	}

	// Support the option of writing to an indicator file once all databses have been opened,
	// confirming to watching processes/scripts that database open/recovery has finished.
	std::string indicator_filename = properties.getProperty<std::string>("indicator_filename", std::string());
	if (!indicator_filename.empty()) {
		for (int i=0; i<g_num_db; i++) {
			shared_lock<boost::shared_mutex> lock;
			getDatabase(i, lock);
		}
		std::ofstream indf(indicator_filename.c_str());
	}
	
	// now await their completion
	for (int i=0; i<thread_count; i++) {
		workers[i]->join();
		delete workers[i];
	}

	// close the databases
	for (int i=0; i<g_num_db; i++) {
		closeDatabase(i);
	}

	// final print timing stats (if requested)
	if (config.enabled_percent > 0.0)
		stldb::time_tracked::print(std::cout, true);

	return 0;
}