コード例 #1
0
void torrent_handle::force_reannounce(
    boost::posix_time::time_duration duration) const
{
    async_call(&torrent::force_tracker_request, aux::time_now()
               + seconds(duration.total_seconds()), -1);
}
コード例 #2
0
ファイル: torrent_handle.cpp プロジェクト: ABuus/libtorrent
	void torrent_handle::force_reannounce(
		boost::posix_time::time_duration duration) const
	{
		INVARIANT_CHECK;
		TORRENT_ASYNC_CALL1(force_tracker_request, time_now() + seconds(duration.total_seconds()));
	}
コード例 #3
0
 unsigned int NetworkActivity::getCurrentTime()
 {
     boost::posix_time::time_duration const diff = boost::posix_time::microsec_clock::local_time() - profilingStart_;
     return diff.total_microseconds();
 }
コード例 #4
0
ファイル: control-from-console.cpp プロジェクト: acfr/snark
inertial::value::value( boost::posix_time::time_duration decay, unsigned int maximum ) : decay_( decay.total_microseconds() ), maximum_( maximum ), value_( 0 ) {}
コード例 #5
0
 static double ToSeconds(const boost::posix_time::time_duration &diff) {
     return diff.total_seconds() + diff.total_nanoseconds() / 1e9;
 }
コード例 #6
0
namespace __fwrite__
{

    bool record_thread_running = true;
    bool datagen_thread_running = true;

    #if !defined(WITH_BOOST_TIME)
    timespec ts_beg, ts_end;
    #else
    boost::posix_time::ptime start_time, stop_time;
    boost::posix_time::time_duration time_duration;
    #endif

    vector<long> v_fTime_s;
    vector<long> v_fTime_us;
    vector<float> v_fDifftime;
    float f_DT_s = 0.;

    std::string string_buffer_1, string_buffer_2;
    std::string *active_buffer = &string_buffer_1;

    boost::condition_variable record_trigger;
    boost::mutex mutex;

    const int NUM_LINES = 2e+5;
    bool datagen_done = false;

    /* threat functions*/
    void datagen_thread_loop(void)
    {
        ostringstream testline;

        /* create testdata*/
        int jj=0;
        for(int ii=0; ii < 8*8-1; ii++) //64 = 63 chars + end line
        {
            if(++jj > 9) jj = 0;
            testline << jj;
        }
        testline << "\n";

        jj=0;
        while(record_thread_running && jj < NUM_LINES)
        {
    #if !defined(WITH_BOOST_TIME)
            clock_gettime(CLOCK_MONOTONIC, &ts_beg); // http://linux.die.net/man/3/clock_gettime
    #else
            start_time = boost::posix_time::microsec_clock::local_time();
    #endif

            // ********************************* //
            *active_buffer += testline.str().c_str();
            if(4*1024 < active_buffer->length()) //write 4 kbyte blocks
            {
                record_trigger.notify_all();
            }
            // ********************************* //

    #if !defined(WITH_BOOST_TIME)
            clock_gettime(CLOCK_MONOTONIC, &ts_end);
            v_fTime_s.push_back(ts_end.tv_sec);
            v_fTime_us.push_back(ts_end.tv_nsec/1e+3);
            v_fDifftime.push_back((ts_end.tv_sec - ts_beg.tv_sec)  + (ts_end.tv_nsec - ts_beg.tv_nsec) / 1e9);
            f_DT_s = (ts_end.tv_sec - ts_beg.tv_sec)  + (ts_end.tv_nsec - ts_beg.tv_nsec) / 1e9;
    #else
            stop_time = boost::posix_time::microsec_clock::local_time();
            time_duration = (stop_time - start_time);
            v_fTime_s.push_back( (stop_time-boost::posix_time::from_time_t(0)).total_seconds() );
            v_fTime_us.push_back( (stop_time-boost::posix_time::from_time_t(0)).fractional_seconds() );
            v_fDifftime.push_back( time_duration.total_seconds()+ time_duration.fractional_seconds()/ 1e6);
            f_DT_s = (time_duration.total_seconds()+ time_duration.fractional_seconds()/ 1e6);
    #endif
    #if defined(DEBUG)
            if(0.5 < 1.e+3*f_DT_s) // log only values above 0.5 ms
            {
                cout << "Line " << jj << " of " << NUM_LINES << ":"
                     << "\t" << v_fTime_s.back() << "." << v_fTime_us.back() << "s: "
                     << "\tdT: " << fixed << 1.e+3*f_DT_s << " ms"
                     << endl;
            }
    #endif
            boost::this_thread::sleep(boost::posix_time::microseconds(4*1e+6*f_DT_s)); //about 50% CPU load
            jj++;
        }//while

        datagen_done = true;
    }

