Move CPU instrumentation up into the main loop.

This commit is contained in:
Oliver Jowett 2014-09-29 23:11:36 +01:00
parent 7a0ca85a90
commit dcae71faa8
2 changed files with 15 additions and 14 deletions

View file

@ -888,6 +888,7 @@ int main(int argc, char **argv) {
pthread_mutex_lock(&Modes.data_mutex); pthread_mutex_lock(&Modes.data_mutex);
while (Modes.exit == 0) { while (Modes.exit == 0) {
struct timespec cpu_start_time, cpu_end_time;
if (Modes.iDataReady == 0) { if (Modes.iDataReady == 0) {
pthread_cond_wait(&Modes.data_cond,&Modes.data_mutex); // This unlocks Modes.data_mutex, and waits for Modes.data_cond pthread_cond_wait(&Modes.data_cond,&Modes.data_mutex); // This unlocks Modes.data_mutex, and waits for Modes.data_cond
@ -922,11 +923,25 @@ int main(int argc, char **argv) {
// Process data after releasing the lock, so that the capturing // Process data after releasing the lock, so that the capturing
// thread can read data while we perform computationally expensive // thread can read data while we perform computationally expensive
// stuff at the same time. // stuff at the same time.
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &cpu_start_time);
if (Modes.oversample) if (Modes.oversample)
detectModeS_oversample(Modes.magnitude, MODES_ASYNC_BUF_SAMPLES); detectModeS_oversample(Modes.magnitude, MODES_ASYNC_BUF_SAMPLES);
else else
detectModeS(Modes.magnitude, MODES_ASYNC_BUF_SAMPLES); detectModeS(Modes.magnitude, MODES_ASYNC_BUF_SAMPLES);
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &cpu_end_time);
Modes.stat_cputime.tv_sec += (cpu_end_time.tv_sec - cpu_start_time.tv_sec);
Modes.stat_cputime.tv_nsec += (cpu_end_time.tv_nsec - cpu_start_time.tv_nsec);
if (Modes.stat_cputime.tv_nsec < 0) {
Modes.stat_cputime.tv_nsec += 1000000000L;
Modes.stat_cputime.tv_sec--;
} else if (Modes.stat_cputime.tv_nsec > 1000000000L) {
Modes.stat_cputime.tv_nsec -= 1000000000L;
Modes.stat_cputime.tv_sec++;
}
// Update the timestamp ready for the next block // Update the timestamp ready for the next block
if (Modes.oversample) if (Modes.oversample)
Modes.timestampBlk += (MODES_ASYNC_BUF_SAMPLES*5); Modes.timestampBlk += (MODES_ASYNC_BUF_SAMPLES*5);

View file

@ -2082,9 +2082,6 @@ void detectModeS_oversample(uint16_t *m, uint32_t mlen) {
unsigned char msg[MODES_LONG_MSG_BYTES], *pMsg; unsigned char msg[MODES_LONG_MSG_BYTES], *pMsg;
uint32_t j; uint32_t j;
struct timespec cpu_start_time, cpu_end_time;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &cpu_start_time);
memset(&mm, 0, sizeof(mm)); memset(&mm, 0, sizeof(mm));
for (j = 0; j < mlen; j++) { for (j = 0; j < mlen; j++) {
@ -2415,17 +2412,6 @@ void detectModeS_oversample(uint16_t *m, uint32_t mlen) {
} }
} }
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &cpu_end_time);
Modes.stat_cputime.tv_sec += (cpu_end_time.tv_sec - cpu_start_time.tv_sec);
Modes.stat_cputime.tv_nsec += (cpu_end_time.tv_nsec - cpu_start_time.tv_nsec);
if (Modes.stat_cputime.tv_nsec < 0) {
Modes.stat_cputime.tv_nsec += 1000000000L;
Modes.stat_cputime.tv_sec--;
} else if (Modes.stat_cputime.tv_nsec > 1000000000L) {
Modes.stat_cputime.tv_nsec -= 1000000000L;
Modes.stat_cputime.tv_sec++;
}
//Send any remaining partial raw buffers now //Send any remaining partial raw buffers now
if (Modes.rawOutUsed || Modes.beastOutUsed) if (Modes.rawOutUsed || Modes.beastOutUsed)
{ {