void do_wait(const Duration& timeout, pdalboost::system::error_code& ec)
 {
   ::timeval tv;
   tv.tv_sec = timeout.total_seconds();
   tv.tv_usec = timeout.total_microseconds() % 1000000;
   socket_ops::select(0, 0, 0, 0, &tv, ec);
 }
Exemplo n.º 2
0
int COpenTest::delete_random(BonTimer &timer)
{
  random_sort(timer.random_source);
  timer.start();
  int i;
  Duration dur;
  for(i = 0; i < m_number; i++)
  {
    dur.start();
    if(unlink(m_file_names[i]))
    {
      fprintf(stderr, "Can't delete file %s\n", m_file_names[i]);
      return -1;
    }
    if(m_sync && m_sync_dir)
    {
      if(fsync(m_directoryHandles[m_dirIndex[i]]))
      {
        fprintf(stderr, "Can't sync directory, turning off dir-sync.\n");
        m_sync_dir = false;
      }
    }
    dur.stop();
  }
  if(m_number_directories > 1)
  {
    char buf[6];
    for(i = 0; i < m_number_directories; i++)
    {
      sprintf(buf, "%05d", i);
      if(m_sync)
      {
        close(m_directoryHandles[i]);
      }
      if(rmdir(buf))
      {
        io_error("rmdir");
        return -1;
      }
    }
  }
  else
  {
    if(m_sync)
    {
      close(m_directoryHandles[0]);
    }
  }
  if(chdir("..") || rmdir(m_dirname))
  {
    io_error("rmdir");
    return -1;
  }
  delete m_dirname;
  m_dirname = NULL;
  sync();
  timer.stop_and_record(DelRand);
  timer.add_latency(DelRand, dur.getMax());
  return 0;
}
Exemplo n.º 3
0
void Odometry_new::run()
{
  scout_position = node.advertise< ::messages::ScoutPosition>(name+"/posn", 1000);
  double last_time = Time::now().toSec();
  double loop_time, current_time;

  // Reset encoders.
  encoders->reset();

  //Rate r(LOOP_RATE); 
  Duration r = Duration(LOOP_TIME);

  motors->set_sides(-50,50, MOTOR_ABSOLUTE);

  while(ok())
  {
    current_time = Time::now().toSec();
    loop_time = current_time - last_time;
    last_time = current_time;

    get_position(loop_time);
    ROS_INFO("loop time %f", loop_time);

    position.name = name;
    position.x = scout_pos->x;
    position.y = scout_pos->y;
    position.theta = scout_pos->theta;
    scout_position.publish(position);

    ROS_INFO("scout is at %f %f theta: %f", position.x, position.y, position.theta);

    r.sleep();
  }
}
Exemplo n.º 4
0
void Lilypond::addNote(const LNote& lnote)
      {
      createMeasure();

      Segment* segment = new Segment(measure);
      segment->setSubtype(SegChordRest);
      segment->setTick(tick);
      segment->setParent(measure);
      measure->add(segment);

      Chord* chord = new Chord(score);
      chord->setTrack(staff->idx() * VOICES);
      chord->setParent(segment);
      Duration d;
      d.setVal(lnote.len);
      chord->setDurationType(d);

      segment->add(chord);

      Note* note = new Note(score);
      note->setPitch(lnote.pitch);
      note->setTpcFromPitch();
      note->setParent(chord);
      note->setTrack(staff->idx() * VOICES);
      chord->add(note);
      tick += lnote.len;
      }
