示例#1
0
void UniverseTracker::PrintStats() {
  UniverseStatsMap::iterator iter = m_stats.begin();
  TimeStamp now;
  m_clock.CurrentTime(&now);

  TimeInterval interval = now - m_start_time;
  OLA_INFO << "Time delta was " << interval;

  for (; iter != m_stats.end(); ++iter) {
    const UniverseStats stats = iter->second;

    float fps = 0.0;
    if (interval.Seconds() > 0)
      fps = static_cast<float>(stats.frame_count) / interval.Seconds();

    cout << "Universe " << iter->first << endl;
    cout << "  Frames Received: " << stats.frame_count <<
      ", Frames/sec: " << fps << endl;
    cout << "  Frame changes: " << stats.frame_changes << endl;
    cout << "  Smallest Frame: ";
    if (stats.shortest_frame == DMX_UNIVERSE_SIZE + 1)
      cout << "N/A";
    else
      cout << stats.shortest_frame;
    cout << ", Largest Frame: ";
    if (stats.longest_frame == 0)
      cout << "N/A";
    else
      cout << stats.longest_frame;
    cout << endl;
    cout << "------------------------------" << endl;
  }
}
示例#2
0
/**  Returns an intersection of this interval with \a ti
     @param ti :: Time interval
     @return A valid time interval if this interval intersects with \a ti or
             an empty interval otherwise.
 */
TimeInterval TimeInterval::intersection(const TimeInterval& ti)const
{
    if (!isValid() || !ti.isValid()) return TimeInterval();

    DateAndTime t1 = begin();
    if (ti.begin() > t1) t1 = ti.begin();

    DateAndTime t2 = end();
    if (ti.end() < t2) t2 = ti.end();

    return t1 < t2? TimeInterval(t1,t2) : TimeInterval();

}
/*
 * Check RegisterSingleTimeout works.
 */
void TimeoutManagerTest::testSingleTimeouts() {
  MockClock clock;
  TimeoutManager timeout_manager(&m_map, &clock);

  OLA_ASSERT_FALSE(timeout_manager.EventsPending());

  TimeInterval timeout_interval(1, 0);
  timeout_id id1 = timeout_manager.RegisterSingleTimeout(
      timeout_interval,
      NewSingleCallback(this, &TimeoutManagerTest::HandleEvent, 1u));
  OLA_ASSERT_NE(id1, ola::thread::INVALID_TIMEOUT);

  TimeStamp last_checked_time;

  clock.AdvanceTime(0, 1);  // Small offset to work around timer precision
  clock.CurrentTime(&last_checked_time);
  TimeInterval next = timeout_manager.ExecuteTimeouts(&last_checked_time);
  OLA_ASSERT_EQ(0u, GetEventCounter(1));
  OLA_ASSERT_LT(next, timeout_interval);

  clock.AdvanceTime(0, 500000);
  clock.CurrentTime(&last_checked_time);
  next = timeout_manager.ExecuteTimeouts(&last_checked_time);
  OLA_ASSERT_EQ(0u, GetEventCounter(1));
  OLA_ASSERT_LT(next, TimeInterval(0, 500000));

  clock.AdvanceTime(0, 500000);
  clock.CurrentTime(&last_checked_time);
  next = timeout_manager.ExecuteTimeouts(&last_checked_time);
  OLA_ASSERT_TRUE(next.IsZero());
  OLA_ASSERT_EQ(1u, GetEventCounter(1));

  OLA_ASSERT_FALSE(timeout_manager.EventsPending());

  // now add another timeout and then remove it
  timeout_id id2 = timeout_manager.RegisterSingleTimeout(
      timeout_interval,
      NewSingleCallback(this, &TimeoutManagerTest::HandleEvent, 2u));
  OLA_ASSERT_NE(id2, ola::thread::INVALID_TIMEOUT);
  OLA_ASSERT_TRUE(timeout_manager.EventsPending());
  OLA_ASSERT_EQ(0u, GetEventCounter(2));

  timeout_manager.CancelTimeout(id2);

  clock.AdvanceTime(1, 0);
  clock.CurrentTime(&last_checked_time);
  next = timeout_manager.ExecuteTimeouts(&last_checked_time);
  OLA_ASSERT_FALSE(timeout_manager.EventsPending());
  OLA_ASSERT_EQ(0u, GetEventCounter(2));
}
/*
 * Check RegisterRepeatingTimeout works.
 */
