static void benchmark(SSL *ssl, uint64_t send_bytes, uint64_t recv_bytes) { uint64_t bytes = 0; char buf[BENCH_CHUNK]; record_time_t t0, t1, t2; int sd; memset(buf, 'a', BENCH_CHUNK); record_time(&t0); if (SSL_connect(ssl) != 1) { ERR_print_errors_fp(stderr); goto out; } printf("cipher: %s\n", SSL_CIPHER_get_name(SSL_get_current_cipher(ssl))); record_time(&t1); if (send_bytes) { while (bytes < send_bytes) { int to_send = (send_bytes - bytes > BENCH_CHUNK) ? BENCH_CHUNK : send_bytes - bytes; if (SSL_write_all(ssl, buf, to_send)) break; bytes += to_send; } } else { while (bytes < recv_bytes) { int to_recv = (recv_bytes - bytes > BENCH_CHUNK) ? BENCH_CHUNK : recv_bytes - bytes; int recved; recved = SSL_read(ssl, buf, sizeof(to_recv)); if (recved > 0) bytes += recved; else break; } } record_time(&t2); print_time((send_bytes > 0) ? "sending" : "receiving", (send_bytes > 0) ? send_bytes : recv_bytes, &t1, &t2); SSL_shutdown(ssl); out: sd = SSL_get_fd(ssl); SSL_free(ssl); close(sd); }
//record the error to the file of error void record_login ( char *string ) { //the file's discribtion int fd; //open the file if ( ( fd = open ( "./login", O_RDWR|O_CREAT|O_APPEND ) ) == -1 ) { perror ( "open" ); exit (1); } //write the name of the login record_wr ( fd, string ); //write the "error" if ( write ( fd, " login at ", 10 ) != 10 ) { perror ( "write" ); exit (1); } //write the time to the file record_time ( fd ); close ( fd ); }
void read (LatencyTest & an_instance, ACE_UINT64 receive_time) { if (an_instance.seq_num == seq_num_) { record_time (receive_time); received_ = true; } }
void read (LatencyTest & an_instance, struct RTINtpTime& receive_time) { if (an_instance.seq_num == seq_num_) { record_time (receive_time); received_ = true; } }
int main(int argc, char * argv[]){ PhraseLargeTable largetable; FILE * gbfile = fopen("../../data/gb_char.table", "r"); if ( gbfile == NULL ) { fprintf(stderr, "open gb_char.table failed!\n"); return 1; } largetable.load_text(gbfile); fclose(gbfile); FILE * gbkfile = fopen("../../data/gbk_char.table", "r"); if (gbkfile == NULL ) { fprintf(stderr, "open gbk_char.table failed!\n"); return 1; } largetable.load_text(gbkfile); fclose(gbkfile); MemoryChunk * chunk = new MemoryChunk; largetable.store(chunk); largetable.load(chunk); char * linebuf = NULL; size_t size = 0; while( getline(&linebuf, &size, stdin) ){ linebuf[strlen(linebuf) - 1] = '\0'; if ( strcmp ( linebuf, "quit" ) == 0) break; glong phrase_len = g_utf8_strlen(linebuf, -1); utf16_t * new_phrase = g_utf8_to_utf16(linebuf, -1, NULL, NULL, NULL); phrase_token_t token; guint32 start = record_time(); for ( size_t i = 0; i < bench_times; ++i){ largetable.search(phrase_len, new_phrase, token); } print_time(start, bench_times); int retval = largetable.search(phrase_len, new_phrase, token); if ( retval & SEARCH_OK ) printf("%s:\t%d\n", linebuf, token); else printf("phrase %s not found.\n", linebuf); g_free(new_phrase); } if ( linebuf ) free(linebuf); return 0; }
int main(int argc, char *argv[]) { int sockfd, rval; struct sockaddr_un serv_addr, client_addr; char buf[BUF_MAX]; sockfd = socket(AF_UNIX, SOCK_DGRAM, 0); if (sockfd < 0) { LOG("opening stream socket"); ERROR("opening stream socket"); } int fd_flag, result; result = fcntl(sockfd, F_GETFD, &fd_flag); LOG("get Flag((%d)), result((%d))", fd_flag, result); fd_flag |= O_NONBLOCK; result = fcntl(sockfd, F_SETFD, fd_flag); memset(&serv_addr, 0, sizeof(serv_addr)); serv_addr.sun_family = AF_UNIX; strncpy(serv_addr.sun_path, SOCK_FILEPATH_NAME, MAX_PATH_LEN); memset(&client_addr, 0, sizeof(client_addr)); client_addr.sun_family = AF_UNIX; strncpy(client_addr.sun_path, CLIENT_ENDPOINT, MAX_PATH_LEN); // LOG("client path(%s)", client_addr.sun_path); unlink(client_addr.sun_path); if (bind(sockfd, (struct sockaddr *) &client_addr, sizeof(client_addr))) { ERROR("binding stream socket"); } if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) { LOG("connecting stream socket"); close(sockfd); ERROR("connecting stream socket"); } for (;;) { memset(buf, 0, sizeof(char) * BUF_MAX); rval = read(sockfd, buf, BUF_MAX - 1); record_time(); if (rval < 0) { LOG("ERROR reading from socket"); perror("ERROR reading from socket"); } else if (rval == 0){ LOG("connection error?"); } LOG("((%s))", buf); } close(sockfd); return EXIT_SUCCESS; }
TEST(STORE_STAT_TEST, HandleNoneZeroInput) { MEM_POOL* mem_pool = mem_pool_init(M_1M); store_stats_init(1000*10,mem_pool); uint64 i; for(i=0;i<10000;i++) record_time("index_equal",1000*100); ASSERT_EQ(100.000000,get_avg_time_inms("index_equal")); ASSERT_EQ(10000,get_count("index_equal")); ASSERT_EQ(10000,get_total_count("index_equal")); sleep(2); ASSERT_EQ(5000,get_throughput("index_equal")); }
void *start_task(void *data) { struct thread *thr = (struct thread *)data; long id = (long) thr->arg; thread_pids[id] = gettid(); unsigned long long start_time; int ret; int high = 0; cpu_set_t cpumask; cpu_set_t save_cpumask; int cpu = 0; unsigned long l; long pid; ret = sched_getaffinity(0, sizeof(save_cpumask), &save_cpumask); if (ret < 0) debug(DBG_ERR, "sched_getaffinity failed: %s\n", strerror(ret)); pid = gettid(); /* Check if we are the highest prio task */ if (id == nr_tasks-1) high = 1; while (!done) { if (high) { /* rotate around the CPUS */ if (!CPU_ISSET(cpu, &save_cpumask)) cpu = 0; CPU_ZERO(&cpumask); CPU_SET(cpu, &cpumask); cpu++; sched_setaffinity(0, sizeof(cpumask), &cpumask); } pthread_barrier_wait(&start_barrier); start_time = rt_gettime(); ftrace_write("Thread %d: started %lld diff %lld\n", pid, start_time, start_time - now); l = busy_loop(start_time); record_time(id, start_time / NS_PER_US, l); pthread_barrier_wait(&end_barrier); } return (void *)pid; }
int main(int argc, char * argv[]){ PhraseItem phrase_item; utf16_t string1 = 2; PinyinKey key1 = PinyinKey((PinyinInitial)3,(PinyinFinal)3,(PinyinTone)3); PinyinKey key2 = PinyinKey((PinyinInitial)4,(PinyinFinal)4,(PinyinTone)4); phrase_item.set_phrase_string(1, &string1); phrase_item.append_pronunciation(&key1, 100); phrase_item.append_pronunciation(&key2, 300); assert(phrase_item.get_phrase_length() == 1); PinyinKey key3; guint32 freq; phrase_item.get_nth_pronunciation(0, &key3, freq); assert(key3 == key1); assert(freq == 100); phrase_item.get_nth_pronunciation(1, &key3, freq); assert(key3 == key2); assert(freq == 300); PinyinCustomSettings custom; gfloat poss = phrase_item.get_pinyin_possibility(custom, &key1); printf("pinyin possiblitiy:%f\n", poss); assert(phrase_item.get_unigram_frequency() == 0); utf16_t string2; phrase_item.get_phrase_string(&string2); assert(string1 == string2); FacadePhraseIndex phrase_index; assert(!phrase_index.add_phrase_item(1, &phrase_item)); MemoryChunk* chunk = new MemoryChunk; assert(phrase_index.store(0, chunk)); assert(phrase_index.load(0, chunk)); PhraseItem item2; guint32 time = record_time(); for ( size_t i = 0; i < bench_times; ++i){ phrase_index.get_phrase_item(1, item2); assert(item2.get_unigram_frequency() == 0); assert(item2.get_n_pronunciation() == 2); assert(item2.get_phrase_length() == 1); assert(item2.get_pinyin_possibility(custom, &key2) == 0.75); } print_time(time, bench_times); { PhraseItem item3; phrase_index.get_phrase_item(1, item3); item3.increase_pinyin_possibility(custom, &key1, 200); assert(item3.get_pinyin_possibility(custom, &key1) == 0.5) ; } { PhraseItem item5; phrase_index.get_phrase_item(1, item5); gfloat poss = item5.get_pinyin_possibility(custom, &key1); printf("pinyin poss:%f\n", poss); assert(poss == 0.5); } FacadePhraseIndex phrase_index_load; FILE* infile = fopen("../../data/gb_char.table", "r"); if ( NULL == infile ){ fprintf(stderr, "open gb_char.table failed!\n"); exit(ENOENT); } phrase_index_load.load_text(1, infile); fclose(infile); infile = fopen("../../data/gbk_char.table", "r"); if ( NULL == infile ){ fprintf(stderr, "open gbk_char.table failed!\n"); exit(ENOENT); } phrase_index_load.load_text(2, infile); fclose(infile); phrase_index.compat(); MemoryChunk* store1 = new MemoryChunk; phrase_index_load.store(1, store1); phrase_index_load.load(1, store1); MemoryChunk* store2 = new MemoryChunk; phrase_index_load.store(2, store2); phrase_index_load.load(2, store2); phrase_index.compat(); phrase_index_load.get_phrase_item(16870555, item2); assert( item2.get_phrase_length() == 14); assert( item2.get_n_pronunciation() == 1); gunichar2 buf[1024]; item2.get_phrase_string(buf); char * string = g_utf16_to_utf8( buf, 14, NULL, NULL, NULL); printf("%s\n", string); g_free(string); guint32 delta = 3; phrase_index_load.add_unigram_frequency(16870555, delta); phrase_index_load.get_phrase_item(16870555, item2); assert( item2.get_unigram_frequency() == 3); phrase_index_load.get_phrase_item(16777222, item2); assert(item2.get_phrase_length() == 1); assert(item2.get_n_pronunciation() == 6); return 0; }
int main( int argc, char * argv[]){ SystemTableInfo system_table_info; bool retval = system_table_info.load("../../data/table.conf"); if (!retval) { fprintf(stderr, "load table.conf failed.\n"); exit(ENOENT); } pinyin_option_t options = USE_TONE; FacadeChewingTable largetable; MemoryChunk * chunk = new MemoryChunk; chunk->load("../../data/pinyin_index.bin"); largetable.load(options, chunk, NULL); const pinyin_table_info_t * phrase_files = system_table_info.get_table_info(); FacadePhraseIndex phrase_index; if (!load_phrase_index(phrase_files, &phrase_index)) exit(ENOENT); Bigram system_bigram; system_bigram.attach("../../data/bigram.db", ATTACH_READONLY); Bigram user_bigram; user_bigram.attach(NULL, ATTACH_CREATE|ATTACH_READWRITE); gfloat lambda = system_table_info.get_lambda(); PinyinLookup2 pinyin_lookup(lambda, options, &largetable, &phrase_index, &system_bigram, &user_bigram); /* prepare the prefixes for get_best_match. */ TokenVector prefixes = g_array_new (FALSE, FALSE, sizeof(phrase_token_t)); g_array_append_val(prefixes, sentence_start); CandidateConstraints constraints = g_array_new (TRUE, FALSE, sizeof(lookup_constraint_t)); MatchResults results = g_array_new(FALSE, FALSE, sizeof(phrase_token_t)); char* linebuf = NULL; size_t size = 0; ssize_t read; while( (read = getline(&linebuf, &size, stdin)) != -1 ){ if ( '\n' == linebuf[strlen(linebuf) - 1] ) { linebuf[strlen(linebuf) - 1] = '\0'; } if ( strcmp ( linebuf, "quit" ) == 0) break; FullPinyinParser2 parser; ChewingKeyVector keys = g_array_new(FALSE, FALSE, sizeof(ChewingKey)); ChewingKeyRestVector key_rests = g_array_new(FALSE, FALSE, sizeof(ChewingKeyRest)); parser.parse(options, keys, key_rests, linebuf, strlen(linebuf)); if ( 0 == keys->len ) /* invalid pinyin */ continue; /* initialize constraints. */ g_array_set_size(constraints, keys->len); for ( size_t i = 0; i < constraints->len; ++i){ lookup_constraint_t * constraint = &g_array_index(constraints, lookup_constraint_t, i); constraint->m_type = NO_CONSTRAINT; } guint32 start_time = record_time(); for ( size_t i = 0; i < bench_times; ++i) pinyin_lookup.get_best_match(prefixes, keys, constraints, results); print_time(start_time, bench_times); for ( size_t i = 0; i < results->len; ++i){ phrase_token_t * token = &g_array_index(results, phrase_token_t, i); if ( null_token == *token) continue; printf("pos:%ld,token:%d\t", i, *token); } printf("\n"); char * sentence = NULL; pinyin_lookup.convert_to_utf8(results, sentence); printf("%s\n", sentence); g_array_free(keys, TRUE); g_array_free(key_rests, TRUE); g_free(sentence); } g_array_free(prefixes, TRUE); g_array_free(constraints, TRUE); g_array_free(results, TRUE); free(linebuf); return 0; }
int main(int argc, char * argv[]){ SystemTableInfo2 system_table_info; bool retval = system_table_info.load("../../data/table.conf"); if (!retval) { fprintf(stderr, "load table.conf failed.\n"); exit(ENOENT); } PhraseLargeTable3 largetable; FacadePhraseIndex phrase_index; const pinyin_table_info_t * phrase_files = system_table_info.get_default_tables(); TABLE_PHONETIC_TYPE type = system_table_info.get_table_phonetic_type(); if (!load_phrase_table(phrase_files, NULL, &largetable, &phrase_index, type)) exit(ENOENT); #if 0 MemoryChunk * chunk = new MemoryChunk; largetable.store(chunk); largetable.load(chunk); #endif char* linebuf = NULL; size_t size = 0; ssize_t read; while ((read = getline(&linebuf, &size, stdin)) != -1) { if ( '\n' == linebuf[strlen(linebuf) - 1] ) { linebuf[strlen(linebuf) - 1] = '\0'; } if ( strcmp ( linebuf, "quit" ) == 0) break; glong phrase_len = g_utf8_strlen(linebuf, -1); ucs4_t * new_phrase = g_utf8_to_ucs4(linebuf, -1, NULL, NULL, NULL); if (0 == phrase_len) continue; PhraseTokens tokens; memset(tokens, 0, sizeof(PhraseTokens)); phrase_index.prepare_tokens(tokens); guint32 start = record_time(); size_t i = 0; for (i = 0; i < bench_times; ++i){ phrase_index.clear_tokens(tokens); largetable.search(phrase_len, new_phrase, tokens); } print_time(start, bench_times); /* test search continued information. */ int retval = SEARCH_NONE; for (i = 1; i < phrase_len; ++i) { phrase_index.clear_tokens(tokens); retval = largetable.search(i, new_phrase, tokens); if (retval & SEARCH_CONTINUED) printf("return continued information with length:%ld\n", i); } phrase_index.clear_tokens(tokens); retval = largetable.search(phrase_len, new_phrase, tokens); if (retval & SEARCH_OK) { for (size_t i = 0; i < PHRASE_INDEX_LIBRARY_COUNT; ++i) { GArray * array = tokens[i]; if (NULL == array) continue; for (size_t k = 0; k < array->len; ++k) { phrase_token_t token = g_array_index (array, phrase_token_t, k); printf("token:%d\t", token); } } printf("\n"); } phrase_index.destroy_tokens(tokens); g_free(new_phrase); } if ( linebuf ) free(linebuf); /* mask out all index items. */ largetable.mask_out(0x0, 0x0); return 0; }
int main(int ac, char **av) { int i, j; int aflag = 0; int uflag = 0; int fpos; /* current position in time format buffer */ int chrcnt; /* # of chars formatted by current sprintf */ int bl, wtmp; char *ct; char *ut_host; char *ut_user; struct utmpx *bp; time_t otime; struct stat stb; int print = 0; char *crmsg = (char *)0; long outrec = 0; long maxrec = 0x7fffffffL; char *wtmpfile = "/var/adm/wtmpx"; size_t hostf_len; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't. */ #endif (void) textdomain(TEXT_DOMAIN); (void) time(&buf[0].ut_xtime); ac--, av++; argc = ac; argv = av; names = malloc(argc * sizeof (char *)); if (names == NULL) { perror("first"); exit(2); } names_num = 0; for (i = 0; i < argc; i++) { if (argv[i][0] == '-') { /* -[0-9]* sets max # records to print */ if (isdigit(argv[i][1])) { maxrec = atoi(argv[i]+1); continue; } for (j = 1; argv[i][j] != '\0'; ++j) { switch (argv[i][j]) { /* -f name sets filename of wtmp file */ case 'f': if (argv[i][j+1] != '\0') { wtmpfile = &argv[i][j+1]; } else if (i+1 < argc) { wtmpfile = argv[++i]; } else { (void) fprintf(stderr, gettext("first: argument to " "-f is missing\n")); (void) fprintf(stderr, gettext(USAGE)); exit(1); } goto next_word; /* -n number sets max # records to print */ case 'n': { char *arg; if (argv[i][j+1] != '\0') { arg = &argv[i][j+1]; } else if (i+1 < argc) { arg = argv[++i]; } else { (void) fprintf(stderr, gettext("first: argument to " "-n is missing\n")); (void) fprintf(stderr, gettext(USAGE)); exit(1); } if (!isdigit(*arg)) { (void) fprintf(stderr, gettext("first: argument to " "-n is not a number\n")); (void) fprintf(stderr, gettext(USAGE)); exit(1); } maxrec = atoi(arg); goto next_word; } /* -a displays hostname last on the line */ case 'a': aflag++; break; /* -u displays times in UNIX epoch format */ case 'u': uflag++; break; default: (void) fprintf(stderr, gettext(USAGE)); exit(1); } } next_word: continue; } if (strlen(argv[i]) > 2 || strcmp(argv[i], "~") == 0 || getpwnam(argv[i]) != NULL) { /* Not a tty number. */ names[names_num] = argv[i]; ++names_num; } else { /* tty number. Prepend "tty". */ names[names_num] = strspl("tty", argv[i]); ++names_num; } } wtmp = open(wtmpfile, O_RDONLY | O_LARGEFILE); if (wtmp < 0) { perror(wtmpfile); exit(1); } (void) fstat(wtmp, &stb); bl = (stb.st_size + sizeof (buf)-1) / sizeof (buf); if (signal(SIGINT, SIG_IGN) != SIG_IGN) { (void) signal(SIGINT, onintr); (void) signal(SIGQUIT, onintr); } lines = CHUNK_SIZE; ttnames = calloc(lines, sizeof (char *)); logouts = calloc(lines, sizeof (time_t)); if (ttnames == NULL || logouts == NULL) { (void) fprintf(stderr, gettext("Out of memory \n ")); exit(2); } for (bl--; bl >= 0; bl--) { (void) lseek(wtmp, (off_t)(bl * sizeof (buf)), 0); bp = &buf[read(wtmp, buf, sizeof (buf)) / sizeof (buf[0]) - 1]; for (; bp >= buf; bp--) { if (want(bp, &ut_host, &ut_user)) { for (i = 0; i <= lines; i++) { if (i == lines) reallocate_buffer(); if (ttnames[i] == NULL) { memory_alloc(i); /* * LMAX+HMAX+NMAX+3 bytes have been * allocated for ttnames[i]. * If bp->ut_line is longer than LMAX, * ut_host is longer than HMAX, * and ut_user is longer than NMAX, * truncate it to fit ttnames[i]. */ (void) strlcpy(ttnames[i], bp->ut_line, LMAX+1); (void) strlcpy(ttnames[i]+LMAX+1, ut_host, HMAX+1); (void) strlcpy(ttnames[i]+LMAX+HMAX+2, ut_user, NMAX+1); record_time(&otime, &print, i, bp); break; } else if (linehostnameq(ttnames[i], bp->ut_line, ut_host, ut_user)) { record_time(&otime, &print, i, bp); break; } } } if (print) { if (strncmp(bp->ut_line, "ftp", 3) == 0) bp->ut_line[3] = '\0'; if (strncmp(bp->ut_line, "uucp", 4) == 0) bp->ut_line[4] = '\0'; ct = ctime(&bp->ut_xtime); (void) printf(gettext("%-*.*s %-*.*s "), NMAX, NMAX, bp->ut_name, LMAX, LMAX, bp->ut_line); hostf_len = strlen(bp->ut_host); (void) snprintf(hostf, sizeof (hostf), "%-*.*s", hostf_len, hostf_len, bp->ut_host); if(uflag) { fpos = snprintf(timef, sizeof (timef), "%10lu ", bp->ut_xtime); } else { fpos = snprintf(timef, sizeof (timef), "%10.10s %13.13s ", /* MJC 8 extra chars */ ct, 11 + ct); } if (!lineq(bp->ut_line, "system boot") && !lineq(bp->ut_line, "system down")) { if (otime == 0 && bp->ut_type == USER_PROCESS) { if (fpos < sizeof (timef)) { /* timef still has room */ (void) snprintf(timef + fpos, sizeof (timef) - fpos, gettext(" still logged in")); } } else { time_t delta; if (otime < 0) { otime = -otime; /* * TRANSLATION_NOTE * See other notes on "down" * and "- %5.5s". * "-" means "until". This * is displayed after the * starting time as in: * 16:20 - down * You probably don't want to * translate this. Should you * decide to translate this, * translate "- %5.5s" too. */ if (fpos < sizeof (timef)) { /* timef still has room */ if(uflag) { chrcnt = snprintf(timef + fpos, sizeof (timef) - fpos, gettext("- %-10s"), crmsg); } else { chrcnt = snprintf(timef + fpos, sizeof (timef) - fpos, gettext("- %-24s"), crmsg); } fpos += chrcnt; } } else { if (fpos < sizeof (timef)) { /* timef still has room */ if(uflag) { chrcnt = snprintf(timef + fpos, sizeof (timef) - fpos, gettext("- %10lu"), otime); } else { chrcnt = snprintf(timef + fpos, sizeof (timef) - fpos, gettext("- %10.10s %13.13s"), ctime(&otime), ctime(&otime) + 11); /* MJC 19 extra chars */ } fpos += chrcnt; } } delta = otime - bp->ut_xtime; if (delta < SECDAY) { if (fpos < sizeof (timef)) { /* timef still has room */ (void) snprintf(timef + fpos, sizeof (timef) - fpos, gettext(" (%5.5s)"), asctime(gmtime(&delta)) + 11); } } else { if (fpos < sizeof (timef)) { /* timef still has room */ (void) snprintf(timef + fpos, sizeof (timef) - fpos, gettext(" (%ld+%5.5s)"), delta / SECDAY, asctime(gmtime(&delta)) + 11); } } } } if (aflag) (void) printf("%-62.62s %-.*s\n", /* MJC */ timef, strlen(hostf), hostf); else (void) printf("%-16.16s %-.62s\n", /* MJC */ hostf, timef); (void) fflush(stdout); if (++outrec >= maxrec) exit(0); } /* * when the system is down or crashed. */ if (bp->ut_type == BOOT_TIME) { for (i = 0; i < lines; i++) logouts[i] = -bp->ut_xtime; bootxtime = -bp->ut_xtime; /* * TRANSLATION_NOTE * Translation of this "down " will replace * the %s in "- %s". "down" is used instead * of the real time session was ended, probably * because the session ended by a sudden crash. */ crmsg = gettext("down "); } print = 0; /* reset the print flag */ } } if(uflag) { (void) printf(gettext("\nwtmp begins %lu \n"), buf[0].ut_xtime); } else { ct = ctime(&buf[0].ut_xtime); (void) printf(gettext("\nwtmp begins %24.24s \n"), ct); } /* free() called to prevent lint warning about names */ free(names); return (0); }
void main() { int i,j; UART1_Init(57600); Delay_ms(100); UART1_Write_Text("Start\n"); UART1_Write(13); UART1_Write(10); timer_setup(); UART1_Write_Text("timer started"); UART1_Write(13); UART1_Write(10); for( i = STOP; i > state_e; state_e++ ) // every state is being executed 1000 times except GRAPHICS, it is done 10 times { for( j = 0; j < 10000; j++ ) { switch( state_e ) { case DHRYSTONE: dhrystone_benchmark(); // after executing, record the time passed record_time(); reset_time(); break; case FFT: fft_benchmark(); record_time(); reset_time(); break; case WHETSTONE: whetstone_benchmark(); record_time(); reset_time(); timer_setup(); break; case GRAPHICS: { uint8_t temp; if ( j % 100 == 0) { for (temp = 0; temp <10; temp++) { graphics_benchmark(); record_time(); reset_time(); } } } break; } } } // print out the time passed UART1_Write_Text("Drhystone: "); IntToStr(dhrystone_time, txt); UART1_Write_Text(txt); UART1_Write(13); UART1_Write(10); UART1_Write_Text("FFT: "); IntToStr(fft_time, txt); UART1_Write_Text(txt); UART1_Write(13); UART1_Write(10); UART1_Write_Text("whetstone: "); IntToStr(whetstone_time, txt); UART1_Write_Text(txt); UART1_Write(13); UART1_Write(10); UART1_Write_Text("graphics: "); IntToStr(graphics_time, txt); UART1_Write_Text(txt); UART1_Write(13); UART1_Write(10); }
int main(int argc, char * argv[]) { pinyin_option_t options = USE_TONE | PINYIN_INCOMPLETE; ChewingLargeTable largetable(options); FacadePhraseIndex phrase_index; FILE * gbfile = fopen("../../data/gb_char.table", "r"); if (NULL == gbfile) { fprintf(stderr, "open gb_char.table failed!\n"); exit(ENOENT); } largetable.load_text(gbfile); fseek(gbfile, 0L, SEEK_SET); phrase_index.load_text(1, gbfile); fclose(gbfile); FILE * gbkfile = fopen("../../data/gbk_char.table", "r"); if (NULL == gbkfile) { fprintf(stderr, "open gbk_char.table failed!\n"); exit(ENOENT); } largetable.load_text(gbkfile); fseek(gbkfile, 0L, SEEK_SET); phrase_index.load_text(2, gbkfile); fclose(gbkfile); MemoryChunk * new_chunk = new MemoryChunk; largetable.store(new_chunk); largetable.load(new_chunk); char* linebuf = NULL; size_t size = 0; while( getline(&linebuf, &size, stdin) ){ linebuf[strlen(linebuf)-1] = '\0'; if ( strcmp ( linebuf, "quit" ) == 0) break; FullPinyinParser2 parser; ChewingKeyVector keys = g_array_new(FALSE, FALSE, sizeof(ChewingKey)); ChewingKeyRestVector key_rests = g_array_new(FALSE, FALSE, sizeof(ChewingKeyRest)); parser.parse(options, keys, key_rests, linebuf, strlen(linebuf)); if (0 == keys->len) { fprintf(stderr, "Invalid input.\n"); continue; } guint32 start = record_time(); PhraseIndexRanges ranges; memset(ranges, 0, sizeof(PhraseIndexRanges)); guint8 min_index, max_index; phrase_index.get_sub_phrase_range(min_index, max_index); for (size_t i = min_index; i < max_index; ++i) { ranges[i] = g_array_new(FALSE, FALSE, sizeof(PhraseIndexRange)); } for (size_t i = 0; i < bench_times; ++i) { largetable.search(keys->len, (ChewingKey *)keys->data, ranges); } for (size_t i = min_index; i < max_index; ++i) { g_array_set_size(ranges[i], 0); } print_time(start, bench_times); largetable.search(keys->len, (ChewingKey *)keys->data, ranges); for (size_t i = min_index; i < max_index; ++i) { GArray * & range = ranges[i]; if (range) { if (range->len) printf("range items number:%d\n", range->len); for (size_t k = 0; k < range->len; ++k) { PhraseIndexRange * onerange = &g_array_index(range, PhraseIndexRange, k); printf("start:%d\tend:%d\n", onerange->m_range_begin, onerange->m_range_end); PhraseItem item; for ( phrase_token_t token = onerange->m_range_begin; token != onerange->m_range_end; ++token){ phrase_index.get_phrase_item( token, item); /* get phrase string */ gunichar2 buffer[MAX_PHRASE_LENGTH + 1]; item.get_phrase_string(buffer); char * string = g_utf16_to_utf8 ( buffer, item.get_phrase_length(), NULL, NULL, NULL); printf("%s\t", string); g_free(string); ChewingKey chewing_buffer[MAX_PHRASE_LENGTH]; size_t npron = item.get_n_pronunciation(); guint32 freq; for (size_t m = 0; m < npron; ++m){ item.get_nth_pronunciation(m, chewing_buffer, freq); for (size_t n = 0; n < item.get_phrase_length(); ++n){ printf("%s'", chewing_buffer[n].get_pinyin_string()); } printf("\b\t%d\t", freq); } } printf("\n"); } } g_array_set_size(range, 0); } g_array_free(keys, TRUE); g_array_free(key_rests, TRUE); } if (linebuf) free(linebuf); return 0; }
/*********************************************************** 电池充电 **************************************************************/ int charge(void) { FRESULT result; FATFS fs; FIL file; DIR DirInf; uint32_t bw; char time_buf[TIME_MAX]; char write_buf[WR_MAX]; char tmp_buf[8]; int i = 0; int min_count = 0; int adc_value = 0; int adc_tmp = 0; int flag = 0; int times = 0; double charge_time = 0; double vol; /* 挂载文件系统,打开文件,定位文件指针 */ result = f_mount(0, &fs); if (result != FR_OK){ printf("FileSystem Mounted Failed (%d)\r\n", result); goto ERROR; } result = f_opendir(&DirInf, "/"); if (result != FR_OK){ printf("Open Root Directory Error (%d)\r\n", result); goto ERROR; } result = f_open(&file, conf->file_name, FA_OPEN_ALWAYS | FA_READ | FA_WRITE); if(result !=FR_OK){ printf("open error, errornu:%d\n\r",result); goto ERROR; } if(f_lseek(&file,file.fsize) != FR_OK){ printf("f_lseek error, errornu:%d\n\r",result); goto ERROR; } beeper_on(); /* 蜂鸣器提示 */ delay_ms(200); beeper_off(); load_con_off(); /*负载通道关闭 */ charge_con_on(); /*打开CHAR_CON充电通道 */ bsp_LedOn(2); memset(time_buf,0,TIME_MAX); /*清空数组,防止乱码*/ memset(write_buf,0,WR_MAX); StartTimer(0, 100); adc_value = GetADC(); do{ if(jump) goto JMP; if(CheckTimer(0)) { vol = ADC_SAMPLING(); charge_time ++; min_count ++; StartTimer(0, 1000); adc_tmp = GetADC(); if((abs(adc_value - adc_tmp) > 3) || (times != 0)){ if(abs(adc_value - adc_tmp) <= 3){ times = 0; } else{ times++; if(times >= 10){ times = 0; flag = 0; adc_value = adc_tmp; } } } else if((abs(adc_value - adc_tmp) <= 3) && (times == 0)){ flag ++; } if(min_count >= 60){ /* 每隔一分钟采样一次 */ min_count = 0; record_time(time_buf); strcat(time_buf,","); strcat(write_buf, time_buf); memset(time_buf,0,TIME_MAX); sprintf(tmp_buf, "%.2f", vol); strcat(write_buf, tmp_buf); strcat(write_buf,",充电\n"); if(i > 9){ /* 10次采样将数据记录到flash中 */ result = f_write(&file,write_buf,sizeof(write_buf),&bw); if(result != FR_OK){ printf("file write faild, errornu:%d\n\r",result); goto ERROR; } memset(write_buf,0,WR_MAX); i = 0; } i++; } } }while(charge_timeout(charge_time/3600, vol, flag)); /* 充电时间 */ JMP: jump = 0; if(i != 0){ /* 最后将不足10次的数据记录到flash中 */ result = f_write(&file,write_buf,(15 + TIME_MAX)*i, &bw); if(result != FR_OK){ printf("file write faild, errornu:%d\n\r",result); goto ERROR; } i = 0; } memset(write_buf,0,WR_MAX); charge_con_off(); /* 关闭CHAR_CON充电通道 */ bsp_LedOff(2); /* 关闭文件,卸载文件系统 */ f_close(&file); f_mount(0, NULL); return 0; ERROR: /* 错误处理 */ bsp_LedOff(2); f_close(&file); f_mount(0, NULL); return 1; }
int main( int argc, char * argv[]){ PinyinCustomSettings custom; PinyinLargeTable largetable(&custom); FacadePhraseIndex phrase_index; FILE * gbfile = fopen("../../data/gb_char.table", "r"); if ( gbfile == NULL ) { fprintf(stderr, "open gb_char.table failed!\n"); exit(ENOENT); } largetable.load_text(gbfile); fseek(gbfile, 0L, SEEK_SET); phrase_index.load_text(1, gbfile); fclose(gbfile); FILE * gbkfile = fopen("../../data/gbk_char.table","r"); if ( gbkfile == NULL ) { fprintf(stderr, "open gb_char.table failed!\n"); exit(ENOENT); } largetable.load_text(gbkfile); fseek(gbkfile, 0L, SEEK_SET); phrase_index.load_text(2, gbkfile); fclose(gbkfile); MemoryChunk* new_chunk = new MemoryChunk; largetable.store(new_chunk); largetable.load(new_chunk); char* linebuf = NULL; size_t size = 0; while( getline(&linebuf, &size, stdin) ){ linebuf[strlen(linebuf)-1] = '\0'; if ( strcmp ( linebuf, "quit" ) == 0) break; PinyinDefaultParser parser; NullPinyinValidator validator; PinyinKeyVector keys; PinyinKeyPosVector poses; keys = g_array_new(FALSE, FALSE, sizeof( PinyinKey)); poses = g_array_new(FALSE, FALSE, sizeof( PinyinKeyPos)); parser.parse(validator, keys, poses, linebuf); guint32 start = record_time(); PhraseIndexRanges ranges; for( size_t i = 0 ; i < PHRASE_INDEX_LIBRARY_COUNT ; ++i){ ranges[i] = g_array_new(FALSE, FALSE, sizeof (PhraseIndexRange)); } for ( size_t i = 0 ; i < bench_times; ++i){ largetable.search(keys->len, (PinyinKey *)keys->data, ranges); } for( size_t i = 0 ; i < PHRASE_INDEX_LIBRARY_COUNT ; ++i){ GArray * range = ranges[i]; g_array_set_size( range, 0); } print_time(start, bench_times); largetable.search(keys->len, (PinyinKey *)keys->data, ranges); for( size_t i = 0 ; i < PHRASE_INDEX_LIBRARY_COUNT ; ++i){ GArray * range = ranges[i]; if ( range ){ for (size_t k = 0; k < range->len; ++k){ PhraseIndexRange* onerange = &g_array_index(range, PhraseIndexRange, k); printf("start:%d\tend:%d\n", onerange->m_range_begin, onerange->m_range_end); PhraseItem item; for ( phrase_token_t token = onerange->m_range_begin; token != onerange->m_range_end; ++token){ phrase_index.get_phrase_item( token, item); gunichar2 bufstr[1024]; item.get_phrase_string(bufstr); char * string = g_utf16_to_utf8 ( bufstr, item.get_phrase_length(), NULL, NULL, NULL); printf("%s\t", string); g_free(string); PinyinKey pinyin_buffer[1024]; size_t npron = item.get_n_pronunciation(); guint32 freq; for ( size_t n = 0; n < npron; ++n){ item.get_nth_pronunciation(n, pinyin_buffer, freq); for ( size_t o = 0; o < item.get_phrase_length(); ++o){ printf("%s'", pinyin_buffer[o].get_key_string()); } printf("\b\t%d\t", freq); } printf("\n"); } } if ( range->len) printf("range items number:%d\n", range->len); } g_array_set_size( range, 0); } g_array_free(keys, TRUE); g_array_free(poses, TRUE); } if (linebuf) free(linebuf); return 0; }
/*********************************************** 电池放电 ***********************************************/ int dis_charge(void) { FRESULT result; FATFS fs; FIL file; DIR DirInf; uint32_t bw; char time_buf[TIME_MAX]; char write_buf[WR_MAX]; char tmp_buf[8]; int dis_time = 0; int i = 0; int min_count = 0; double vol; result = f_mount(0, &fs); if (result != FR_OK){ printf("FileSystem Mounted Failed (%d)\r\n", result); goto ERROR; } result = f_opendir(&DirInf, "/"); if (result != FR_OK){ printf("Open Root Directory Error (%d)\r\n", result); goto ERROR; } result = f_open(&file, conf->file_name, FA_OPEN_ALWAYS | FA_READ | FA_WRITE); if(result !=FR_OK){ printf("open error, errornu:%d\n\r",result); goto ERROR; } if(f_lseek(&file,file.fsize) != FR_OK){ printf("f_lseek error, errornu:%d\n\r",result); goto ERROR; } load_con_on(); //打开负载通道LOAD_CON bsp_LedOn(3); beeper_on(); delay_ms(200); beeper_off(); memset(time_buf,0,TIME_MAX); memset(write_buf,0,WR_MAX); StartTimer(0, 1000); // Time_Display(RTC_GetCounter()); // vol = ADC_SAMPLING(); do{ if(jump) goto JMP; if(CheckTimer(0)) { dis_time ++; StartTimer(0, 1000); min_count ++; vol = ADC_SAMPLING(); if(min_count >=60){ min_count = 0; memset(time_buf,0,TIME_MAX); record_time(time_buf); strcat(time_buf,","); strcat(write_buf, time_buf); memset(time_buf,0,TIME_MAX); sprintf(tmp_buf, "%.2f", vol); strcat(write_buf, tmp_buf); strcat(write_buf,",放电\n"); if(i > 9){ result = f_write(&file,write_buf,sizeof(write_buf),&bw); if(result != FR_OK){ printf("file write faild, errornu:%d\n\r",result); goto ERROR; } memset(write_buf,0,WR_MAX); i = 0; } i++; } } }while(dis_charge_timeout(vol)); JMP: record[rec]= dis_time/60; rec++; jump = 0; if(i != 0){ result = f_write(&file,write_buf,35*i, &bw); if(result != FR_OK){ printf("file write faild, errornu:%d\n\r",result); goto ERROR; } i = 0; } memset(write_buf,0,WR_MAX); bsp_LedOff(3); //放电结束 load_con_off(); f_close(&file); f_mount(0, NULL); return 0; //关闭负载通道LOAD_CON ERROR: bsp_LedOff(3); f_close(&file); f_mount(0, NULL); return 1; }
int main(int argc, char * argv[]) { SystemTableInfo system_table_info; bool retval = system_table_info.load("../../data/table.conf"); if (!retval) { fprintf(stderr, "load table.conf failed.\n"); exit(ENOENT); } pinyin_option_t options = USE_TONE | PINYIN_INCOMPLETE; ChewingLargeTable largetable(options); FacadePhraseIndex phrase_index; const pinyin_table_info_t * phrase_files = system_table_info.get_table_info(); if (!load_phrase_table(phrase_files, &largetable, NULL, &phrase_index)) exit(ENOENT); MemoryChunk * new_chunk = new MemoryChunk; largetable.store(new_chunk); largetable.load(new_chunk); char* linebuf = NULL; size_t size = 0; ssize_t read; while ((read = getline(&linebuf, &size, stdin)) != -1) { if ( '\n' == linebuf[strlen(linebuf) - 1] ) { linebuf[strlen(linebuf) - 1] = '\0'; } if ( strcmp ( linebuf, "quit" ) == 0) break; FullPinyinParser2 parser; ChewingKeyVector keys = g_array_new(FALSE, FALSE, sizeof(ChewingKey)); ChewingKeyRestVector key_rests = g_array_new(FALSE, FALSE, sizeof(ChewingKeyRest)); parser.parse(options, keys, key_rests, linebuf, strlen(linebuf)); if (0 == keys->len) { fprintf(stderr, "Invalid input.\n"); continue; } guint32 start = record_time(); PhraseIndexRanges ranges; memset(ranges, 0, sizeof(PhraseIndexRanges)); phrase_index.prepare_ranges(ranges); for (size_t i = 0; i < bench_times; ++i) { phrase_index.clear_ranges(ranges); largetable.search(keys->len, (ChewingKey *)keys->data, ranges); } print_time(start, bench_times); phrase_index.clear_ranges(ranges); largetable.search(keys->len, (ChewingKey *)keys->data, ranges); for (size_t i = 0; i < PHRASE_INDEX_LIBRARY_COUNT; ++i) { GArray * & range = ranges[i]; if (!range) continue; if (range->len) printf("range items number:%d\n", range->len); for (size_t k = 0; k < range->len; ++k) { PhraseIndexRange * onerange = &g_array_index(range, PhraseIndexRange, k); printf("start:%d\tend:%d\n", onerange->m_range_begin, onerange->m_range_end); PhraseItem item; for ( phrase_token_t token = onerange->m_range_begin; token != onerange->m_range_end; ++token){ phrase_index.get_phrase_item( token, item); /* get phrase string */ ucs4_t buffer[MAX_PHRASE_LENGTH + 1]; item.get_phrase_string(buffer); char * string = g_ucs4_to_utf8 ( buffer, item.get_phrase_length(), NULL, NULL, NULL); printf("%s\t", string); g_free(string); ChewingKey chewing_buffer[MAX_PHRASE_LENGTH]; size_t npron = item.get_n_pronunciation(); guint32 freq; for (size_t m = 0; m < npron; ++m){ item.get_nth_pronunciation(m, chewing_buffer, freq); for (size_t n = 0; n < item.get_phrase_length(); ++n){ gchar * pinyins = chewing_buffer[n].get_pinyin_string(); printf("%s'", pinyins); g_free(pinyins); } printf("\b\t%d\t", freq); } } printf("\n"); } g_array_set_size(range, 0); } phrase_index.destroy_ranges(ranges); g_array_free(keys, TRUE); g_array_free(key_rests, TRUE); } if (linebuf) free(linebuf); /* mask out all index items. */ largetable.mask_out(0x0, 0x0); return 0; }
/* 充放电结束后放置一小时 */ int delay_hour(void) { FRESULT result; FATFS fs; FIL file; DIR DirInf; uint32_t bw; char time_buf[TIME_MAX]; char write_buf[WR_MAX]; char tmp_buf[8]; int sec = 0; int i = 0; int min_count = 0; double vol; result = f_mount(0, &fs); if (result != FR_OK){ printf("FileSystem Mounted Failed (%d)\r\n", result); goto ERROR; } result = f_opendir(&DirInf, "/"); if (result != FR_OK){ printf("Open Root Directory Error (%d)\r\n", result); goto ERROR; } result = f_open(&file, conf->file_name, FA_OPEN_ALWAYS | FA_READ | FA_WRITE); if(result !=FR_OK){ printf("open error, errornu:%d\n\r",result); goto ERROR; } if(f_lseek(&file,file.fsize) != FR_OK){ printf("f_lseek error, errornu:%d\n\r",result); goto ERROR; } beeper_on(); delay_ms(200); beeper_off(); memset(time_buf,0,TIME_MAX); memset(write_buf,0,WR_MAX); printf("\n\r静置开始"); Time_Display(RTC_GetCounter()); printf("\n\r"); bsp_LedOn(4); StartTimer(0, 1000); // Time_Display(RTC_GetCounter()); do{ if(jump) goto JMP; if(CheckTimer(0) ) { StartTimer(0, 1000); sec++; min_count ++; vol = ADC_SAMPLING(); if(min_count >= 60){ min_count = 0; record_time(time_buf); strcat(time_buf,","); strcat(write_buf, time_buf); memset(time_buf,0,TIME_MAX); sprintf(tmp_buf, "%.2f", vol); strcat(write_buf, tmp_buf); strcat(write_buf,",静置\n"); if(i >= 9){ result = f_write(&file,write_buf,sizeof(write_buf),&bw); if(result != FR_OK){ printf("file write faild, errornu:%d\n\r",result); goto ERROR; } memset(write_buf,0,WR_MAX); i = 0; } i++; } } }while(sec < 3600); /* 静置时间(单位:秒) */ JMP: jump = 0; if(i != 0){ result = f_write(&file,write_buf,(15 + TIME_MAX)*i, &bw); if(result != FR_OK){ printf("file write faild, errornu:%d\n\r",result); goto ERROR; } i = 0; } memset(write_buf,0,WR_MAX); printf("静置结束"); Time_Display(RTC_GetCounter()); printf("\n\r"); bsp_LedOff(4); f_close(&file); f_mount(0, NULL); return 0; ERROR: bsp_LedOff(4); f_close(&file); f_mount(0, NULL); return 1; }
void *start_task(void *data) { long id = (long)data; unsigned long long start_time; struct sched_param param = { .sched_priority = id + prio_start, }; int ret; int high = 0; cpu_set_t cpumask; cpu_set_t save_cpumask; int cpu = 0; unsigned long l; long pid; ret = sched_getaffinity(0, sizeof(save_cpumask), &save_cpumask); if (ret < 0) perr("getting affinity"); pid = gettid(); /* Check if we are the highest prio task */ if (id == nr_tasks-1) high = 1; ret = sched_setscheduler(0, SCHED_FIFO, ¶m); if (ret < 0 && !id) fprintf(stderr, "Warning, can't set priorities\n"); while (!done) { if (high) { /* rotate around the CPUS */ if (!CPU_ISSET(cpu, &save_cpumask)) cpu = 0; CPU_ZERO(&cpumask); CPU_SET(cpu, &cpumask); cpu++; sched_setaffinity(0, sizeof(cpumask), &cpumask); } pthread_barrier_wait(&start_barrier); start_time = get_time(); lgprint(lfd, "Thread %d: started %lld diff %lld\n", pid, start_time, start_time - now); l = busy_loop(start_time); record_time(id, start_time, l); pthread_barrier_wait(&end_barrier); } return (void*)pid; } static int check_times(int l) { int i; unsigned long long last; unsigned long long last_loops; unsigned long long last_length; for (i=0; i < nr_tasks; i++) { if (i && last < intervals[l][i] && ((intervals[l][i] - last) > max_err)) { /* * May be a false positive. * Make sure that we did more loops * our start is before the end * and the end should be tested. */ if (intervals_loops[l][i] < last_loops || intervals[l][i] > last_length || (intervals_length[l][i] > last_length && intervals_length[l][i] - last_length > max_err)) { check = -1; return 1; } } last = intervals[l][i]; last_loops = intervals_loops[l][i]; last_length = intervals_length[l][i]; } return 0; }
int main(int argc, char * argv[]){ PhraseLargeTable2 largetable; FacadePhraseIndex phrase_index; if (!load_phrase_table(NULL, &largetable, &phrase_index)) exit(ENOENT); MemoryChunk * chunk = new MemoryChunk; largetable.store(chunk); largetable.load(chunk); char* linebuf = NULL; size_t size = 0; ssize_t read; while ((read = getline(&linebuf, &size, stdin)) != -1) { if ( '\n' == linebuf[strlen(linebuf) - 1] ) { linebuf[strlen(linebuf) - 1] = '\0'; } if ( strcmp ( linebuf, "quit" ) == 0) break; glong phrase_len = g_utf8_strlen(linebuf, -1); ucs4_t * new_phrase = g_utf8_to_ucs4(linebuf, -1, NULL, NULL, NULL); if (0 == phrase_len) continue; PhraseTokens tokens; memset(tokens, 0, sizeof(PhraseTokens)); phrase_index.prepare_tokens(tokens); guint32 start = record_time(); for (size_t i = 0; i < bench_times; ++i){ phrase_index.clear_tokens(tokens); largetable.search(phrase_len, new_phrase, tokens); } print_time(start, bench_times); phrase_index.clear_tokens(tokens); int retval = largetable.search(phrase_len, new_phrase, tokens); if (retval & SEARCH_OK) { for (size_t i = 0; i < PHRASE_INDEX_LIBRARY_COUNT; ++i) { GArray * array = tokens[i]; if (NULL == array) continue; for (size_t k = 0; k < array->len; ++k) { phrase_token_t token = g_array_index (array, phrase_token_t, k); printf("token:%d\t", token); } } printf("\n"); } phrase_index.destroy_tokens(tokens); g_free(new_phrase); } if ( linebuf ) free(linebuf); return 0; }