Exemplo n.º 5
0
bool Shader::compile(const char* source)
{
    _compilationDuration = 0;
    GlError error;

    if (source[0] == '\0')
    {
        _lastCompilationLog = "Shader source is empty!";
        return false;
    }

    glShaderSource(_shaderId, 1, &source, NULL);
    if (error.hasOccured())
    {
        _lastCompilationLog = error.toString("Error while attaching source to shader (glShaderSource)");
        return false;
    }

    Duration duration;
    glCompileShader(_shaderId);
    _compilationDuration= duration.elapsed();
    if (error.hasOccured())
    {
        _lastCompilationLog = error.toString("Error while compiling shader (glCompileShader)");
        return false;
    }

    GLint compilationSucceeded = GL_FALSE;
    glGetShaderiv(_shaderId, GL_COMPILE_STATUS, &compilationSucceeded);

    extractInfoLog();

    return compilationSucceeded == GL_TRUE;
}
Exemplo n.º 6
0
void
Clock::Begin (TimeSpan parentTime)
{
	//printf ("clock %p (%s) begin\n", this, GetName ());
	emit_completed = false;
	has_completed = false;
	was_stopped = false;

	/* we're starting.  initialize our current_time field */
	SetCurrentTime ((parentTime - root_parent_time - timeline->GetBeginTime ()) * timeline->GetSpeedRatio());

	Duration d = GetNaturalDuration ();
	if (d.HasTimeSpan ()) {
		if (d.GetTimeSpan() == 0) {
			progress = 1.0;
		}
		else {
			progress = (double)current_time / d.GetTimeSpan();
			if (progress > 1.0)
				progress = 1.0;
		}
	}
	else
		progress = 0.0;

	CalculateFillTime ();

	SetClockState (Clock::Active);

	// force the time manager to tick the clock hierarchy to wake it up
	time_manager->NeedClockTick ();
}
  void generate()
  {
    watch.start();

    while (true) {
      Duration elapsed = watch.elapsed();

      if (duration.isSome() && elapsed >= duration.get()) {
        LOG(INFO) << "LoadGenerator generated " << messages
                  << " messages in " << elapsed << " (throughput = "
                  << (messages / elapsed.secs()) << " messages/sec)";

        LOG(INFO) << "Stopping LoadGenerator and scheduler driver";

        terminate(self());
        driver->stop();
        return;
      }

      Stopwatch reconcile;
      reconcile.start();

      driver->reconcileTasks(vector<TaskStatus>());

      messages++;

      // Compensate for the driver call overhead.
      os::sleep(std::max(
          Duration::zero(),
          Seconds(1) / qps - reconcile.elapsed()));
    }
  }