void TimeoutManagerTest::testRepeatingTimeouts() {
  MockClock clock;
  TimeoutManager timeout_manager(&m_map, &clock);

  OLA_ASSERT_FALSE(timeout_manager.EventsPending());

  TimeInterval timeout_interval(1, 0);
  timeout_id id1 = timeout_manager.RegisterRepeatingTimeout(
      timeout_interval,
      NewCallback(this, &TimeoutManagerTest::HandleRepeatingEvent, 1u));
  OLA_ASSERT_NE(id1, ola::thread::INVALID_TIMEOUT);

  TimeStamp last_checked_time;

  clock.AdvanceTime(0, 1);  // Small offset to work around timer precision
  clock.CurrentTime(&last_checked_time);
  TimeInterval next = timeout_manager.ExecuteTimeouts(&last_checked_time);
  OLA_ASSERT_EQ(0u, GetEventCounter(1));
  OLA_ASSERT_LT(next, timeout_interval);

  clock.AdvanceTime(0, 500000);
  clock.CurrentTime(&last_checked_time);
  next = timeout_manager.ExecuteTimeouts(&last_checked_time);
  OLA_ASSERT_EQ(0u, GetEventCounter(1));
  OLA_ASSERT_LT(next, TimeInterval(0, 500000));

  clock.AdvanceTime(0, 500000);
  clock.CurrentTime(&last_checked_time);
  next = timeout_manager.ExecuteTimeouts(&last_checked_time);
  OLA_ASSERT_LTE(next, timeout_interval);
  OLA_ASSERT_EQ(1u, GetEventCounter(1));

  OLA_ASSERT_TRUE(timeout_manager.EventsPending());

  // fire the event again
  clock.AdvanceTime(1, 0);
  clock.CurrentTime(&last_checked_time);
  next = timeout_manager.ExecuteTimeouts(&last_checked_time);
  OLA_ASSERT_LTE(next, timeout_interval);
  OLA_ASSERT_EQ(2u, GetEventCounter(1));

  // cancel the event
  timeout_manager.CancelTimeout(id1);
  clock.AdvanceTime(1, 0);
  clock.CurrentTime(&last_checked_time);
  next = timeout_manager.ExecuteTimeouts(&last_checked_time);
  OLA_ASSERT_TRUE(next.IsZero());
  OLA_ASSERT_EQ(2u, GetEventCounter(1));
}
示例#5
0
void Tracker::LogTime() {
  TimeStamp now;
  m_clock.CurrentTime(&now);
  TimeInterval delta = now - m_send_time;
  if (delta > m_max) {
    m_max = delta;
  }
  m_sum += delta.MicroSeconds();

  OLA_INFO << "RPC took " << delta;
  if (FLAGS_count == ++m_count) {
    m_wrapper.GetSelectServer()->Terminate();
  } else {
    SendRequest();
  }
}
void GroupableTimeSeriesSet::similar(GroupableTimeSeriesSet *other, int otherSeq, TimeInterval otherInt,
                                     SearchStrategy strat, int warps)
{
    if (!valid() || !other->valid()) {
        session->geterr() << "Warning: Attempted to find similarities using an invalid database." << endl;
        return;
    }

    if (grouping == NULL) {
        session->geterr() << "Warning: Attempted to find similarities on ungrouped dataset." << endl;
        return;
    }

    kBest best = grouping->getBestInterval(otherInt.length(),
                                           other->dataset->getRawData(otherSeq, otherInt.start),
                                           strat, warps);

    session->getout() << "Found most similar interval." << endl;
    session->getout() << "Sequence number and interval: " << best.seq << "@"
                      << "[" << best.interval.start << ", " << best.interval.end << "]." << endl;
    session->getout() << "Distance: " << best.dist << endl;
    if (verbosity > 0) {
        session->getout() << "Sequence: " << endl;
        dataset->printInterval(session->getout(), best.seq, best.interval);
    }
}
示例#7
0
/**
 * Check the granularity of usleep.
 */
