void Timer::GetCPUTimeMicroSeconds(Timer::CPUTime* cpu_time) const { #if !defined(_WIN32) && !defined(_WIN64) struct rusage usage; if (getrusage(RUSAGE_SELF, &usage)) { TRACE_ERR("Error occurred: getrusage().\n"); exit(1); } cpu_time->user_time = GetMicroSeconds(usage.ru_utime); cpu_time->sys_time = GetMicroSeconds(usage.ru_stime); #else // Windows // Not implemented yet. // TODO: implement the Windows version using native APIs. #endif }
int JackDebugClient::TimeCallback(jack_nframes_t nframes, void *arg) { JackDebugClient* client = (JackDebugClient*)arg; jack_time_t t1 = GetMicroSeconds(); int res = client->fProcessTimeCallback(nframes, client->fProcessTimeCallbackArg); if (res == 0) { jack_time_t t2 = GetMicroSeconds(); long delta = long((t2 - t1) - client->GetEngineControl()->fPeriodUsecs); if (delta > 0 && !client->fFreewheel) { *client->fStream << "!!! ERROR !!! : Process overload of " << delta << " us" << endl; } } return res; }
int JackPortAudioDriver::Render(const void* inputBuffer, void* outputBuffer, PaStreamCallbackFlags statusFlags) { fInputBuffer = (jack_default_audio_sample_t**)inputBuffer; fOutputBuffer = (jack_default_audio_sample_t**)outputBuffer; if (statusFlags) { if (statusFlags & paOutputUnderflow) jack_error("JackPortAudioDriver::Render paOutputUnderflow"); if (statusFlags & paInputUnderflow) jack_error("JackPortAudioDriver::Render paInputUnderflow"); if (statusFlags & paOutputOverflow) jack_error("JackPortAudioDriver::Render paOutputOverflow"); if (statusFlags & paInputOverflow) jack_error("JackPortAudioDriver::Render paInputOverflow"); if (statusFlags & paPrimingOutput) jack_error("JackPortAudioDriver::Render paOutputUnderflow"); if (statusFlags != paPrimingOutput) { jack_time_t cur_time = GetMicroSeconds(); NotifyXRun(cur_time, float(cur_time - fBeginDateUst)); // Better this value than nothing... } } // Setup threaded based log function set_threaded_log_function(); CycleTakeBeginTime(); return (Process() == 0) ? paContinue : paAbort; }
int JackPortAudioDriver::Render(const void* inputBuffer, void* outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags statusFlags, void* userData) { JackPortAudioDriver* driver = (JackPortAudioDriver*)userData; driver->fInputBuffer = (jack_default_audio_sample_t**)inputBuffer; driver->fOutputBuffer = (jack_default_audio_sample_t**)outputBuffer; //MMCSSAcquireRealTime(GetCurrentThread()); if (statusFlags) { if (statusFlags & paOutputUnderflow) jack_error("JackPortAudioDriver::Render paOutputUnderflow"); if (statusFlags & paInputUnderflow) jack_error("JackPortAudioDriver::Render paInputUnderflow"); if (statusFlags & paOutputOverflow) jack_error("JackPortAudioDriver::Render paOutputOverflow"); if (statusFlags & paInputOverflow) jack_error("JackPortAudioDriver::Render paInputOverflow"); if (statusFlags & paPrimingOutput) jack_error("JackPortAudioDriver::Render paOutputUnderflow"); if (statusFlags != paPrimingOutput) { jack_time_t cur_time = GetMicroSeconds(); driver->NotifyXRun(cur_time, float(cur_time - driver->fBeginDateUst)); // Better this value than nothing... } } // Setup threadded based log function set_threaded_log_function(); driver->CycleTakeBeginTime(); return (driver->Process() == 0) ? paContinue : paAbort; }
INLINE void StartMeasure() { if (fDynAdapt) { //fStart = DSP_rdtsc(); fStart = GetMicroSeconds(); } }
void NetworkTester::TestMessage(Message & message) { int address = message.GetSource(); Message dummyMessage; dummyMessage.SetTag(TEST_MESSAGE_RESPONSE); timeBefore = GetMicroSeconds(); Send(address, dummyMessage); }
void jack_timestamp (const char *what) { if (timestamp_index < timestamp_cnt) { timestamps[timestamp_index].when = GetMicroSeconds(); timestamps[timestamp_index].what = what; ++timestamp_index; } }
jack_nframes_t JackTransportEngine::GetCurrentFrame() { jack_position_t pos; ReadCurrentPos(&pos); if (fTransportState == JackTransportRolling) { float usecs = GetMicroSeconds() - pos.usecs; jack_nframes_t elapsed = (jack_nframes_t)floor((((float) pos.frame_rate) / 1000000.0f) * usecs); return pos.frame + elapsed; } else { return pos.frame; } }
void NetworkTester::SayHello(Message & message) { int total = GetSize() * ACTORS_PER_RANK; PrintAddress(); cout << "Hello ! I am " << GetAddress(); cout << " out of " << total << " NetworkTester actors" << endl; Message dummyMessage; dummyMessage.SetTag(TEST_MESSAGE_RESPONSE); int address = GetAddress(); timeBefore = GetMicroSeconds(); Send(address, dummyMessage); }
void NetworkTester::TestMessageResponse(Message & message) { uint64_t timeAfter = GetMicroSeconds(); int latency = (timeAfter - timeBefore) / 2; sum += latency; messages ++; int messagesToSend = 10000; if(messages == messagesToSend) { PrintAddress(); cout << "communicated " << messages << " "; cout << " TEST_MESSAGE messages"; int average = sum / messages; cout << " point-to-point latency: "; cout << average << " us" << endl; // kill the actor Message dummyMessage; dummyMessage.SetTag(Starter::ADVISE); int address = controller; Send(address, dummyMessage); } else { // send a message to a random stranger int total = GetSize() * ACTORS_PER_RANK; int address = rand() % total; // skip Starter actors address += GetSize() * 1; Message dummyMessage; dummyMessage.SetTag(TEST_MESSAGE); Send(address, dummyMessage); } }
INLINE void StopMeasure(int staticthreadnum, int& dynthreadnum) { if (!fDynAdapt) { return; } //fStop = DSP_rdtsc(); fStop = GetMicroSeconds(); fCounter = (fCounter + 1) % KDSPMESURE; if (fCounter == 0) { float mean = ComputeMean(); // Recompute dynthreadnum is timing différence is sufficient... //printf("mean = %f fOldMean = %f\n", mean, fOldMean); if (fabs(mean - fOldMean) / fOldMean > MEAN_TRESHOLD) { if (mean > fOldMean) { // Worse... if (fOldfDynamicNumThreads > dynthreadnum) { fOldfDynamicNumThreads = dynthreadnum; dynthreadnum += 1; } else { fOldfDynamicNumThreads = dynthreadnum; dynthreadnum -= 1; } } else { // Better... if (fOldfDynamicNumThreads > dynthreadnum) { fOldfDynamicNumThreads = dynthreadnum; dynthreadnum -= 1; } else { fOldfDynamicNumThreads = dynthreadnum; dynthreadnum += 1; } } fOldMean = mean; dynthreadnum = Range(1, staticthreadnum, dynthreadnum); //printf("dynthreadnum = %d\n", dynthreadnum); } } // And keep computation time fTiming[fCounter] = fStop - fStart; }
jack_nframes_t JackAlsaDriver::frame_time() const { JackTimer timer; fEngineControl->ReadFrameTime(&timer); return timer.Time2Frames(GetMicroSeconds(), fEngineControl->fBufferSize); }
void JackDriver::CycleTakeEndTime() { fEndDateUst = GetMicroSeconds(); // Take end date here }
void JackDriver::CycleTakeBeginTime() { fBeginDateUst = GetMicroSeconds(); // Take callback date here fEngineControl->CycleIncTime(fBeginDateUst); }
MilliSeconds GetMilliSeconds(void) { return (MilliSeconds) (GetMicroSeconds() / 1000ULL); }