Exemplo n.º 8
0
////////////////////////////////////////////////////////////////////////////////
// Lexer::Type::duration
//   <ISO8106p> | <Duration>
bool Lexer::isDuration (std::string& token, Lexer::Type& type)
{
  std::size_t marker = _cursor;
  ISO8601p iso;

  std::string extractedToken;
  Lexer::Type extractedType;
  if (isOperator(extractedToken, extractedType))
  {
    _cursor = marker;
    return false;
  }

  marker = 0;
  if (iso.parse (_text.substr (_cursor), marker))
  {
    type = Lexer::Type::duration;
    token = _text.substr (_cursor, marker);
    _cursor += marker;
    return true;
  }

  Duration dur;
  if (dur.parse (_text.substr (_cursor), marker))
  {
    type = Lexer::Type::duration;
    token = _text.substr (_cursor, marker);
    _cursor += marker;
    return true;
  }

  return false;
}
Exemplo n.º 9
0
TEST(DurationTest, AssignSubtract) {
    Duration d = Duration::fromSeconds(5);
    Duration d2 = Duration::fromSeconds(10);
    d -= d2;

    EXPECT_EQ(-5, d.toIntegerSeconds());
    EXPECT_EQ(10, d2.toIntegerSeconds());
}
Exemplo n.º 10
0
TEST(DurationTest, AssignAdd) {
    Duration d = Duration::fromSeconds(5);
    Duration d2 = Duration::fromSeconds(2);
    d += d2;

    EXPECT_EQ(7, d.toIntegerSeconds());
    EXPECT_EQ(2, d2.toIntegerSeconds());
}
void ElevationMapping::resetMapUpdateTimer()
{
  mapUpdateTimer_.stop();
  Duration periodSinceLastUpdate = Time::now() - map_.getTimeOfLastUpdate();
  if (periodSinceLastUpdate > maxNoUpdateDuration_) periodSinceLastUpdate.fromSec(0.0);
  mapUpdateTimer_.setPeriod(maxNoUpdateDuration_ - periodSinceLastUpdate);
  mapUpdateTimer_.start();
}
Exemplo n.º 12
0
void TestUnpackRowLength::TestAndOutput(int aNumIterations, FILE* aFile)
{
  TestGLRunner tgr(this);
  Duration d = tgr.Run(aNumIterations);
  OutputTestName(aFile);
  fprintf(aFile, ",%d,%d,%d,%d,%d,%.0f\n", mPixelSize, mTextureSize, mAlignment,
          mUploadWidth, mOffset, d.ToMilliseconds());
}
Exemplo n.º 13
0
int main( int argc, char *argv[] )
{
	const Clock::time_point start = Clock::now();

	std::cout << "called with: " << std::endl << "\t";
	for ( int i = 0; i < argc; ++i ) {
		std::cout << argv[i] << " ";
	}
	std::cout << std::endl;

	po::options_description desc( "testRDIS options" );

	try {
		addOptions( desc );

		po::variables_map options;
		po::store( po::parse_command_line( argc, argv, desc ), options );

		po::notify( options );

		if ( options.count( "help" ) ) {
			std::cout << desc << std::endl;

		} else {
			std::vector<string> files;

			if ( options.count( "file" ) ) {
				// get the set of files to optimize
				const std::vector<string> tmpf =
						options["file"].as< std::vector<string> >();
				files.assign( tmpf.begin(), tmpf.end() );
			}

			if ( files.empty() ) {
				// run the pre-defined debug tests
				run_debug_test( options );

			} else {
				// optimize each input polynomial
				for ( string file : files ) {
					optimize_poly( file, options );
				}
			}
		}

	} catch ( const std::exception & e ) {
		std::cerr << "Exception occurred in main: \n\t" << e.what() << std::endl;
	} catch ( const std::string & s ) {
		std::cerr << "Exception occurred in main: \n\t" << s << std::endl;
	} catch ( const char * c ) {
		std::cerr << "Exception occurred in main: \n\t" << c << std::endl;
	}

	const Duration elapsed = Clock::now() - start;
	std::cout << "total elapsed time: " << elapsed.count() << " seconds" << std::endl;

	return 0;
}
Exemplo n.º 14
0
Time ObjectHost::localTime(const SpaceID& space, const Time& t) {
    Duration off = clientTimeOffset(space);
    // FIXME we should probably return a negative time and force the code using
    // this (e.g. the loc update stuff) to make sure it handles it correctly by
    // extrapolating to a current time.
    // This is kinda gross, but we need to make sure result >= 0
    if ( (int64)t.raw() + off.toMicro() < 0) return Time::null();
    return t + off;
}
Exemplo n.º 15
0
TEST(DurationTest, Subtract) {
    Duration d = Duration::fromSeconds(5);
    Duration d2 = Duration::fromSeconds(2);
    Duration d3 = d - d2;

    EXPECT_EQ(5, d.toIntegerSeconds());
    EXPECT_EQ(2, d2.toIntegerSeconds());
    EXPECT_EQ(3, d3.toIntegerSeconds());
}
Exemplo n.º 16
0
TEST(DurationTest, Add) {
    Duration d = Duration::fromSeconds(5);
    Duration d2 = Duration::fromSeconds(2);
    Duration d3 = d + d2;

    EXPECT_EQ(5, d.toIntegerSeconds());
    EXPECT_EQ(2, d2.toIntegerSeconds());
    EXPECT_EQ(7, d3.toIntegerSeconds());
}
Exemplo n.º 17
0
int main( int argc, const char * const argv[] )
{
	BOOSTNS::random::mt19937 rng( 834725927 );
	const Clock::time_point start = Clock::now();

	std::cout << "called with: " << std::endl << "\t";
	for ( int i = 0; i < argc; ++i ) {
		std::cout << argv[i] << " ";
	}
	std::cout << std::endl;

	po::options_description desc( "Bundle Adjustment options" );

	try {
		addOptions( desc );

		po::variables_map options;
		po::store( po::parse_command_line( argc, argv, desc ), options );

//		po::parsed_options parsed =
//				po::command_line_parser( argc, argv ).options( desc ).allow_unregistered().run();
//		po::store( parsed, vm );
//		std::vector< string > to_pass_further =
//				po::collect_unrecognized( parsed.options, po::exclude_positional );

		po::notify( options );

		if ( options.count( "help" ) ) {
			std::cout << desc << std::endl;

		} else if ( !options.count( "file" ) ) {
			std::cout << "\nat least one input BA file must be specified\n" << std::endl;
			std::cout << desc << std::endl;

		} else {
			// get the set of files to optimize
			const std::vector< string > files =
					options[ "file" ].as< std::vector< string > >();

			// optimize each one
			for ( string file : files ) {
				optimize_BA( rng, options, file );
			}
		}

	} catch ( po::error & e) {
		  std::cerr << "\nCommand line error: " << e.what() << std::endl << std::endl;
		  std::cerr << desc << std::endl;
	} catch ( std::exception & e ) {
		std::cerr << "\nException occurred in main (B.A. opt): \n\t" << e.what()
				<< ", application will now exit. Goodbye!" << std::endl;
	}

	const Duration elapsed = Clock::now() - start;
	std::cout << "total elapsed time: " << elapsed.count() << " seconds" << std::endl;
}
Exemplo n.º 18
0
 double get(const Time& t, double K) const {
     Duration diff = t - _t;
     double dt = diff.toSeconds();
     if (dt<1.0e-9) {
         return _value;
     }
     double blend = exp(-dt/K);
     uint32 new_bytes = _backlog;
     return _value*blend+(1-blend)*new_bytes/dt;
 }