void UartDmxThread::CheckTimeGranularity() {
  TimeStamp ts1, ts2;
  Clock clock;
  /** If sleeping for 1ms takes longer than this, don't trust
   * usleep for this session
   */
  const int threshold = 3;

  clock.CurrentTime(&ts1);
  usleep(1000);
  clock.CurrentTime(&ts2);

  TimeInterval interval = ts2 - ts1;
  m_granularity = interval.InMilliSeconds() > threshold ? BAD : GOOD;
  OLA_INFO << "Granularity for UART thread is "
           << (m_granularity == GOOD ? "GOOD" : "BAD");
}
示例#8
0
/******************************************************************************
* This is called when the active animation interval has changed.
******************************************************************************/
void ActionManager::onAnimationIntervalChanged(TimeInterval newAnimationInterval)
{
	bool isAnimationInterval = newAnimationInterval.duration() != 0;
	getAction(ACTION_GOTO_START_OF_ANIMATION)->setEnabled(isAnimationInterval);
	getAction(ACTION_GOTO_PREVIOUS_FRAME)->setEnabled(isAnimationInterval);
	getAction(ACTION_TOGGLE_ANIMATION_PLAYBACK)->setEnabled(isAnimationInterval);
	getAction(ACTION_GOTO_NEXT_FRAME)->setEnabled(isAnimationInterval);
	getAction(ACTION_GOTO_END_OF_ANIMATION)->setEnabled(isAnimationInterval);
}
示例#9
0
TimeInterval
MediaSourceDecoder::ClampIntervalToEnd(const TimeInterval& aInterval)
{
  if (!mEnded) {
    return aInterval;
  }
  TimeInterval interval(TimeUnit(), TimeUnit::FromSeconds(GetDuration()));
  return aInterval.Intersection(interval);
}
示例#10
0
void AvahiDiscoveryAgent::SetUpReconnectTimeout() {
  // We don't strictly need an ExponentialBackoffPolicy here because the client
  // goes into the AVAHI_CLIENT_CONNECTING state if the server isn't running.
  // Still, it's a useful defense against spinning rapidly if something goes
  // wrong.
  TimeInterval delay = m_backoff.Next();
  OLA_INFO << "Re-creating avahi client in " << delay << "s";
  struct timeval tv;
  delay.AsTimeval(&tv);

  const AvahiPoll *poll = avahi_threaded_poll_get(m_threaded_poll);
  if (m_reconnect_timeout) {
    poll->timeout_update(m_reconnect_timeout, &tv);
  } else {
    m_reconnect_timeout = poll->timeout_new(
        avahi_threaded_poll_get(m_threaded_poll),
        &tv,
        reconnect_callback,
        this);
  }
}
示例#11
0
/*
 * Display the debug page
 * @param request the HttpRequest
 * @param response the HttpResponse
 * @returns MHD_NO or MHD_YES
 */