    void record_thread_loop(void)
    {
        int buffer_no = 0;

        /* open log file*/
        FILE *logfile = fopen("fwrite_thread_testlog.log","w");
        BOOST_REQUIRE_MESSAGE(logfile != NULL, "Could not open logfile!");

        boost::unique_lock<boost::mutex> lock(mutex);

        while(record_thread_running)
        {
            record_trigger.wait(lock);
            if(buffer_no < 2)
            {
                active_buffer = &string_buffer_2;
                fwrite(string_buffer_1.c_str(), sizeof(char), string_buffer_1.length(), logfile);
                string_buffer_1.clear();
                buffer_no = 2;
            }
            else
            {
                active_buffer = &string_buffer_1;
                fwrite(string_buffer_2.c_str(), sizeof(char), string_buffer_2.length(), logfile);
                string_buffer_2.clear();
                buffer_no = 1;
            }
        }
        fclose(logfile);
    }
}; //namespace __fwrite__
コード例 #7
0
ファイル: io_impl.cpp プロジェクト: 13572293130/uhd
static UHD_INLINE double from_time_dur(const pt::time_duration &time_dur){
    return 1e-6*time_dur.total_microseconds();
}
コード例 #8
0
boost::posix_time::ptime DateTimeEventsManager::GetEventStartTime(const DateTimeEvent* pEvent) const
{
	boost::posix_time::ptime resultTime;

	switch (pEvent->GetType())
	{
	case DateTimeEvent::typeOnce:
		{
			boost::posix_time::ptime scheduledTime(pEvent->GetDate(), pEvent->GetTime());
			const boost::posix_time::time_duration d = boost::posix_time::second_clock::local_time() - scheduledTime;

			// This may happen after player startup if there is an event with date/time in the past.
			if (d.total_seconds() > 1)
			{
				scheduledTime = boost::posix_time::not_a_date_time;
			}

			resultTime = scheduledTime;
		}
		break;

	case DateTimeEvent::typeDaily:
		{
			boost::posix_time::ptime startTime(boost::gregorian::day_clock::local_day(), pEvent->GetTime());
			
			if (boost::posix_time::second_clock::local_time() >= startTime)
				startTime += boost::gregorian::days(1);

			resultTime = startTime;
		}
		break;

	case DateTimeEvent::typeWeekly:
		{
			boost::gregorian::date dateNow(boost::gregorian::day_clock::local_day());

			int currentDayOfWeek = dateNow.day_of_week().as_number();

			if (currentDayOfWeek == 0)
				currentDayOfWeek = 7;

			--currentDayOfWeek; // Format 0 = Mon, 1 = Tue, .. , 6 = Sun
			
			boost::gregorian::date weekStartDate =
				dateNow - boost::gregorian::date_duration(currentDayOfWeek);

			std::vector<boost::posix_time::ptime> times;

			for (int i = 0; i < 7; ++i)
				if (pEvent->GetWeekDays() & (1 << i))
				{
					boost::posix_time::ptime startTime(
						weekStartDate + boost::gregorian::date_duration(i), pEvent->GetTime());

					if (boost::posix_time::second_clock::local_time() >= startTime)
						startTime += boost::gregorian::days(7);

					times.push_back(startTime);
				}

			std::sort(times.begin(), times.end());

			_ASSERTE(!times.empty());
			resultTime = times[0];
		}
		break;
	}

	return resultTime;
}
コード例 #9
0
ファイル: curl.cpp プロジェクト: reaper/libfreelan
void curl::set_connect_timeout(const boost::posix_time::time_duration& timeout)
{
    set_option(CURLOPT_CONNECTTIMEOUT_MS, timeout.total_milliseconds());
}
コード例 #10
0
void AutomaticGraphicsLevelManager::averageTimePerFrameUpdated(const boost::posix_time::time_duration timePerFrame)
{
	//Convert microseconds per frame to fps.
	checkFps(1000000.0f / timePerFrame.total_microseconds());
}
コード例 #11
0
ファイル: velodyne-thin.cpp プロジェクト: WangFei-DUT/snark
void run( S* stream )
{
    static const unsigned int timeSize = 12;
    boost::mt19937 generator;
    boost::uniform_real< float > distribution( 0, 1 );
    boost::variate_generator< boost::mt19937&, boost::uniform_real< float > > random( generator, distribution );
    comma::uint64 count = 0;
    comma::uint64 dropped_count = 0;
    double compression = 0;
    velodyne::packet packet;
    comma::signal_flag isShutdown;
    velodyne::scan_tick tick;
    comma::uint32 scan_id = 0;
    while( !isShutdown && std::cin.good() && !std::cin.eof() && std::cout.good() && !std::cout.eof() )
    {
        const char* p = velodyne::impl::stream_traits< S >::read( *stream, sizeof( velodyne::packet ) );
        if( p == NULL ) { break; }
        ::memcpy( &packet, p, velodyne::packet::size );
        if( tick.is_new_scan( packet ) ) { ++scan_id; } // quick and dirty
        boost::posix_time::ptime timestamp = stream->timestamp();
        if( scan_rate ) { scan.thin( packet, *scan_rate, angularSpeed( packet ) ); }
        if( !scan_rate || !scan.empty() )
        {
            if( focus ) { velodyne::thin::thin( packet, *focus, *db, angularSpeed( packet ), random ); }
            if( rate ) { velodyne::thin::thin( packet, *rate, random ); }
        }
        const boost::posix_time::ptime base( snark::timing::epoch );
        const boost::posix_time::time_duration d = timestamp - base;
        comma::int64 seconds = d.total_seconds();
        comma::int32 nanoseconds = static_cast< comma::int32 >( d.total_microseconds() % 1000000 ) * 1000;
        if( outputRaw ) // real quick and dirty
        {
            static boost::array< char, 16 + timeSize + velodyne::packet::size + 4 > buf;
            static const boost::array< char, 2 > start = {{ -78, 85 }}; // see QLib::Bytestreams::GetDefaultStartDelimiter()
            static const boost::array< char, 2 > end = {{ 117, -97 }}; // see QLib::Bytestreams::GetDefaultStartDelimiter()
            ::memcpy( &buf[0], &start[0], 2 );
            ::memcpy( &buf[0] + buf.size() - 2, &end[0], 2 );
            ::memcpy( &buf[0] + 16, &seconds, 8 );
            ::memcpy( &buf[0] + 16 + 8, &nanoseconds, 4 );
            ::memcpy( &buf[0] + 16 + 8 + 4, &packet, velodyne::packet::size );
            if( publisher ) { publisher->write( &buf[0], buf.size() ); }
            else if( publisher_udp_socket ) { publisher_udp_socket->send_to( boost::asio::buffer( &buf[0], buf.size() ), udp_destination ); }
            else { std::cout.write( &buf[0], buf.size() ); }
        }
        else
        {
            // todo: certainly rewrite with the proper header using comma::packed
            static char buf[ timeSize + sizeof( comma::uint16 ) + velodyne::thin::maxBufferSize ];
            comma::uint16 size = velodyne::thin::serialize( packet, buf + timeSize + sizeof( comma::uint16 ), scan_id );
            bool empty = size == ( sizeof( comma::uint32 ) + 1 ); // todo: atrocious... i.e. packet is not empty; refactor!!!
            if( !empty )
            {
                size += timeSize;
                ::memcpy( buf, &size, sizeof( comma::uint16 ) );
                size += sizeof( comma::uint16 );
                ::memcpy( buf + sizeof( comma::uint16 ), &seconds, sizeof( comma::int64 ) );
                ::memcpy( buf + sizeof( comma::uint16 ) + sizeof( comma::int64 ), &nanoseconds, sizeof( comma::int32 ) );
                if( publisher ) { publisher->write( buf, size ); }
                else if( publisher_udp_socket ) { publisher_udp_socket->send_to( boost::asio::buffer( buf, size ), udp_destination ); }
                else { std::cout.write( buf, size ); }
            }
            else
            {
                ++dropped_count;
            }
            if( verbose )
            {
                ++count;
                compression = 0.9 * compression + 0.1 * ( empty ? 0.0 : double( size + sizeof( comma::int16 ) ) / ( velodyne::packet::size + timeSize ) );
                if( count % 10000 == 0 ) { std::cerr << "velodyne-thin: processed " << count << " packets; dropped " << ( double( dropped_count ) * 100. / count ) << "% full packets; compression rate " << compression << std::endl; }
            }
        }
    }
    if( publisher ) { publisher->close(); }
    std::cerr << "velodyne-thin: " << ( isShutdown ? "signal received" : "no more data" ) << "; shutdown" << std::endl;
}
コード例 #12
0
ファイル: TimeClient.hpp プロジェクト: eidolonsystems/beam
 /*!
   \param time The time point to truncate.
   \param unit The unit of time to truncate the time point to.
   \return The time point truncated to the specified <i>unit</i>.
 */
 inline boost::posix_time::ptime Truncate(const boost::posix_time::ptime& time,
     boost::posix_time::time_duration unit) {
   return time - boost::posix_time::microseconds(
     time.time_of_day().total_microseconds() % unit.total_microseconds());
 }
