int main(int argc, char *argv[]) { extern char *bwa_pg; int i, ret; double t_real; kstring_t pg = {0,0,0}; t_real = realtime(); ksprintf(&pg, "@PG\tID:biscuit\tPN:biscuit\tVN:%s\tCL:%s", PACKAGE_VERSION, argv[0]); for (i = 1; i < argc; ++i) ksprintf(&pg, " %s", argv[i]); bwa_pg = pg.s; if (argc < 2) return usage(); if (strcmp(argv[1], "index") == 0) ret = main_biscuit_index(argc-1, argv+1); else if (strcmp(argv[1], "align") == 0) ret = main_align(argc-1, argv+1); else if (strcmp(argv[1], "pileup") == 0) ret = main_pileup(argc-1, argv+1); else if (strcmp(argv[1], "somatic") == 0) ret = main_somatic(argc-1, argv+1); else { fprintf(stderr, "[main] unrecognized command '%s'\n", argv[1]); return 1; } err_fflush(stdout); err_fclose(stdout); if (ret == 0) { fprintf(stderr, "[%s] Version: %s\n", __func__, PACKAGE_VERSION); fprintf(stderr, "[%s] CMD:", __func__); for (i = 0; i < argc; ++i) fprintf(stderr, " %s", argv[i]); fprintf(stderr, "\n[%s] Real time: %.3f sec; CPU: %.3f sec\n", __func__, realtime() - t_real, cputime()); } free(bwa_pg); return ret; }
static realtime_t get_nss_cert_notafter(CERTCertificate *cert) { PRTime notBefore, notAfter; if (CERT_GetCertTimes(cert, ¬Before, ¬After) != SECSuccess) return realtime(-1); else return realtime(notAfter / PR_USEC_PER_SEC); }
int main(int argc, char *argv[]) { int i, ret; double t_real; kstring_t pg = {0,0,0}; t_real = realtime(); ksprintf(&pg, "@PG\tID:bwa\tPN:bwa\tVN:%s\tCL:%s", PACKAGE_VERSION, argv[0]); for (i = 1; i < argc; ++i) ksprintf(&pg, " %s", argv[i]); bwa_pg = pg.s; if (argc < 2) return usage(); if (strcmp(argv[1], "fa2pac") == 0) ret = bwa_fa2pac(argc-1, argv+1); else if (strcmp(argv[1], "pac2bwt") == 0) ret = bwa_pac2bwt(argc-1, argv+1); else if (strcmp(argv[1], "pac2bwtgen") == 0) ret = bwt_bwtgen_main(argc-1, argv+1); else if (strcmp(argv[1], "bwtupdate") == 0) ret = bwa_bwtupdate(argc-1, argv+1); else if (strcmp(argv[1], "bwt2sa") == 0) ret = bwa_bwt2sa(argc-1, argv+1); else if (strcmp(argv[1], "index") == 0) ret = bwa_index(argc-1, argv+1); else if (strcmp(argv[1], "aln") == 0) ret = bwa_aln(argc-1, argv+1); else if (strcmp(argv[1], "samse") == 0) ret = bwa_sai2sam_se(argc-1, argv+1); else if (strcmp(argv[1], "sampe") == 0) ret = bwa_sai2sam_pe(argc-1, argv+1); else if (strcmp(argv[1], "bwtsw2") == 0) ret = bwa_bwtsw2(argc-1, argv+1); else if (strcmp(argv[1], "dbwtsw") == 0) ret = bwa_bwtsw2(argc-1, argv+1); else if (strcmp(argv[1], "bwasw") == 0) ret = bwa_bwtsw2(argc-1, argv+1); else if (strcmp(argv[1], "fastmap") == 0) ret = main_fastmap(argc-1, argv+1); else if (strcmp(argv[1], "mem") == 0) ret = main_mem(argc-1, argv+1); else if (strcmp(argv[1], "pemerge") == 0) ret = main_pemerge(argc-1, argv+1); else { fprintf(stderr, "[main] unrecognized command '%s'\n", argv[1]); return 1; } #ifdef USE_HTSLIB if (strcmp(argv[1], "mem") != 0) { err_fflush(stdout); err_fclose(stdout); } #else err_fflush(stdout); err_fclose(stdout); #endif if (ret == 0) { fprintf(stderr, "[%s] Version: %s\n", __func__, PACKAGE_VERSION); fprintf(stderr, "[%s] CMD:", __func__); for (i = 0; i < argc; ++i) fprintf(stderr, " %s", argv[i]); fprintf(stderr, "\n[%s] Real time: %.3f sec; CPU: %.3f sec\n", __func__, realtime() - t_real, cputime()); } free(bwa_pg); return ret; }
int process_update_command ( char *key, size_t nkey, uint32_t flags, char *value, size_t nbytes, int32_t exptime_int, int comm ) { item *it; enum store_item_type ret; int32_t vlen = ( int32_t ) nbytes; if ( exptime_int < 0 ) exptime_int = REALTIME_MAXDELTA + 1; vlen += 2; if ( vlen < 0 || vlen - 2 < 0 ) { return false; } it = item_alloc (key, nkey, flags, realtime (exptime_int), value, vlen); if ( it == 0 ) { if ( comm == NREAD_SET ) { it = item_get (key, nkey); if ( it ) { item_unlink (it); item_remove (it); } } return false; } ret = store_item (it, comm); item_remove (it); if ( ret != STORED ) { return false; } return true; }
int VersionSlider::value() { if(realtime()) { return ui->versionSpin->maximum() - 1; } else { return ui->versionSpin->value(); } }
int main(int argc, char *argv[]) { int i, ret; double t_real; t_real = realtime(); if (argc < 2) return usage(); /* if (strcmp(argv[1], "fa2pac") == 0) ret = bwa_fa2pac(argc-1, argv+1); */ /* else if (strcmp(argv[1], "pac2bwt") == 0) ret = bwa_pac2bwt(argc-1, argv+1); * else if (strcmp(argv[1], "pac2bwtgen") == 0) ret = bwt_bwtgen_main(argc-1, argv+1); * else if (strcmp(argv[1], "bwtupdate") == 0) ret = bwa_bwtupdate(argc-1, argv+1); * else if (strcmp(argv[1], "bwt2sa") == 0) ret = bwa_bwt2sa(argc-1, argv+1); */ else if (strcmp(argv[1], "index") == 0) ret = bwa_index_main(argc-1, argv+1); else if (strcmp(argv[1], "aln") == 0) ret = bwa_aln(argc-1, argv+1); /* else if (strcmp(argv[1], "samse") == 0) ret = bwa_sai2sam_se(argc-1, argv+1); */ /* else if (strcmp(argv[1], "sw") == 0) ret = bwa_stdsw(argc-1, argv+1); * * else if (strcmp(argv[1], "sampe") == 0) ret = bwa_sai2sam_pe(argc-1, argv+1); * else if (strcmp(argv[1], "pac2cspac") == 0) ret = bwa_pac2cspac(argc-1, argv+1); * else if (strcmp(argv[1], "stdsw") == 0) ret = bwa_stdsw(argc-1, argv+1); * else if (strcmp(argv[1], "bwtsw2") == 0) ret = bwa_bwtsw2(argc-1, argv+1); * else if (strcmp(argv[1], "dbwtsw") == 0) ret = bwa_bwtsw2(argc-1, argv+1); * else if (strcmp(argv[1], "bwasw") == 0) ret = bwa_bwtsw2(argc-1, argv+1); * else if (strcmp(argv[1], "fastmap") == 0) ret = main_fastmap(argc-1, argv+1); */ else { fprintf(stderr, "[main] unrecognized command '%s'\n", argv[1]); return 1; } err_fflush(stdout); err_fclose(stdout); if (ret == 0) { fprintf(stderr, "[%s] Version: %s\n", __func__, PACKAGE_VERSION); fprintf(stderr, "[%s] CMD:", __func__); for (i = 0; i < argc; ++i) fprintf(stderr, " %s", argv[i]); fprintf(stderr, "\n[%s] Real time: %.3f sec; CPU: %.3f sec\n", __func__, realtime() - t_real, cputime()); } return 0; }
void VersionSlider::updateTime(void) { if(showUpdate) { currentMaxTimestamp = maxTimestamp; } if(currentMaxTimestamp > 20000000) currentMaxTimestamp = 20000000; if(currentTimestamp > 20000000) currentTimestamp = 20000000; if(realtime()) { currentTimestamp = currentMaxTimestamp; } ui->versionSlider->setMaximum(ceil(currentMaxTimestamp * 100)); ui->versionSlider->setValue(ceil(currentTimestamp * 100)); QString text = realtime()? "(R) " : ""; text += QString::number(currentTimestamp); ui->currentTimeLabel->setText(text); }
// 1 is incomplete, 2 is fail, 0 is complete. Nothing will be written // to 'out' unless we returned 0. int mm_inject (byte b, struct mm_msg *out) { static byte lasttype = 0; static byte lastchan = 0; static struct mm_msg bytes; static int nbytes = 0; if (realtime(b)) { out->type = b; return 0; } switch (nbytes) { case 0: if (b & 0x80) { // New status lasttype = bytes.type = (b&0x70)>>4; lastchan = bytes.chan = b & 0x0F; nbytes = 1; } else { // Running status
void mm_mapopt_update(mm_mapopt_t *opt, const mm_idx_t *mi) { if ((opt->flag & MM_F_SPLICE_FOR) || (opt->flag & MM_F_SPLICE_REV) || (mi->splices != 0)) opt->flag |= MM_F_SPLICE; if (opt->specified_intron_score < 0) opt->specified_intron_score = opt->noncan / 2; if (opt->mid_occ <= 0) opt->mid_occ = mm_idx_cal_max_occ(mi, opt->mid_occ_frac); if (opt->mid_occ < opt->min_mid_occ) opt->mid_occ = opt->min_mid_occ; if (mm_verbose >= 3) fprintf(stderr, "[M::%s::%.3f*%.2f] mid_occ = %d\n", __func__, realtime() - mm_realtime0, cputime() / (realtime() - mm_realtime0), opt->mid_occ); }
void mm_write (int fd, struct mm_msg *m) { static byte lasttype = MM_RESET; int size = msgsize(m->type); byte status = 0x80 | (m->chan&0x0F) | ((m->type&0x07)<<4); byte buf[3] = {status, m->arg1, m->arg2}; if (realtime(m->type)) { E("write", write(fd, &m->type, 1)); return; } { byte *out = buf; if (lasttype == status) { size--; out++; } for (;;) { int written = write(fd, out, size); if (!written) exit(0); if (written == size) break; if (written < 0) err(1, "write"); size -= written; out += written; }}}
int process_touch_command ( char *key, size_t nkey, int32_t exptime_int ) { item *it; it = item_touch (key, nkey, realtime (exptime_int)); if ( it ) { item_update (it); item_remove (it); return true; } else { //item_remove(it); return false; } }
void VersionSlider::onUpdateVersionCount(int versionCount) { bool versionChange = false; bool inRealtime = realtime(); if(value() > versionCount || inRealtime) versionChange = true; setMaximum(versionCount); if(inRealtime) { setRealtime(); } if(versionChange) emit changeWsnVersion(value()); }
time_t time(time_t *tloc) { time_t rval; if (use_realtime) { time_t (*realtime)(time_t *tloc) = dlsym(RTLD_NEXT, "time"); if (dlerror()) { rval = (time_t)-1; } rval = realtime(tloc); } else { if (tloc) { *tloc = faketime; } rval = faketime; } return rval; }
int DMxVMPI(int argc, char *argv[], int numProcs, int myid) { int ret_code = 1; int option; unsigned long *II; unsigned long *J; double *values; unsigned long M; unsigned long local_M; unsigned long N; unsigned long long nz; double *vectorValues; unsigned long M_Vector; unsigned long N_Vector; unsigned long long nz_vector; char *outputFileName = NULL; char *inputMatrixFile = NULL; char *inputVectorFile = NULL; char *outputVectorFile = NULL; int inputFormatRow = 0; double alpha = 1.0; double beta = 0.0; int numThreads = 1; int i, j; while ((option = getopt(argc, argv,"ro:a:b:t:")) >= 0) { switch (option) { case 'o' : //free(outputFileName); outputFileName = (char *) malloc(sizeof(char)*strlen(optarg)+1); strcpy(outputFileName,optarg); break; case 'r': inputFormatRow = 1; break; case 'b': beta = atof(optarg); break; case 'a': alpha = atof(optarg); break; case 't': numThreads = atoi(optarg); break; default: break; } } if ((optind + 3 != argc) && (optind + 2 != argc)) { if (myid == 0) { //fprintf(stderr,"[%s] Argc: %d, optind: %d\n",__func__, argc, optind); usageDMxVMPI(); } return 0; } openblas_set_num_threads(numThreads); if(optind + 3 == argc) { //We have an output vector outputVectorFile = (char *)malloc(sizeof(char)*strlen(argv[optind+2])+1); strcpy(outputVectorFile,argv[optind+2]); } if(outputFileName == NULL) { outputFileName = (char *) malloc(sizeof(char)*6); sprintf(outputFileName,"stdout"); } inputMatrixFile = (char *)malloc(sizeof(char)*strlen(argv[optind])+1); inputVectorFile = (char *)malloc(sizeof(char)*strlen(argv[optind+1])+1); strcpy(inputMatrixFile,argv[optind]); strcpy(inputVectorFile,argv[optind+1]); //Read matrix if(inputFormatRow) { if(!readDenseCoordinateMatrixMPIRowLine(inputMatrixFile,&II,&J,&values,&M,&local_M,&N,&nz,myid, numProcs)){ fprintf(stderr, "[%s] Can not read Matrix\n",__func__); return 0; } } else{ if(!readDenseCoordinateMatrixMPI(inputMatrixFile,&II,&J,&values,&M,&local_M,&N,&nz,myid, numProcs)){ fprintf(stderr, "[%s] Can not read Matrix\n",__func__); return 0; } } //Read input vector if(!readDenseVector(inputVectorFile, &vectorValues,&M_Vector,&N_Vector,&nz_vector)){ fprintf(stderr, "[%s] Can not read Vector\n",__func__); return 0; } /* void cblas_dgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE TransA, const int M, const int N, const double alpha, const double *A, const int lda, const double *X, const int incX, const double beta, double *Y, const int incY); */ double *partial_result=(double *) calloc(local_M,sizeof(double)); double* y = (double*)calloc(N,sizeof(double)); if(y == NULL){ fprintf(stderr,"[%s] Error reserving memory for final result vector in processor %d\n",__func__,myid); return 0; } //Read output vector if any if(outputVectorFile != NULL) { if(!readDenseVector(outputVectorFile, &y,&M_Vector,&N_Vector,&nz_vector)){ fprintf(stderr, "[%s] Can not read Vector %s\n",__func__, outputVectorFile); return 0; } for( i = (local_M * myid), j = 0; i< (local_M * myid + local_M) && j< local_M; i++, j++) { partial_result[j] = y [i]; } } double t_real = realtime(); //y := alpha * A * x + beta * y //cblas_dgemv(CblasRowMajor,CblasNoTrans,local_M,N,1.0,values,N,vectorValues,1,0.0,partial_result,1); cblas_dgemv(CblasRowMajor,CblasNoTrans,local_M,N,alpha,values,N,vectorValues,1,beta,partial_result,1); MPI_Allgather (partial_result,local_M,MPI_DOUBLE,y,local_M,MPI_DOUBLE,MPI_COMM_WORLD); MPI_Barrier(MPI_COMM_WORLD); fprintf(stderr, "\n[%s] Time spent in DMxV: %.6f sec\n", __func__, realtime() - t_real); if (myid == 0){ writeDenseVector(outputFileName, y,M_Vector,N_Vector,nz_vector); } return ret_code; }
// //##################################################################### // Main Program //##################################################################### // int main(int argc, char *argv[]) { // //******************************************************* // Load an image: //******************************************************* // /* // // Test Image: // long m = 100; long n = 80; long p = 50; DoubleArray3D u0(m,n,p); long i; long j; long k; for(k=0; k < p; k++) { for(j=0; j < n; j++) { for(i=0; i < m; i++) { if( i>42 && i<58) if(j>32 && j<48) if(k>17 && k<33) u0(i,j,k) = 200.0; } } } */ int m; int n; int p; GridParameters gridData; TwoPhase3D AC; double timeStart, timeTaken; RunParameters runData; long TimeSteps = 0; long outputCount = 0; double cont; double totalTime = 0.0; long kk = 0; char stemp[1024]; if (configure(argc, argv) == -1) return -1; getDAT3DInfo(IMG_FILE, &m, &n, &p); // get image dimensions //cout << endl << "Dimensions: " << m << " " << n << " " << p << endl; printf("\n Dimensions: %d %d %d \n", m, n, p); readDAT3D(u0, IMG_FILE); // //******************************************************* // Specify the computational domain and the grid size //******************************************************* // gridData.m = m; // m = the number of pixels in x-direction gridData.n = n; // n = the number of pixels in y-direction gridData.p = p; gridData.dx = 1.0; gridData.dy = 1.0; gridData.dz = 1.0; gridData.xMin = 0.0; gridData.xMax = (m - 1) * gridData.dx; gridData.yMin = 0.0; gridData.yMax = (n - 1) * gridData.dy; gridData.zMin = 0.0; gridData.zMax = (p - 1) * gridData.dz; // //******************************************************* // Declare Computational Variables and Initialize //******************************************************* // // AC.mu = 0.2 * 255 * 255; AC.mu = 0.18 * 255 * 255; AC.nu = 0.0; AC.lambda1 = 1.0; AC.lambda2 = 1.0; //cout << "Enter the Method " << endl; //cout << "e = Explicit " << endl; //cout << "i = Semi-Implicit " << endl; //cin >> AC.method; printf("Enter the Method \n"); printf("e = Explicit \n"); printf("i = Semi-Implicit \n"); AC.method = 'e'; printf("%c\n", AC.method); //cout << "Enter the Approximation to the Gradient " << endl; //cout << "g = Grad " << endl; //cout << "d = Dirac Delta " << endl; //cin >> AC.grad; printf("Enter the Approximation to the Gradient \n"); printf("g = Grad \n"); printf("d = Dirac Delta \n"); AC.grad = 'g'; printf("%c\n", AC.grad); initializePHI(phi, &gridData); // //******************************************************* // Specify run and output parameters //******************************************************* // runData.epsilon = 10e-10; //cout << "Number of TimeSteps: " << endl; //cin >> TimeSteps; printf("Number of TimeSteps: \n"); TimeSteps = 10; printf("%d\n", TimeSteps); //cout << "Output Every nth Step: " << endl; //cin >> outputCount; printf("Output Every nth Step: \n"); outputCount = 1; printf("%d\n", outputCount); runData.rkOrder = 1; runData.dt = getCourantLimit(&gridData, &AC); if (AC.method == 'i') { runData.dt = 10e7 * runData.dt; } // //******************************************************* // Output Parameters and Initial Conditions //******************************************************* // //cout << endl; ////cout << "Image: " << img_name << endl; //cout << "M = " << gridData.m << " N = " << gridData.n << " P = " << gridData.p << endl; //cout << "dx = " << gridData.dx << " dy = " << gridData.dy << " dz = " << gridData.dz << endl; //cout << endl; //cout << "Time Stepping Parameters " << endl; //cout << "Number of Steps: " << TimeSteps << endl; //cout << "dt = " << runData.dt << " RK order : " << runData.rkOrder << endl; //cout << endl; //cout << "Active Contours CV 3D Parameters" << endl; //cout << "mu = " << AC.mu / (255*255) << " * 255 * 255, nu = " << AC.nu << ", lambda1 = " << AC.lambda1 << ", lambda2 = " << AC.lambda2 << endl; //cout << endl; //cout << "Enter any character to continue..." << endl; //cin >> cont; // Plot initial data outputData(phi, gridData, 0); // //******************************************************* // Initialize Time //******************************************************* // //cout << "Time : " << totalTime << endl; printf("Time : %lf \n", totalTime); // //******************************************************* // Main Time Stepping Loop //******************************************************* // timeStart = realtime(); int Events[5]; u_long_long papi_values[5]; util_start_papi(batch_id, Events); for (kk = 1; kk <= TimeSteps; kk++) { if (AC.method == 'e') { advanceTimeStepEXPLICIT(phi, u0, &gridData, &runData, &AC); } else if (AC.method == 'i') { advanceTimeStepIMPLICIT(phi, u0, &gridData, &runData, &AC); } //cout << "Step " << kk << endl; printf("Step %d\n", kk); totalTime += runData.dt; if ((kk % outputCount) == 0) { //outputData(phi,gridData,kk); outputData(phi, gridData, kk); } //cout << endl; //cout << "Time : " << totalTime << endl; printf("\nTime : %lf \n", totalTime); } util_stop_papi(batch_id, papi_values); util_print_papi(batch_id, papi_values, (batch_id == 0)); timeTaken = realtime() - timeStart; //cout << "Filtering time : " << timeTaken << " milliseconds. (timeb.h)" << endl; //cout << "Filtering time : " << timeTaken/1000 << " seconds. (timeb.h)" << endl; printf("Filtering time : %lf milliseconds (timeb.h)\n", timeTaken); return 0; }
bool BatteryMonitor::update(void) { bool logthis; props.chargerAcOnline = false; props.chargerUsbOnline = false; props.chargerWirelessOnline = false; props.batteryStatus = BATTERY_STATUS_UNKNOWN; props.batteryHealth = BATTERY_HEALTH_UNKNOWN; if (!mHealthdConfig->batteryPresentPath.isEmpty()) props.batteryPresent = getBooleanField(mHealthdConfig->batteryPresentPath); else props.batteryPresent = mBatteryDevicePresent; props.batteryLevel = mBatteryFixedCapacity ? mBatteryFixedCapacity : getIntField(mHealthdConfig->batteryCapacityPath); props.batteryVoltage = getIntField(mHealthdConfig->batteryVoltagePath) / 1000; props.batteryTemperature = mBatteryFixedTemperature ? mBatteryFixedTemperature : getIntField(mHealthdConfig->batteryTemperaturePath); const int SIZE = 128; char buf[SIZE]; String8 btech; if (readFromFile(mHealthdConfig->batteryStatusPath, buf, SIZE) > 0) props.batteryStatus = getBatteryStatus(buf); if (readFromFile(mHealthdConfig->batteryHealthPath, buf, SIZE) > 0) props.batteryHealth = getBatteryHealth(buf); if (readFromFile(mHealthdConfig->batteryTechnologyPath, buf, SIZE) > 0) props.batteryTechnology = String8(buf); unsigned int i; for (i = 0; i < mChargerNames.size(); i++) { String8 path; path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, mChargerNames[i].string()); if (readFromFile(path, buf, SIZE) > 0) { if (buf[0] != '0') { path.clear(); path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, mChargerNames[i].string()); switch(readPowerSupplyType(path)) { case ANDROID_POWER_SUPPLY_TYPE_AC: props.chargerAcOnline = true; break; case ANDROID_POWER_SUPPLY_TYPE_USB: props.chargerUsbOnline = true; break; case ANDROID_POWER_SUPPLY_TYPE_WIRELESS: props.chargerWirelessOnline = true; break; default: KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n", mChargerNames[i].string()); } } } } logthis = !healthd_board_battery_update(&props); if (logthis) { char dmesgline[256]; if (props.batteryPresent) { snprintf(dmesgline, sizeof(dmesgline), "battery l=%d v=%d t=%s%d.%d h=%d st=%d", props.batteryLevel, props.batteryVoltage, props.batteryTemperature < 0 ? "-" : "", abs(props.batteryTemperature / 10), abs(props.batteryTemperature % 10), props.batteryHealth, props.batteryStatus); if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) { int c = getIntField(mHealthdConfig->batteryCurrentNowPath); char b[20]; snprintf(b, sizeof(b), " c=%d", c / 1000); strlcat(dmesgline, b, sizeof(dmesgline)); } } else { snprintf(dmesgline, sizeof(dmesgline), "battery none"); } size_t len = strlen(dmesgline); snprintf(dmesgline + len, sizeof(dmesgline) - len, " chg=%s%s%s", props.chargerAcOnline ? "a" : "", props.chargerUsbOnline ? "u" : "", props.chargerWirelessOnline ? "w" : ""); log_time realtime(CLOCK_REALTIME); time_t t = realtime.tv_sec; struct tm *tmp = gmtime(&t); if (tmp) { static const char fmt[] = " %Y-%m-%d %H:%M:%S.XXXXXXXXX UTC"; len = strlen(dmesgline); if ((len < (sizeof(dmesgline) - sizeof(fmt) - 8)) // margin && strftime(dmesgline + len, sizeof(dmesgline) - len, fmt, tmp)) { char *usec = strchr(dmesgline + len, 'X'); if (usec) { len = usec - dmesgline; snprintf(dmesgline + len, sizeof(dmesgline) - len, "%09u", realtime.tv_nsec); usec[9] = ' '; } } } KLOG_WARNING(LOG_TAG, "%s\n", dmesgline); } healthd_mode_ops->battery_update(&props); return props.chargerAcOnline | props.chargerUsbOnline | props.chargerWirelessOnline; }
std::ostream& Timer::print( std::ostream& o ) const { o << "user time: " << usertime() << '\n' ; o << "sys. time: " << systime() << '\n' ; return o << "real time: " << realtime() << std::endl ; }
double basetime(void) { return realtime() - basetime_time; }
void RecordSample(const std::string uri, const std::string vid_file, const std::string ui_file) { // Setup Video Source pangolin::VideoRecordRepeat video(uri, vid_file, 1024*1024*200); const pangolin::VideoPixelFormat vid_fmt = video.PixFormat(); const unsigned w = video.Width(); const unsigned h = video.Height(); pangolin::InputRecordRepeat input("ui."); input.LoadBuffer(ui_file); // Create OpenGL window const int panel_width = 200; pangolin::CreateWindowAndBind("Main",w + panel_width,h); // Create viewport for video with fixed aspect pangolin::CreatePanel("ui.") .SetBounds(0.0, 1.0, 0.0, pangolin::Attach::Pix(panel_width)); pangolin::View& vVideo = pangolin::Display("Video") .SetBounds(0.0, 1.0, pangolin::Attach::Pix(panel_width), 1.0) .SetAspect((float)w/h); // OpenGl Texture for video frame pangolin::GlTexture texVideo(w,h,GL_RGBA); unsigned char* img = new unsigned char[video.SizeBytes()]; pangolin::Var<bool> record("ui.Record",false,false); pangolin::Var<bool> play("ui.Play",false,false); pangolin::Var<bool> source("ui.Source",false,false); pangolin::Var<bool> realtime("ui.realtime",true,true); pangolin::Var<float> hue("ui.Hue",0,0,360); pangolin::Var<bool> colour("ui.Colour Video",false,true); while( !pangolin::ShouldQuit() ) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Load next video frame if( video.GrabNext(img,true) ) { texVideo.Upload(img, vid_fmt.channels==1 ? GL_LUMINANCE:GL_RGB, GL_UNSIGNED_BYTE); // Associate input with this video frame input.SetIndex(video.FrameId()); } // Activate video viewport and render texture vVideo.Activate(); if( colour ) { glColorHSV(hue,0.5,1.0); }else{ glColor3f(1,1,1); } texVideo.RenderToViewportFlipY(); if(pangolin::Pushed(record)) { video.Record(); input.Record(); } if(pangolin::Pushed(play)) { video.Play(realtime); input.PlayBuffer(0,input.Size()-1); input.SaveBuffer(ui_file); } if(pangolin::Pushed(source)) { video.Source(); input.Stop(); input.SaveBuffer(ui_file); } pangolin::FinishFrame(); } delete[] img; }
void process_command(conn *c, char *command) { int comm = 0; int incr = 0; /* * for commands set/add/replace, we build an item and read the data * directly into it, then continue in nread_complete(). */ if (settings.verbose > 1) fprintf(stderr, "<%d %s\n", c->sfd, command); /* All incoming commands will require a response, so we cork at the beginning, and uncork at the very end (usually by means of out_string) */ set_cork(c, 1); if ((strncmp(command, "add ", 4) == 0 && (comm = NREAD_ADD)) || (strncmp(command, "set ", 4) == 0 && (comm = NREAD_SET)) || (strncmp(command, "replace ", 8) == 0 && (comm = NREAD_REPLACE))) { char key[251]; int flags; time_t expire; int len, res; item *it; res = sscanf(command, "%*s %250s %u %ld %d\n", key, &flags, &expire, &len); if (res!=4 || strlen(key)==0 ) { out_string(c, "CLIENT_ERROR bad command line format"); return; } expire = realtime(expire); it = item_alloc(key, flags, expire, len+2); if (it == 0) { out_string(c, "SERVER_ERROR out of memory"); /* swallow the data line */ c->write_and_go = conn_swallow; c->sbytes = len+2; return; } c->item_comm = comm; c->item = it; c->rcurr = ITEM_data(it); c->rlbytes = it->nbytes; c->state = conn_nread; return; } if ((strncmp(command, "incr ", 5) == 0 && (incr = 1)) || (strncmp(command, "decr ", 5) == 0)) { char temp[32]; unsigned int value; item *it; unsigned int delta; char key[251]; int res; char *ptr; time_t now = time(0); res = sscanf(command, "%*s %250s %u\n", key, &delta); if (res!=2 || strlen(key)==0 ) { out_string(c, "CLIENT_ERROR bad command line format"); return; } it = assoc_find(key); if (it && (it->it_flags & ITEM_DELETED)) { it = 0; } if (it && it->exptime && it->exptime < now) { item_unlink(it); it = 0; } if (!it) { out_string(c, "NOT_FOUND"); return; } ptr = ITEM_data(it); while (*ptr && (*ptr<'0' && *ptr>'9')) ptr++; value = atoi(ptr); if (incr) value+=delta; else { if (delta >= value) value = 0; else value-=delta; } sprintf(temp, "%u", value); res = strlen(temp); if (res + 2 > it->nbytes) { /* need to realloc */ item *new_it; new_it = item_alloc(ITEM_key(it), it->flags, it->exptime, res + 2 ); if (new_it == 0) { out_string(c, "SERVER_ERROR out of memory"); return; } memcpy(ITEM_data(new_it), temp, res); memcpy(ITEM_data(new_it) + res, "\r\n", 2); item_replace(it, new_it); } else { /* replace in-place */ memcpy(ITEM_data(it), temp, res); memset(ITEM_data(it) + res, ' ', it->nbytes-res-2); } out_string(c, temp); return; } if (strncmp(command, "get ", 4) == 0) { char *start = command + 4; char key[251]; int next; int i = 0; item *it; time_t now = time(0); while(sscanf(start, " %250s%n", key, &next) >= 1) { start+=next; stats.get_cmds++; it = assoc_find(key); if (it && (it->it_flags & ITEM_DELETED)) { it = 0; } if (settings.oldest_live && it && it->time <= settings.oldest_live) { item_unlink(it); it = 0; } if (it && it->exptime && it->exptime < now) { item_unlink(it); it = 0; } if (it) { if (i >= c->isize) { item **new_list = realloc(c->ilist, sizeof(item *)*c->isize*2); if (new_list) { c->isize *= 2; c->ilist = new_list; } else break; } stats.get_hits++; it->refcount++; item_update(it); *(c->ilist + i) = it; i++; } else stats.get_misses++; } c->icurr = c->ilist; c->ileft = i; if (c->ileft) { c->ipart = 0; c->state = conn_mwrite; c->ibytes = 0; return; } else { out_string(c, "END"); return; } } if (strncmp(command, "delete ", 7) == 0) { char key[251]; item *it; int res; time_t exptime = 0; res = sscanf(command, "%*s %250s %ld", key, &exptime); it = assoc_find(key); if (!it) { out_string(c, "NOT_FOUND"); return; } if (exptime == 0) { item_unlink(it); out_string(c, "DELETED"); return; } if (delcurr >= deltotal) { item **new_delete = realloc(todelete, sizeof(item *) * deltotal * 2); if (new_delete) { todelete = new_delete; deltotal *= 2; } else { /* * can't delete it immediately, user wants a delay, * but we ran out of memory for the delete queue */ out_string(c, "SERVER_ERROR out of memory"); return; } } exptime = realtime(exptime); it->refcount++; /* use its expiration time as its deletion time now */ it->exptime = exptime; it->it_flags |= ITEM_DELETED; todelete[delcurr++] = it; out_string(c, "DELETED"); return; } if (strncmp(command, "stats", 5) == 0) { process_stat(c, command); return; } if (strcmp(command, "flush_all") == 0) { settings.oldest_live = time(0); out_string(c, "OK"); return; } if (strcmp(command, "version") == 0) { out_string(c, "VERSION " VERSION); return; } if (strcmp(command, "quit") == 0) { c->state = conn_closing; return; } if (strncmp(command, "slabs reassign ", 15) == 0) { int src, dst; char *start = command+15; if (sscanf(start, "%u %u\r\n", &src, &dst) == 2) { int rv = slabs_reassign(src, dst); if (rv == 1) { out_string(c, "DONE"); return; } if (rv == 0) { out_string(c, "CANT"); return; } if (rv == -1) { out_string(c, "BUSY"); return; } } out_string(c, "CLIENT_ERROR bogus command"); return; } out_string(c, "ERROR"); return; }
double function(double x) { double t=realtime(); while(realtime()-t <= IDLETIME*x*x); return 4.0 / (1.0+x*x); }