int OlaHttpServer::DisplayDebug(const HttpRequest *request,
                                HttpResponse *response) {
    TimeStamp now;
    m_clock.CurrentTime(&now);
    TimeInterval diff = now - m_start_time;
    stringstream str;
    str << (diff.AsInt() / 1000);
    m_export_map->GetStringVar(K_UPTIME_VAR)->Set(str.str());

    vector<BaseVariable*> variables = m_export_map->AllVariables();
    response->SetContentType(HttpServer::CONTENT_TYPE_PLAIN);

    vector<BaseVariable*>::iterator iter;
    for (iter = variables.begin(); iter != variables.end(); ++iter) {
        stringstream out;
        out << (*iter)->Name() << ": " << (*iter)->Value() << "\n";
        response->Append(out.str());
    }
    int r = response->Send();
    delete response;
    return r;
    (void) request;
}
kBest GroupableTimeSeriesSet::returnSimilar(GroupableTimeSeriesSet *other, int otherSeq, TimeInterval otherInt,
                                     SearchStrategy strat, int warps)
{
    if (!valid() || !other->valid()) {
        session->geterr() << "Warning: Attempted to find similarities using an invalid database." << endl;
        return;
    }

    if (grouping == NULL) {
        session->geterr() << "Warning: Attempted to find similarities on ungrouped dataset." << endl;
        return;
    }

    return grouping->getBestInterval(otherInt.length(),
                                           other->dataset->getRawData(otherSeq, otherInt.start),
                                           strat, warps);

}
示例#13
0
void Tracker::Start() {
  ola::io::SelectServer *ss = m_wrapper.GetSelectServer();
  m_signal_thread.InstallSignalHandler(
      SIGINT,
      ola::NewCallback(ss, &ola::io::SelectServer::Terminate));
  m_signal_thread.InstallSignalHandler(
      SIGTERM,
      ola::NewCallback(ss, &ola::io::SelectServer::Terminate));
  SendRequest();

  ss->Execute(ola::NewSingleCallback(this, &Tracker::StartSignalThread));
  ss->Run();

  // Print this via cout to ensure we actually get some output by default
  // It also means you can just see the stats and not each individual request
  // if you want.
  cout << "--------------" << endl;
  cout << "Sent " << m_count << " RPCs" << endl;
  cout << "Max was " << m_max.MicroSeconds() << " microseconds" << endl;
  cout << "Mean " << m_sum / m_count << " microseconds" << endl;
}
示例#14
0
	//Returns true if a and b overlap, false otherwise
	bool operator&&(const TimeInterval& a, const TimeInterval& b){
		return a.getStart() <= b.getEnd() && a.getStart() >= b.getEnd();
	}