コード例 #13
0
ファイル: util.cpp プロジェクト: glftpd/ebftpd
double CalculateSpeed(long long bytes, const boost::posix_time::time_duration& duration)
{
  double seconds = duration.total_microseconds() / 1000000.0;
  return seconds == 0.0 ? bytes : bytes / seconds;
}
コード例 #14
0
ファイル: cache.hpp プロジェクト: bchoi/pcp-pmda-cpp
/**
 * @brief Purge cache entries that have not been active for some time.
 *
 * @param  indom   Instance domain to purge entries for.
 * @param  recent  All entries that have not been active within this interval
 *                 will be purged.
 *
 * @throw  pcp::exception  On error.
 *
 * @return The number of items purged.
 *
 * @see pmdaCachePurge
 */
inline size_t purge(const pmInDom indom, const boost::posix_time::time_duration &recent)
{
    return purge(indom, recent.total_seconds());
}
コード例 #15
0
ファイル: torrent_handle.cpp プロジェクト: aresch/libtorrent
	void torrent_handle::force_reannounce(
		boost::posix_time::time_duration duration) const
	{
		TORRENT_ASYNC_CALL2(force_tracker_request, aux::time_now()
			+ seconds(duration.total_seconds()), -1);
	}
コード例 #16
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;
}
コード例 #17
0
ファイル: hash.hpp プロジェクト: llawall/protean
 inline boost::uint64_t hash_value(const boost::posix_time::time_duration& value, boost::uint64_t seed)
 {
     return hash_value((boost::int64_t)value.total_milliseconds(), seed);
 }