Exemplo n.º 19
0
 long to_usec(const Duration& d, long max_duration) const
 {
   if (d.ticks() <= 0)
     return 0;
   int64_t usec = d.total_microseconds();
   if (usec == 0)
     return 1;
   if (usec > max_duration)
     return max_duration;
   return static_cast<long>(usec);
 }
Exemplo n.º 20
0
TEST(DurationTest, Format) {
    Duration d = Duration::fromNanos(255);
    EXPECT_QSTRING_EQ("255 ns", d.formatNanosWithUnit());

    d = Duration::fromNanos(-255);
    // Formatted as -255 in two's-complement.
    EXPECT_QSTRING_EQ("-255 ns", d.formatNanosWithUnit());

    d = Duration::fromNanos(1e9);
    EXPECT_QSTRING_EQ("1000000000 ns", d.formatNanosWithUnit());
}
Exemplo n.º 21
0
Rest::Rest(Score* s, const Duration& d)
  : ChordRest(s)
      {
      setFlags(ELEMENT_MOVABLE | ELEMENT_SELECTABLE);
      _beamMode  = BEAM_NO;
      dotline    = -1;
      _sym       = rest4Sym;
      setDurationType(d);
      if (d.fraction().isValid())
            setDuration(d.fraction());
      }
Exemplo n.º 22
0
/******************************************************************************
*  Initialise the controls with a specified time period.
*  The time unit combo-box is initialised to 'defaultUnits', but if 'dateOnly'
*  is true, it will never be initialised to minutes or hours/minutes.
*/
void TimePeriod::setPeriod(const Duration& perod, bool dateOnly, TimePeriod::Units defaultUnits)
{
	Duration oldinterval = period();
	if (!dateOnly  &&  mNoHourMinute)
		dateOnly = true;
	int item;
	if (perod)
	{
		int count = perod.value();
		if (perod.isDaily())
		{
			if (count % 7)
				item = Days;
			else
			{
				item = Weeks;
				count /= 7;
			}
		}
		else
		{
			count /= 60;   // minutes
			item = (defaultUnits == Minutes && count <= mSpinBox->maximum()) ? Minutes : HoursMinutes;
		}
		if (item < mDateOnlyOffset)
			item = mDateOnlyOffset;
		else if (item > mMaxUnitShown)
			item = mMaxUnitShown;
		mUnitsCombo->setCurrentIndex(item - mDateOnlyOffset);
		if (item == HoursMinutes)
			mTimeSpinBox->setValue(count);
		else
			mSpinBox->setValue(count);
		item = setDateOnly(perod, dateOnly, false);
	}
	else
	{
		item = defaultUnits;
		if (item < mDateOnlyOffset)
			item = mDateOnlyOffset;
		else if (item > mMaxUnitShown)
			item = mMaxUnitShown;
		mUnitsCombo->setCurrentIndex(item - mDateOnlyOffset);
		if ((dateOnly && !mDateOnlyOffset)  ||  (!dateOnly && mDateOnlyOffset))
			item = setDateOnly(perod, dateOnly, false);
	}
	setUnitRange();
	showHourMin(item == HoursMinutes  &&  !mNoHourMinute);

	Duration newinterval = period();
	if (newinterval != oldinterval)
		emit valueChanged(newinterval);
}
Exemplo n.º 23
0
Duration
ParallelTimeline::GetNaturalDurationCore (Clock *clock)
{
	TimelineCollection *collection = GetChildren ();
	Duration d = Duration::Automatic;
	TimeSpan duration_span = 0;
	Timeline *timeline;
	
	int count = collection->GetCount ();

	if (count == 0)
		return Duration::FromSeconds (0);
	
	for (int i = 0; i < count; i++) {
		timeline = collection->GetValueAt (i)->AsTimeline ();
		
		Duration duration = timeline->GetNaturalDuration (clock);
		if (duration.IsAutomatic())
			continue;
		
		if (duration.IsForever())
			return Duration::Forever;
		
		TimeSpan span = duration.GetTimeSpan ();
		
		RepeatBehavior *repeat = timeline->GetRepeatBehavior ();
		if (repeat->IsForever())
			return Duration::Forever;
		
		if (repeat->HasCount ())
			span = (TimeSpan) (span * repeat->GetCount ());
		
		if (timeline->GetAutoReverse ())
			span *= 2;

		// If we have duration-base repeat behavior, 
		// clamp/up our span to that.
		if (repeat->HasDuration ())
			span = repeat->GetDuration ();
		
		if (span != 0)
			span = (TimeSpan)(span / timeline->GetSpeedRatio());

		span += timeline->GetBeginTime ();

		if (duration_span <= span) {
			duration_span = span;
			d = Duration (duration_span);
		}
	}

	return d;
}
Exemplo n.º 24
0
std::string CmdEdit::formatDuration (
  Task& task,
  const std::string& attribute)
{
  std::string value = task.get (attribute);
  if (value.length ())
  {
    Duration dur (value);
    value = dur.formatSeconds ();
  }

  return value;
}
Exemplo n.º 25
0
void TestGL::TestAndOutput(int aNumIterations, FILE* aFile)
{
  TestGLRunner tgr(this);
  Duration d = tgr.Run(aNumIterations);
  OutputTestName(aFile);

  int screenSize = 1000 * 1000;
  double numOfUploadsToFillScreen = screenSize/(mTextureSize*mTextureSize);
  double timePerUpload = d.ToMilliseconds() / aNumIterations;
  int timeToFillScreen = (int)(numOfUploadsToFillScreen * timePerUpload);
  fprintf(aFile, ",%10d,%10d,%10d,%10d,%10.0f\n", mPixelSize, mTextureSize, mAlignment, timeToFillScreen,
          d.ToMilliseconds());
}
Exemplo n.º 26
0
int main(int argc, char** argv)
{
  Duration d;
  
  signal(SIGINT, sigint_handler);

  d.version();
  d.process();
  cout << "\nPress any key to continue..";
  cout.put('\n');
  cin.get();

 return 0;
}
Exemplo n.º 27
0
QVariant CriticalPathItemModel::duration( int role ) const
{
    switch ( role ) {
        case Qt::DisplayRole:
        case Qt::ToolTipRole: {
            Duration v = m_project->duration( m_manager->scheduleId() );
            return QVariant(QLocale().toString( v.toDouble( presentationUnit( v ) ), 'f', 1 ) + Duration::unitToString( presentationUnit( v ) ));
        }
        case Qt::StatusTipRole:
        case Qt::WhatsThisRole:
            return QVariant();
    }
    return QVariant();
}
Exemplo n.º 28
0
 double estimate_rate(const Time& t, uint32 len, double K) {
     Duration diff = t - _t;
     double dt = diff.toSeconds();
     if (dt<1.0e-9) {
         _backlog += len;
         return _value;
     }
     double blend = exp(-dt/K);
     uint32 new_bytes = len + _backlog;
     _value=_value*blend+(1-blend)*new_bytes/dt;
     _t = t;
     _backlog = 0;
     return _value;
 }
Exemplo n.º 29
0
  void do_wait(const Duration& timeout, asio::error_code& ec)
  {
#if defined(ASIO_WINDOWS_RUNTIME)
    std::this_thread::sleep_for(
        std::chrono::seconds(timeout.total_seconds())
        + std::chrono::microseconds(timeout.total_microseconds()));
    ec = asio::error_code();
#else // defined(ASIO_WINDOWS_RUNTIME)
    ::timeval tv;
    tv.tv_sec = timeout.total_seconds();
    tv.tv_usec = timeout.total_microseconds() % 1000000;
    socket_ops::select(0, 0, 0, 0, &tv, ec);
#endif // defined(ASIO_WINDOWS_RUNTIME)
  }
Exemplo n.º 30
0
QVariant CriticalPathItemModel::duration( int role ) const
{
    switch ( role ) {
        case Qt::DisplayRole:
        case Qt::ToolTipRole: {
            Duration v = m_project->duration( m_manager->id() );
            return KGlobal::locale()->formatNumber( v.toDouble( presentationUnit( v ) ), 1 ) + Duration::unitToString( presentationUnit( v ) );
        }
        case Qt::StatusTipRole:
        case Qt::WhatsThisRole:
            return QVariant();
    }
    return QVariant();
}