示例#15
0
int main(int argc, char *argv[])
{
    const int                 test = argc > 1 ? atoi(argv[1]) : 0;
    const bool             verbose = argc > 2;
    const bool         veryVerbose = argc > 3;
    const bool     veryVeryVerbose = argc > 4;
    const bool veryVeryVeryVerbose = argc > 5;

    (void)     veryVeryVerbose;
    (void) veryVeryVeryVerbose;

    printf("TEST " __FILE__ " CASE %d\n", test);

    switch (test) {
    case 0:
    case 4: {
        // --------------------------------------------------------------------
        // USAGE EXAMPLE
        //
        // Concerns:
        //: 1 The usage example provided in the component header file must
        //:   compile, link, and run as shown.
        //
        // Plan:
        //: 1 Incorporate usage example from header into test driver, replace
        //:   leading comment characters with spaces, replace 'assert' with
        //:   'ASSERT', and insert 'if (veryVerbose)' before all output
        //:   operations.  (C-1)
        //
        // Testing:
        //   USAGE EXAMPLE
        // --------------------------------------------------------------------

        if (verbose) printf("\nUSAGE EXAMPLE"
                                "\n=============\n");

///Example 1: Getting Current Wall Clock Time
/// - - - - - - - - - - - - - - - - - - - - -
// The following snippets of code illustrate how to use this utility component
// to obtain the system time by calling 'now' and 'nowRealtimeClock'.
//
// First, we call 'nowRealtimeClock', and set 't1', to the current time
// according to the real-time clock:
//..
        bsls::TimeInterval t1 = bsls::SystemTime::nowRealtimeClock();
//
        ASSERT(bsls::TimeInterval() != t1);
//..
// Next, we sleep for 1 second:
//..
        sleep(1);
//..
// Now, we call 'now', and supply 'e_REALTIME' to indicate a real-time clock
// value should be returned, and then set 't2' to the current time according
// to the real-time clock:
//..
        bsls::TimeInterval t2 = bsls::SystemTime::now(
                                    bsls::SystemClockType::e_REALTIME);
//
        ASSERT(bsls::TimeInterval() != t2);
//..
// Finally, we verify the interval between 't1' and 't2' is close to 1 second:
//..
        bsls::TimeInterval interval = t2 - t1;
//
        ASSERT(bsls::TimeInterval(.9) <= interval &&
               interval <= bsls::TimeInterval(1.1));
//..
    }
    break;
    case 3: {
        // --------------------------------------------------------------------
        // CLASS METHODS: 'now(SystemClockType::Enum)'
        //  Ensure the returned 'TimeInterval' value represents the current
        //  system time as per the specified 'SystemClockType::Enum'.
        //
        // Concerns:
        //: 1 'now(e_REALTIME)' provides the current "wall" time.
        //:
        //: 2 'now(e_MONOTONIC)' provides the current monotonic clock time.
        //
        // Plan:
        //: 1 Verify 'now(e_REALTIME)' closely approximates the value returned
        //:   by 'nowRealtimeClock'.  (C-1)
        //:
        //: 2 Verify 'now(e_MONOTONIC)' closely approximates the value returned
        //:   by 'nowMonotonicClock'.  (C-2)
        //
        // Testing:
        //  TimeInterval now(SystemClockType::Enum);
        // --------------------------------------------------------------------

        if (verbose) printf("\nCLASS METHODS: 'now(SystemClockType::Enum)'"
                                "\n===========================================\n");

        if (veryVerbose) printf("\tCompare results w/ monotonic clock\n");
        {
            TimeInterval first  = Obj::nowMonotonicClock();
            TimeInterval second = Obj::now(SystemClockType::e_MONOTONIC);
            ASSERT(second - first  < TimeInterval(1, 0));
        }

        if (veryVerbose) printf("\tCompare results w/ real-time clock\n");
        {
            TimeInterval first  = Obj::nowRealtimeClock();
            TimeInterval second = Obj::now(SystemClockType::e_REALTIME);
            ASSERT(second - first  < TimeInterval(1, 0));
        }
    }
    break;
    case 2: {
        // --------------------------------------------------------------------
        // CLASS METHODS: 'nowMonotonicClock'
        //
        // Concerns:
        //: 1 Consecutive calls to 'nowMonotonicClock' measure time intervals
        //:   that match those measured by calls to the (previously tested)
        //:   'nowRealtimeClock'.
        //:
        //: 2 That consecutive values do not decrease.
        //:
        //: 3 QoI: The resolution of the monotonic clock is < 1 second.
        //
        // Plan:
        //: 1 Call 'nowMonotonicClock' in a loop for a couple seconds; verify
        //:   the results do not decrease between iterations, and that
        //:   increments of the clock are less than 1 second.  (C-1..3)
        //
        // Testing:
        //   TimeInterval nowMonotonicClock();
        // --------------------------------------------------------------------

        if (verbose) printf("\nCLASS METHODS: 'nowMonotonicClock'"
                                "\n==================================\n");

        if (veryVerbose) printf("\tCompare results w/ real-time clock\n");
        {
            // Test sequential values are increasing and have a resolution of
            // less than 1 second.

            TimeInterval ONE_SEC = TimeInterval(1, 0);
            TimeInterval realOrigin = Obj::nowRealtimeClock();
            TimeInterval monoOrigin = Obj::nowMonotonicClock();
            TimeInterval prev       = monoOrigin;
            TimeInterval now        = monoOrigin;

            while (TimeInterval(1.5) > now - monoOrigin) {
                if (veryVerbose) {
                    P_(prev);
                    P(now);
                }

                now = Obj::nowMonotonicClock();

                ASSERT(prev <= now);
                ASSERT(prev + ONE_SEC > now);

                prev = now;
            }

            TimeInterval realInterval = Obj::nowRealtimeClock() - realOrigin;
            TimeInterval monoInterval = now - monoOrigin;
            TimeInterval delta        = monoInterval - realInterval;

            const TimeInterval TOLERANCE = TimeInterval(.1);

            ASSERT(-TOLERANCE <= delta && delta <= TOLERANCE);
        }
    }
    break;
    case 1: {
        // --------------------------------------------------------------------
        // CLASS METHODS: 'nowRealtimeClock'
        //
        // Concerns:
        //: 1 'nowRealtimeClock' returns values that are intervals from the
        //:   Unix epoch.
        //:
        //: 2 'nowRealtimeClock' returns time values that are consistent with
        //:   the current wall clock time.
        //:
        //: 3 QoI: That consecutive values do not decrease (under normal
        //:   conditions).
        //:
        //: 4 QoI: The resolution of the real-time clock is < 1 second.
        //
        // Plan:
        //: 1 Call 'nowRealtimeClock' and verify the value returned, when
        //:   treated as an interval from the Unix epoch, corresponds to a
        //:   possible wall clock time.  (C-1)
        //:
        //: 2 Call 'nowRealtimeClock' and compare the value returned to an
        //:   oracle clock, i.e., the standard library function 'time'.  (C-2)
        //:
        //: 3 Call 'nowRealtimeClock' in a loop for a couple seconds; verify
        //:   the results do not decrease between iterations, and that
        //:   increments of the clock are less than 1 second.  (C-3..4)
        //
        // Testing:
        //   TimeInterval nowRealtimeClock();
        // --------------------------------------------------------------------

        if (verbose) printf("\nCLASS METHODS: 'nowRealtimeClock'"
                                "\n=================================\n");

        if (veryVerbose) printf("\tTest result is relative to Unix epoch\n");
        {
            const int64_t SEPT_27_2014         = 1411833584;
            const int64_t HUNDRED_YEARS_APPROX = 60ull * 60 * 24 * 365 * 100;

            TimeInterval t = Obj::nowRealtimeClock();

            ASSERT(SEPT_27_2014                        <= t.seconds());
            ASSERT(SEPT_27_2014 + HUNDRED_YEARS_APPROX >= t.seconds());
        }

        if (veryVerbose) printf("\tCompare results to 'time'\n");
        {
            time_t       timeValue       = time(0);
            TimeInterval systemTimeValue = Obj::nowRealtimeClock();

            ASSERT(timeValue - 1 <= systemTimeValue.seconds());
            ASSERT(timeValue + 1 >= systemTimeValue.seconds());
        }

        if (veryVerbose) printf("\tVerify sequential values'\n");
        {
            // Test sequential values are increasing and have a resolution of
            // less than 1 second.

            TimeInterval ONE_SEC = TimeInterval(1, 0);
            TimeInterval origin  = Obj::nowRealtimeClock();
            TimeInterval prev    = origin;
            TimeInterval now     = origin;

            while (TimeInterval(1.5) > now - origin) {
                if (veryVerbose) {
                    P_(prev);
                    P(now);
                }

                now = Obj::nowRealtimeClock();

                ASSERT(prev <= now);
                ASSERT(prev + ONE_SEC > now);

                prev = now;
            }
        }
    }
    break;
    case -1: {
        // --------------------------------------------------------------------
        // CONCERN: STRESS TEST FOR MONOTONICITY
        //  Verify that each subsequent call to 'now' reports a time that is
        //  non-decreasing.
        //
        // Plan:
        //  Exercise the method in a loop a large, configurable number of
        //  times, verifying in each iteration that the system time is
        //  non-decreasing for all support clock types.
        //
        // Testing:
        //  CONCERN: STRESS TEST FOR MONOTONICITY
        // --------------------------------------------------------------------

        if (verbose)
            printf("\nCONCERN: STRESS TEST FOR MONOTONICITY"
                   "\n=====================================\n");

        SystemClockType::Enum TYPES[] = {
            SystemClockType::e_REALTIME,
            SystemClockType::e_MONOTONIC
        };
        const int NUM_TYPES = sizeof TYPES / sizeof *TYPES;

        for (int type = 0; type < NUM_TYPES; ++type) {
            SystemClockType::Enum TYPE = TYPES[type];

            if (veryVerbose) {
                printf("\nType: %s\n", SystemClockType::toAscii(TYPE));
            }

            TimeInterval TOLERANCE(0.001); // 1ms

            enum {
                NUM_ITERATIONS         = 120,
                NUM_TEST_PER_ITERATION = 1000,
                OUTPUT_WIDTH           = 60,
                OUTPUT_FREQ = NUM_ITERATIONS / OUTPUT_WIDTH
            };

            int iterations = verbose ? atoi(argv[2]) : NUM_ITERATIONS;
            int output_freq = iterations < OUTPUT_WIDTH ? 1
                              : iterations / OUTPUT_WIDTH;
            int testsPerIteration = NUM_TEST_PER_ITERATION;

            if (veryVerbose) {
                testsPerIteration = atoi(argv[3]);
                const char P1[] = "0%";
                const char P2[] = "50%";
                const char P3[] = "100%";
                int hl = OUTPUT_WIDTH / 2;
                printf("%s", P1);

                for (unsigned i=0; i < hl - sizeof(P1) - sizeof(P2) + 4; ++i) {
                    printf("-");
                }
                printf("%s", P2);
                for (unsigned i = 0; i < hl - sizeof(P3); ++i) {
                    printf("-");
                }
                printf("%s\n", P3);
            }
            for (int i = 0; i < iterations; ++i) {
                TimeInterval prev = Obj::now(TYPE);
                for (int j = 0; j < testsPerIteration; ++j) {
                    TimeInterval now = Obj::now(TYPE);
                    if (prev > now) {
                        printf("*** Warning: system time is not "
                               "reliably monotonic on this platform\n."
                               "*** Allowing a tolerance of 1ms "
                               "in test driver.\n");
                        ASSERTV(i, j, prev, now, prev - TOLERANCE <= now);
                    }
                    ASSERTV(i, j, prev, now, prev <= now);
                    prev = now;
                }
                if (veryVerbose && 0 == i % output_freq) {
                    if (0 == i % (OUTPUT_WIDTH / 4 * output_freq)) {
                        printf("|");
                        fflush(stdout);
                    }
                    else {
                        printf("+");
                        fflush(stdout);
                    }
                }
            }
            if (veryVerbose) printf("\n");
        }
    }
    break;
    case -2: {
        // --------------------------------------------------------------------
        // CONCERN: MONOTONICITY UNDER SYSTEM CLOCK CHANGES
        //  Changes to the system clock do not impact the monotonic clock.
        //
        // Plan:
        //  Record the current monotonoic and real-time clock times, pause the
        //  task to allow the current system time to be set to some time in
        //  the past, then capture the system times again.  Ensure that the
        //  second monotonic clock time is subsequent to the first, while the
        //  second real clock time is before the first.
        //
        // Testing:
        //  CONCERN: MONOTONICITY UNDER SYSTEM CLOCK CHANGES
        // --------------------------------------------------------------------

        if (verbose)
            printf("\nCONCERN: MONOTONICITY UNDER SYSTEM CLOCK CHANGES"
                   "\n================================================\n");
        {
            TimeInterval t1Real      = Obj::nowRealtimeClock();
            TimeInterval t1Monotonic = Obj::nowMonotonicClock();

            int dummy;

            printf("Set the system clock back and then"
                   " enter a number to continue\n");
            scanf("%d", &dummy);

            TimeInterval t2Real      = Obj::nowRealtimeClock();
            TimeInterval t2Monotonic = Obj::nowMonotonicClock();

            ASSERTV(t1Real, t2Real, t2Real < t1Real);
            ASSERTV(t1Monotonic, t2Monotonic, t2Monotonic >= t2Monotonic);

            if (veryVerbose) {
                P(t2Real - t1Real);
                P(t2Monotonic - t1Monotonic);
            }
        }
    }
    break;
    default: {
        fprintf(stderr, "WARNING: CASE `%d' NOT FOUND.\n", test);
        testStatus = -1;
    }
    }

    if (testStatus > 0) {
        fprintf(stderr, "Error, non-zero test status = %d.\n", testStatus);
    }
    return testStatus;
}
示例#16
0
void OnlineSession::kSimilar(int dbindex, vector<double> qdata, TimeInterval interval, int k, int strict)
{
    if (groupings[dbindex] == NULL)
        genGrouping(dbindex, defaultST);

    TimeSeriesGrouping *t = groupings[dbindex];

    int slen = dataSets[dbindex]->seqLength;
    int ilen = interval.length();

    TimeSeriesIntervalEnvelope eqdata(TimeSeriesInterval(qdata.data(), TimeInterval(0, qdata.size() - 1)));

    double gb;
    int bsfStart = 0, bsfEnd = 0, bsfIndex = -1;
    double bsf = INF;

    if (strict == 0) {
        for (int i = 0; i < slen; i++) {
            if (debug) {
                cout << "Searching groups from start=" << i << ", bsf=" << bsf << endl;
            }
            for (int j = i; j < slen; j++) {
                int k = t->groups[i * slen + j].getBestGroup(eqdata, &gb, bsf);
                if (k < 0)
                    continue;
                if (gb < bsf) {
                    bsf = gb;
                    bsfStart = i;
                    bsfEnd = j;
                    bsfIndex = k;
                }
            }
        }
    } else if (strict == 1) {
        for (int i = 0; i + ilen - 1 < slen; i++) {
            if (debug)
                cout << "Searching groups from start=" << i << endl;
            int j = i + (ilen - 1);
            int k = t->groups[i * slen + j].getBestGroup(eqdata, &gb, bsf);
            if (k < 0)
                continue;
            if (gb < bsf) {
                bsf = gb;
                bsfStart = i;
                bsfEnd = j;
                bsfIndex = k;
            }
        }
    } else {
        bsfStart = interval.start;
        bsfEnd = interval.end;
        bsfIndex = t->groups[bsfStart * slen + bsfEnd].getBestGroup(eqdata, &gb, bsf);
        if (bsfIndex >= 0)
            bsf = gb;
    }

    if (bsf == INF || bsfIndex < 0) {
        cerr << "kSimilar: Failed to find similar objects. No suitable candidate group centroids." << endl;
        return;
    }

    cout << "Found most similar interval and group: " << bsfIndex << "@"
         << "[" << bsfStart << "," << bsfEnd << "]" << endl;

    vector<kSim> sim = t->groups[bsfStart * slen + bsfEnd].groups[bsfIndex]->getSortedSimilar(eqdata, k);

    cout << "Discovered k similar points:" << endl;
    for (unsigned int i = 0; i < sim.size(); i++) {

        cout << "Series " << sim[i].index << ", interval [" << bsfStart << "," << bsfEnd
             << "] is at distance " << sim[i].distance << "." << endl;

        TimeSeriesInterval interval = (*t->groups[bsfStart * slen + bsfEnd].groups[bsfIndex]->slice)[sim[i].index];

        for (int j = 0; j < interval.length(); j++) {
            cout << interval[j] << " ";
        }
        cout << endl;
    }
}
示例#17
0
bool OrgMode::operator==(const TimeInterval &left, const OrgMode::TimeInterval &right)
{
    return left.start() == right.start() && left.end() == right.end();
}