static double get_sample(struct sample *sample) { double delay, mindelay = 0.0; struct timespec ts1, ts2, ts3; int i; for (i = 0; i < SAMPLE_READINGS; i++) { clock_gettime(CLOCK_MONOTONIC_RAW, &ts1); clock_gettime(CLOCK_MONOTONIC, &ts2); clock_gettime(CLOCK_MONOTONIC_RAW, &ts3); ts1.tv_sec -= mono_raw_base; ts2.tv_sec -= mono_base; ts3.tv_sec -= mono_raw_base; delay = diff_timespec(&ts3, &ts1); if (delay <= 1e-9) { i--; continue; } if (!i || delay < mindelay) { sample->offset = diff_timespec(&ts2, &ts1); sample->offset -= delay / 2.0; sample->time = ts1.tv_sec + ts1.tv_nsec / 1e9; mindelay = delay; } } return mindelay; }
int main(int argv, char **argc) { struct timespec mon, raw, start, end; long long delta1, delta2, interval, eppm, ppm; struct timex tx1, tx2; setbuf(stdout, NULL); if (clock_gettime(CLOCK_MONOTONIC_RAW, &raw)) { printf("ERR: NO CLOCK_MONOTONIC_RAW\n"); return -1; } tx1.modes = 0; adjtimex(&tx1); get_monotonic_and_raw(&mon, &raw); start = mon; delta1 = diff_timespec(mon, raw); if (tx1.offset) printf("WARNING: ADJ_OFFSET in progress, this will cause inaccurate results\n"); printf("Estimating clock drift: "); sleep(120); get_monotonic_and_raw(&mon, &raw); end = mon; tx2.modes = 0; adjtimex(&tx2); delta2 = diff_timespec(mon, raw); interval = diff_timespec(start, end); /* calculate measured ppm between MONOTONIC and MONOTONIC_RAW */ eppm = ((delta2-delta1)*NSEC_PER_SEC)/interval; eppm = -eppm; printf("%lld.%i(est)", eppm/1000, abs((int)(eppm%1000))); /* Avg the two actual freq samples adjtimex gave us */ ppm = (tx1.freq + tx2.freq) * 1000 / 2; ppm = (long long)tx1.freq * 1000; ppm = shift_right(ppm, 16); printf(" %lld.%i(act)", ppm/1000, abs((int)(ppm%1000))); if (llabs(eppm - ppm) > 1000) { printf(" [FAILED]\n"); return ksft_exit_fail(); } printf(" [OK]\n"); return ksft_exit_pass(); }
int main() { int ret; #ifdef _POSIX_CPUTIME struct timespec ts1, ts2, ts_diff; clockid_t clock_cpu; if ((ret = clock_getcpuclockid(0, &clock_cpu)) != 0) { return EXIT_FAILURE; } clock_gettime(clock_cpu, &ts1); #endif int i; double x, step, sum = 0.0; step = 1.0/(double) num_steps; for (i=0; i<num_steps; i++) { x = (i+0.5) * step; sum += 4.0/(1.0 + x*x); } printf("pi = %.8f (sum = %.8f)\n", step*sum, sum); sleep(1); #ifdef _POSIX_CPUTIME clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts2); ts_diff = diff_timespec(ts1, ts2); printf("elapsed cpu time = %ld.%09ld\n", ts_diff.tv_sec, ts_diff.tv_nsec); #endif return EXIT_SUCCESS; }
void FastProfiler::stop() { clock_gettime(CLOCK_MONOTONIC_RAW, &t2); double res = diff_timespec(&t1, &t2); data_[cur_index].time += res; data_[cur_index].counter +=1; started = false; }
void char_ready_handler(int signo, siginfo_t* siginfo, void *dummy) { char answer; Tmeas *temp = (Tmeas*)(((struct aiocb*)siginfo->si_value.sival_ptr)->aio_buf); int ptemp = ((struct aiocb*)siginfo->si_value.sival_ptr) - &aiocb[0]; int intemp = (int)(((struct aiocb*)siginfo->si_value.sival_ptr)->aio_fildes); if (aio_error(((struct aiocb*)siginfo->si_value.sival_ptr)) != 0) printf("ERROR\n"); if( signo == SIGIO ) { /* printf("i/o complete signal is received. Char was %d \n", *((struct Tmeas*)(((struct aiocb*)siginfo->si_value.sival_ptr)->aio_buf)))->value; //start a new read*/ clock_gettime(CLOCK_REALTIME, ¤t_time); lag = diff_timespec(¤t_time, &temp->moment ); printf("# Measurement value of %d sensor is %d, it took %d\n", ptemp+1, temp->value, lag.tv_nsec); increment_timespec(&total_lag, &lag); if (aio_return(((struct aiocb*)siginfo->si_value.sival_ptr)) > 0 ) aio_read(((struct aiocb*)siginfo->si_value.sival_ptr)); else printf("-------------EOF in sensor #%d, %d remaining--------------------\n", ptemp+1, --NSENS); } }
resultado Experimento(int V, double p) { int i, j; struct timespec M_dfs_ini, M_dfs_fim, M_bfs_ini, M_bfs_fim; struct timespec L_dfs_ini, L_dfs_fim, L_bfs_ini, L_bfs_fim; resultado ans; Digraph G = DIGRAPHinit(V); f (i, 0, V) f (j, 0, V) if (i != j && rand() < p*RAND_MAX) DIGRAPHinsertA (G, i, j); clock_gettime(CLOCK_REALTIME, &M_dfs_ini); f (i, 0, 8) DIGRAPHdfsM (G); clock_gettime(CLOCK_REALTIME, &M_dfs_fim); ans.m_dfs = diff_timespec(M_dfs_fim, M_dfs_ini); clock_gettime(CLOCK_REALTIME, &L_dfs_ini); f (i, 0, 8) DIGRAPHdfsL (G); clock_gettime(CLOCK_REALTIME, &L_dfs_fim); ans.l_dfs = diff_timespec(L_dfs_fim, L_dfs_ini); clock_gettime(CLOCK_REALTIME, &M_bfs_ini); f (i, 0, V) f(j, 0, 8) DIGRAPHbfsM(G, i); clock_gettime(CLOCK_REALTIME, &M_bfs_fim); ans.m_bfs = diff_timespec(M_bfs_fim, M_bfs_ini); clock_gettime(CLOCK_REALTIME, &L_bfs_ini); f (i, 0, V) f(j, 0, 8) DIGRAPHbfsL(G, i); clock_gettime(CLOCK_REALTIME, &L_bfs_fim); ans.l_bfs = diff_timespec(L_bfs_fim, L_bfs_ini); ans.arcos = G->A; DIGRAPHfree(G); return ans; }
static void process_interval(void) { struct timespec ts, rs; read_counters(false); clock_gettime(CLOCK_MONOTONIC, &ts); diff_timespec(&rs, &ts, &ref_time); print_counters(&rs, 0, NULL); }
void end_profile_print(){ clock_gettime(CLOCK_MONOTONIC_RAW, &t2); double res = diff_timespec(&t1, &t2); LOG(L_DEBUG, NULL, "Elapsed time: %fs.", res); char buf[20]; time_t t; struct tm *tm; time(&t); tm = localtime(&t); strftime(buf, 20, "%F %T", tm); LOG(L_DEBUG, NULL, " (%s)\n", buf); }
void measure_clock_gettime(void) { struct timespec ta; struct timespec tb; int32_t granularity; int cnt = 0; clock_gettime(CLOCK_REALTIME, &ta); tb = ta; while(tb.tv_nsec == ta.tv_nsec) { clock_gettime(CLOCK_REALTIME, &ta); cnt++; } granularity = diff_timespec(&tb, &ta); printf("\tclock_gettime: %s%d ns\r\n", cnt == 1 ? "<=" : "", granularity); }
void CProfilerTask::stop(){ if(profile_enabled) { stat_it it; clock_gettime(CLOCK_MONOTONIC_RAW, &t_e); const double time_el = diff_timespec(&t, &t_e); it = stat.find(name); if( it != stat.end() ){ it->second.counter++; it->second.time += time_el; } else { Eprofile x; x.counter = 1; x.time = time_el; stat[name] = x; } state_stoped = true; } }
void get_monotonic_and_raw(struct timespec *mon, struct timespec *raw) { struct timespec start, mid, end; long long diff = 0, tmp; int i; for (i = 0; i < 3; i++) { long long newdiff; clock_gettime(CLOCK_MONOTONIC, &start); clock_gettime(CLOCK_MONOTONIC_RAW, &mid); clock_gettime(CLOCK_MONOTONIC, &end); newdiff = diff_timespec(start, end); if (diff == 0 || newdiff < diff) { diff = newdiff; *raw = mid; tmp = (ts_to_nsec(start) + ts_to_nsec(end))/2; *mon = nsec_to_ts(tmp); } } }
int main(void) { int retval = -1; fd_set rfds; int fdmax = 0; int n = 0; int i = 0; int k = 0; struct timespec sumOfDelays; struct timespec delay; struct timespec timeNow; int sensorDescriptors[10]; Tmeas measurement; int eofArray[10]; int eofCount = 0; int counter = 0; // Initialize struct timespec variables memset(&sumOfDelays, 0, sizeof(sumOfDelays)); for (i = 0; i < 10; i++) { eofArray[i] = 1; } // Specify 5 values per sensor if (StartSimulator(sensorDescriptors, 5) < 0) { fprintf(stderr, "Error: Cannot initialize sensor simulator\n"); exit(EXIT_FAILURE); } fdmax = findMaxFileDescriptor(sensorDescriptors, 10); do { FD_ZERO(&rfds); for (i = 0; i < 10; i++) { if (eofArray[i] != 0) // Add file descriptors that haven't reached EOF to the set FD_SET(sensorDescriptors[i], &rfds); } n = select(fdmax+1, &rfds, NULL, NULL, NULL); if (n > 0) { for (i = 0; i < 10; i++) { if (FD_ISSET(sensorDescriptors[i], &rfds)) { k++; /* * Sensor descriptor is ready, but it is also ready on EOF * So check for EOF condition, if EOF, then don't read it */ if (eofArray[i] == 0) // 0 indicates EOF condition break; else { retval = read(sensorDescriptors[i], &measurement, sizeof(Tmeas)); if (retval == 0) { eofArray[i] = 0; eofCount++; } else { counter++; } if (clock_gettime(CLOCK_REALTIME, &timeNow) == -1) { perror("clock gettime"); exit(EXIT_FAILURE); } delay = diff_timespec(&measurement.moment, &timeNow); increment_timespec(&sumOfDelays, &delay); } } // All ready file descriptors have been processed // So it's not necessary for looping to the end of loop if (k == n) break; } k = 0; } } while (eofCount != 10); // Display the total delay printf("Sum of delay %ld s %ld ns\n", sumOfDelays.tv_sec, sumOfDelays.tv_nsec); printf("counter %d\n", counter); return EXIT_SUCCESS; }
double end_profile(timespec *t1){ timespec t2; clock_gettime(CLOCK_MONOTONIC_RAW, &t2); return diff_timespec(t1, &t2); }
double end_profile(){ clock_gettime(CLOCK_MONOTONIC_RAW, &t2); return diff_timespec(&t1, &t2); }
int main(int argc, char **argv){ char addr[32]; if (argc < 8){ printf("not enough input args\n"); printf("usage: progname <cmd> <nbthreads> <server address> <nbquerys>\n"); printf(" cmd - 1 for query, 2 for file submission\n"); printf(" nbthreads - number of driver threads\n"); printf(" arr - ave inter-arrival time (millisecs)\n"); printf(" server address - address of auscoutd, e.g. \"localhost\"\n"); printf(" sink address - e.g. tcp://localhost:port\n"); printf(" port - port of the auscoutd server, e.g. 4005\n"); printf(" nbquerys - total number queries to submit\n"); return 0; } /*args [cmd | nbthreads | arr | server address | nbquerys ] */ const int cmd = (uint8_t)atoi(argv[1]); const int nbthreads = atoi(argv[2]); Arr = atoi(argv[3]); char *auscoutd_address = argv[4]; char *ausink_address = argv[5]; const int port = atoi(argv[6]); const int nbquerys = atoi(argv[7]); snprintf(addr, 32, "tcp://%s:%d", auscoutd_address, port); void *ctx = zmq_init(1); assert(ctx); unsigned int nb_files_per_thread = nbquerys/nbthreads; unsigned int nb_files_last_thread = nbquerys%nbthreads; fprintf(stdout,"\nfiles per thread %u\n" , nb_files_per_thread); fprintf(stdout, "files in last thread %u\n", nb_files_last_thread); fprintf(stdout, "nb threads %d\n\n" , nbthreads); uint32_t **hashes = (uint32_t**)malloc(nbquerys*sizeof(uint32_t*)); uint32_t *ptrNbframes = (uint32_t*)malloc(nbquerys*sizeof(uint32_t));; /* socket to send init signal to ausink */ void *prepskt = socket_connect(ctx, ZMQ_PAIR, ausink_address); assert(prepskt); struct timespec seed; clock_gettime(CLOCK_REALTIME, &seed); srand(seed.tv_nsec); struct timespec start_ts, end_ts; AudioMetaData phonymdata; init_mdata(&phonymdata); phonymdata.composer = "composer"; phonymdata.title2 = "title"; phonymdata.tpe1 = "performer"; phonymdata.date = "date"; phonymdata.year = 2010; phonymdata.album = "album"; phonymdata.genre = "genre"; phonymdata.duration = 1000000; phonymdata.partofset = 1; char mdata_inlinestr[512]; metadata_to_inlinestr(&phonymdata, mdata_inlinestr, 512); int i, err; if (cmd == 1 || cmd == 2){ /* querys */ for (i = 0;i < nbquerys;i++){ uint32_t nbframes = rand()%12500; uint32_t *hash = (uint32_t*)malloc(nbframes*sizeof(uint32_t)); assert(hash); hashes[i] = hash; ptrNbframes[i] = nbframes; } /* start of send time*/ clock_gettime(CLOCK_MONOTONIC, &start_ts); /* send init signal with number of files sending to ausc sink */ uint32_t nb = nbquerys; send_msg_vsm(prepskt, &nb, sizeof(uint32_t)); fprintf(stdout, "send to auscoutd\n"); ThrParam *thrparam; pthread_t *thrs = (pthread_t*)malloc((nbthreads+1)*sizeof(pthread_t)); assert(thrs); for (i=0;i<nbthreads;i++){ thrparam = (ThrParam*)malloc(sizeof(ThrParam)); assert(thrparam); thrparam->ctx = ctx; thrparam->cmd = cmd; thrparam->thrn = i; thrparam->mdatastr = mdata_inlinestr; thrparam->nbfiles = nb_files_per_thread; thrparam->address = addr; thrparam->hashes = hashes + i*nb_files_per_thread; thrparam->nbframes = ptrNbframes + i*nb_files_per_thread; assert(pthread_create(&thrs[i], NULL, query_thread, thrparam) == 0); } if (nb_files_last_thread){ thrparam = (ThrParam*)malloc(sizeof(ThrParam)); assert(thrparam); thrparam->ctx = ctx; thrparam->cmd = cmd; thrparam->thrn = nbthreads; thrparam->mdatastr = mdata_inlinestr; thrparam->nbfiles = nb_files_last_thread; thrparam->address = addr; thrparam->hashes = hashes + nbthreads*nb_files_per_thread; thrparam->nbframes = ptrNbframes + nbthreads*nb_files_per_thread; assert(pthread_create(&thrs[nbthreads], NULL, query_thread, thrparam) == 0); } /* wait for threads */ unsigned long long sum_ull, *ptr_ave = NULL; for (i=0;i < nbthreads;i++){ pthread_join(thrs[i], (void**)&ptr_ave); sum_ull += *ptr_ave; } if (nb_files_last_thread){ pthread_join(thrs[nbthreads], (void**)&ptr_ave); sum_ull += *ptr_ave; } /* end of sending */ clock_gettime(CLOCK_MONOTONIC, &end_ts); struct timespec total_ts = diff_timespec(start_ts, end_ts); unsigned long long total = 1000000000*total_ts.tv_sec + total_ts.tv_nsec; float total_secs = (float)total/1000000000.0f; float ave_latency = (float)sum_ull/(float)nbquerys/1000000000.0f; float rate = (float)nbquerys/total_secs; fprintf(stdout,"ave latency, %f secs\n", ave_latency); fprintf(stdout,"rate: %f querys/sec\n", rate); fprintf(stdout,"total time, %f secs\n", total_secs); } else { fprintf(stdout,"unrecognized cmd, %u\n", cmd); } zmq_close(prepskt); zmq_term(ctx); return 0; }
void* query_thread(void *arg){ ThrParam *thrparam = (ThrParam*)arg; void *ctx = thrparam->ctx; char *mdatastr = thrparam->mdatastr; uint32_t **hashes = thrparam->hashes; uint32_t *pnbframes = thrparam->nbframes; unsigned int nbfiles = thrparam->nbfiles; uint8_t thrn = thrparam->thrn; uint8_t cmd = thrparam->cmd; void *skt = zmq_socket(ctx, ZMQ_REQ); assert(skt); fprintf(stdout,"thrn%d: connect to %s\n", thrn, thrparam->address); assert(zmq_connect(skt, thrparam->address)==0); unsigned int i,j; void *data; int64_t more; size_t msg_size, more_size=sizeof(int64_t); struct timespec t1_ts, t2_ts, diff_ts; unsigned long long latency, sum_ull = 0ULL; if (cmd == 1){ /* queries */ for (i=0;i<nbfiles;i++){ clock_gettime(CLOCK_MONOTONIC, &t1_ts); sendmore_msg_vsm(skt, &cmd, sizeof(uint8_t)); uint32_t snbframes = hosttonet32(pnbframes[i]); sendmore_msg_vsm(skt, &snbframes, sizeof(uint32_t)); send_msg_data(skt, hashes[i], pnbframes[i]*sizeof(uint32_t), free_fn, NULL); recieve_msg(skt, &msg_size, &more, &more_size, &data); clock_gettime(CLOCK_MONOTONIC, &t2_ts); diff_ts = diff_timespec(t1_ts, t2_ts); latency = 1000000000*diff_ts.tv_sec + diff_ts.tv_nsec; sum_ull += latency; fprintf(stdout,"thrd%d: query %u frames, recv:\"%s\" in %llu nsecs\n",\ thrn,pnbframes[i],(char*)data, latency); free(data); /* simulate interarrival */ unsigned int pause = Arr; /* = next_arrival(Arr);*/ usleep(1000*pause); } } else if (cmd == 2){ /* submissions */ for (i=0;i<nbfiles;i++){ clock_gettime(CLOCK_MONOTONIC, &t1_ts); sendmore_msg_vsm(skt, &cmd, sizeof(uint8_t)); uint32_t snbframes = hosttonet32(pnbframes[i]); sendmore_msg_vsm(skt, &snbframes, sizeof(uint32_t)); sendmore_msg_data(skt, hashes[i], pnbframes[i]*sizeof(uint32_t), free_fn, NULL); send_msg_data(skt, mdatastr, strlen(mdatastr)+1, NULL, NULL); recieve_msg(skt, &msg_size, &more, &more_size, &data); assert(msg_size == sizeof(uint32_t)); uint32_t uid; memcpy(&uid, data, sizeof(uint32_t)); uid = nettohost32(uid); clock_gettime(CLOCK_MONOTONIC, &t2_ts); diff_ts = diff_timespec(t1_ts, t2_ts); latency = 1000000000*diff_ts.tv_sec + diff_ts.tv_nsec; sum_ull += latency; fprintf(stdout,"thr%d: submit %u frames, recv %u=uid in %llu nsecs\n",\ thrn, pnbframes[i], uid, latency); /* simulate interarrival */ unsigned int pause = Arr; /*next_arrival(Arr);*/ usleep(1000*pause); free(data); } } free(thrparam); zmq_close(skt); /* return the sum of latency's */ void *ptr = malloc(sizeof(unsigned long long)); assert(ptr); memcpy(ptr, &sum_ull, sizeof(unsigned long long)); pthread_exit(ptr); }
int main( int argc, char ** argv ) { struct timespec start, end; char buffer[32] = {0}; const int vals = 10000000; unsigned long *val = new unsigned long[vals]; long int duration; long test_len; test_len = to_dec_c( 0xDEADBEEFDEADBEEF, buffer, 32 ); buffer[test_len] = 0x00; printf( "Test 1 0xDEADBEEFDEADBEEF = %s\n", buffer ); test_len = to_dec( 0xDEADBEEFDEADBEEF, buffer, 32 ); buffer[test_len] = 0x00; printf( "Test 2 0xDEADBEEFDEADBEEF = %s\n", buffer ); test_len = to_dec( 0xFFFFFFFFFFFFFFFF, buffer, 32 ); buffer[test_len] = 0x00; printf( "Test 3 0xFFFFFFFFFFFFFFEF = %s\n", buffer ); test_len = to_dec_c( 0xFFFFFFFFFFFFFFFF, buffer, 32 ); buffer[test_len] = 0x00; printf( "Test 4 0xFFFFFFFFFFFFFFEF = %s\n", buffer ); test_len = to_dec( (unsigned long)0xFFFFFFFF, buffer, 32 ); buffer[test_len] = 0x00; printf( "Test 5 0xFFFFFFFF = %s\n", buffer ); test_len = to_dec_c( (unsigned long)0xFFFFFFFF, buffer, 32 ); buffer[test_len] = 0x00; printf( "Test 6 0xFFFFFFFF = %s\n", buffer ); printf( "Array setup..." ); fflush(NULL); for( int x = 0; x < vals; x++ ) { val[x] = x; } printf( "done\n" ); current_utc_time( &start ); for( int x = 0; x < vals ; x++ ) { long len = to_dec( val[x], buffer, 32 ); } current_utc_time( &end ); duration = diff_timespec( start, end ); printf( "to_dec, source is array\n" ); printf( "Completed in %8.8f sec (%ld nsec avg)\n\n", (double)duration/nsec_per_sec, duration/vals ); current_utc_time( &start ); for( int x = 0; x < vals ; x++ ) { long len = to_dec( x, buffer, 32 ); } current_utc_time( &end ); duration = diff_timespec( start, end ); printf( "to_dec, source is calculated\n" ); printf( "Completed in %8.8f sec (%ld nsec avg)\n\n", (double)duration/(double)nsec_per_sec, duration/vals ); current_utc_time( &start ); for( int x = 0; x < vals ; x++ ) { long len = to_dec_c( val[x], buffer, 32 ); } current_utc_time( &end ); duration = diff_timespec( start, end ); printf( "to_dec_c, source is array\n" ); printf( "Completed in %8.8f sec (%ld nsec avg)\n\n", (double)duration/(double)nsec_per_sec, duration/vals ); current_utc_time( &start ); for( int x = 0; x < vals ; x++ ) { long len = to_dec_c( x, buffer, 32 ); } current_utc_time( &end ); duration = diff_timespec( start, end ); printf( "to_dec_c, source is calculated\n" ); printf( "Completed in %8.8f sec (%ld nsec avg)\n\n", (double)duration/(double)nsec_per_sec, duration/vals ); return 0; }
int main(int argc, char **argv){ char addr[32]; if (argc < 4){ fprintf(stdout,"not enough args\n"); fprintf(stdout,"usage: prog <auscoutd address> <port> <port>\n"); fprintf(stdout,"address - mock auscoud server address, e.g. \"localhost\"\n"); fprintf(stdout,"port - mock auscoutd server port e.g. 4005\n"); fprintf(stdout,"port - port to recieve init from auscout driver, e.g. 4009\n"); return 0; } /* progname <auscoutd address> <auscoutd port> <driver port>*/ const char *auscoutd_address = argv[1]; const int port = atoi(argv[2]); const int driver_port = atoi(argv[3]); int subscr_port = port + 2; int result_port = port + 3; int table_port = port + 1; snprintf(addr, 32, "tcp://%s:%d", auscoutd_address, table_port); fprintf(stdout,"register as table with %s\n", addr); void *ctx = zmq_init(1); assert(ctx); assert(register_table(ctx, addr) == 0); /* skt to recieve number of files to be sent from auscout driver program */ snprintf(addr, 32, "tcp://*:%d", driver_port); void *prepskt = socket_bind(ctx, ZMQ_PAIR, addr); assert(prepskt); snprintf(addr, 32, "tcp://%s:%d", auscoutd_address, subscr_port); void *subscr_skt = socket_connect(ctx, ZMQ_SUB, addr); assert(subscr_skt); assert(zmq_setsockopt(subscr_skt, ZMQ_SUBSCRIBE, "phash.", 6) == 0); snprintf(addr, 32, "tcp://%s:%d", auscoutd_address, result_port); void *result_skt = socket_connect(ctx, ZMQ_REQ, addr); assert(result_skt); struct timespec seed_ts; clock_gettime(CLOCK_REALTIME, &seed_ts); srand(seed_ts.tv_nsec); uint8_t cmd, thrdnum, tblnum; struct timespec start_ts, end_ts, diff_ts; uint32_t uid, nbframes, count = 0, nbquerys; void *data; int64_t more; size_t msg_size, more_size = sizeof(int64_t); float cs = 0.05555f; fprintf(stdout,"\nready to recieve subscription messages from auscoutd ...\n\n"); while (1){ recieve_msg(prepskt, &msg_size, &more, &more_size, &data); assert(msg_size == sizeof(uint32_t)); memcpy(&nbquerys, data, sizeof(uint32_t)); free(data); fprintf(stdout,"expecting %d querys\n\n", nbquerys); clock_gettime(CLOCK_MONOTONIC, &start_ts); count = 0; do { /* recieve topic */ recieve_msg(subscr_skt, &msg_size, &more, &more_size, &data); free(data); /* recieve cmd */ recieve_msg(subscr_skt, &msg_size, &more, &more_size, &data); memcpy(&cmd, data, sizeof(uint8_t)); free(data); recieve_msg(subscr_skt, &msg_size, &more, &more_size, &data); memcpy(&nbframes, data, sizeof(uint32_t)); nbframes = nettohost32(nbframes); free(data); /* recieve hash */ recieve_msg(subscr_skt, &msg_size, &more, &more_size, &data); free(data); recieve_msg(subscr_skt, &msg_size, &more, &more_size, &data); memcpy(&thrdnum, data, sizeof(uint8_t)); free(data); recieve_msg(subscr_skt, &msg_size, &more, &more_size, &data); memcpy(&uid, data, sizeof(uint32_t)); uid = nettohost32(uid); free(data); if (cmd == 1){ /* recieved lookup */ uid = 0; /* send back random integer id*/ cs = 0.5555; fprintf(stdout,"(%d) lookup: %u frames\n",count,nbframes); fprintf(stdout," reply : thrdnum %u | uid %u | cs %f\n\n",thrdnum,uid,cs); uid = hosttonet32(uid); cs = hosttonetf(cs); sendmore_msg_vsm(result_skt, &thrdnum, sizeof(uint8_t)); sendmore_msg_vsm(result_skt, &uid, sizeof(uint32_t)); send_msg_vsm(result_skt, &cs, sizeof(float)); recieve_msg(result_skt, &msg_size, &more, &more_size, &data); free(data); } else if (cmd == 2){ tblnum = thrdnum; /* recieved submission */ fprintf(stdout,"(%d) submit: %u frames | %u table\n",count,nbframes,tblnum); fprintf(stdout," no reply\n\n"); } fprintf(stdout,"**************************************\n"); } while (++count < nbquerys); clock_gettime(CLOCK_MONOTONIC, &end_ts); diff_ts = diff_timespec(start_ts, end_ts); unsigned long long total_ull = 1000000000*diff_ts.tv_sec + diff_ts.tv_nsec; float total_secs = (float)total_ull/1000000000.0f; float rate = (float)nbquerys/total_secs; fprintf(stdout,"recieved %d querys in %f secs - %f querys/sec\n",\ nbquerys, total_secs, rate); } zmq_close(subscr_skt); zmq_close(result_skt); zmq_close(prepskt); zmq_term(ctx); return 0; }
long long time_diff_ms(struct timespec start, struct timespec end) { return millisec_elapsed(diff_timespec(start, end)); }
void TheLife::LoadLife() { struct timespec start; struct timespec end; struct timespec diff; clock_gettime(CLOCK_MONOTONIC, &start); LogHandler::WriteLog(sLanguage->Get("LOG_LOAD_BEGIN")); pthread_t main, status; //Life Initialization sUI->lwin[0].buf[0] = 0x00; sUI->lwin[1].buf[0] = 0x00; // Init NCurses LogHandler::WriteLog(sLanguage->Get("LOG_LOAD_CURSES")); initscr(); start_color(); use_default_colors(); //noecho(); keypad(stdscr, true); // Init colors LogHandler::WriteLog(sLanguage->Get("LOG_LOAD_COLOR")); init_pair(1, 1, -1); init_pair(2, 2, -1); init_pair(3, 3, -1); init_pair(4, 4, -1); // Init UI LogHandler::WriteLog(sLanguage->Get("LOG_LOAD_UI")); Interface::Load(); sUI->SetHidden(false, WINDOW_CONSOLE); sUI->SetHidden(false, WINDOW_STATUS); // Init Player LogHandler::WriteLog(sLanguage->Get("LOG_LOAD_PLAYER")); FileHandler::PlayerInit(); // Init SIGWICH (Console change signal) to SigHandler LogHandler::WriteLog(sLanguage->Get("LOG_LOAD_SIGWINCH")); signal(SIGWINCH, TheLife::SigHandler); // Thread spawning LogHandler::WriteLog(sLanguage->Get("LOG_LOAD_TH_SPAWN")); pthread_create(&status, NULL, Thread::Status, NULL); pthread_create(&main, NULL, Thread::Run, NULL); LogHandler::WriteLog(sLanguage->Get("LOG_LOAD_TH_ADD")); sThread->AddThread(status); sThread->AddThread(main); LogHandler::WriteLog(sLanguage->Get("LOG_LOAD_TH_JOIN")); pthread_join(status,NULL); pthread_join(main, NULL); LogHandler::WriteLog(sLanguage->Get("LOG_LOAD_END")); clock_gettime(CLOCK_MONOTONIC, &end); diff = diff_timespec(start, end); Debug("Load took %lld milliseconds\n", millisec_elapsed(diff)); }