std::pair<bool, std::string> get_node_value(zhandle_t* handle, const std::string& node, const std::string& stat_message) { char buffer[1024]; int length = 1024; int stat = zoo_get(handle, node.c_str(), 0, buffer, &length, NULL); if (stat != ZOK) print_stat(stat, stat_message + " get_node_value", node); if (stat != ZOK) return std::pair<bool, std::string>(false, ""); // we are good here if (length <= 1024) { // ok. it fit inside the buffer // we can return if (length < 0) return std::pair<bool, std::string>(true, ""); else return std::pair<bool, std::string>(true, std::string(buffer, length)); } else { while(1) { // buffer not long enough. The length parameter constains the actual length // try again. keep looping until we succeed char* newbuffer = new char[length]; int stat = zoo_get(handle, node.c_str(), 0, newbuffer, &length, NULL); if (stat != ZOK) print_stat(stat, stat_message + " get_node_value", node); std::string retval(newbuffer, length); delete newbuffer; if (stat != ZOK) print_stat(stat, stat_message + " get_node_value", node); if (stat != ZOK) return std::pair<bool, std::string>(false, ""); if (length < 0) return std::pair<bool, std::string>(true, ""); else return std::pair<bool, std::string>(true, retval); } } }
void oneway_nb_test(int iters, int nbytes, int alignment) {GASNET_BEGIN_FUNCTION(); int i; int64_t begin, end; stat_struct_t st; gasnet_handle_t *handles; int pad = (alignment % PAGESZ); /* initialize statistics */ init_stat(&st, nbytes, alignment); handles = (gasnet_handle_t*) test_malloc(sizeof(gasnet_handle_t) * iters); memset(locbuf+pad, 1, nbytes); BARRIER(); if (iamsender) { /* measure the throughput of sending a message */ begin = TIME(); for (i = 0; i < iters; i++) { handles[i] = gasnet_put_nb_bulk(peerproc, rembuf, locbuf+pad, nbytes); } gasnet_wait_syncnb_all(handles, iters); end = TIME(); update_stat(&st, (end - begin), iters); } BARRIER(); if (iamsender) { print_stat(myproc, &st, "put_nb_bulk throughput", PRINT_THROUGHPUT); } /* initialize statistics */ init_stat(&st, nbytes, alignment); if (iamsender) { /* measure the throughput of receiving a message */ begin = TIME(); for (i = 0; i < iters; i++) { handles[i] = gasnet_get_nb_bulk(locbuf, peerproc, rembuf+pad, nbytes); } gasnet_wait_syncnb_all(handles, iters); end = TIME(); update_stat(&st, (end - begin), iters); } BARRIER(); if (iamsender) { print_stat(myproc, &st, "get_nb_bulk throughput", PRINT_THROUGHPUT); } test_free(handles); }
int main() { int p[2]; print_stat("/dev/console",0); print_stat("/dev/tty",0); print_stat("/dev/null",0); pipe(p); print_stat("pipe 0",p[0]); print_stat("pipe 1",p[1]); return 0; }
/* Print stats as specified on the provided command line. */ void print_stats(int argc, char **argv) { int i; if (argc == optind) { /* Print all stats. */ for (i = 0; i < num_stats; i++) print_stat(&stats[i]); } else { /* Print selected stats. */ for (i = optind; i < argc; i++) { char *name = argv[i]; stat key; const stat *s, *end; int (*compare)(const void *, const void *); key.name = name; if (name[strlen(name) - 1] == '.') compare = stats_compare_prefix; else compare = stats_compare; if (stats == NULL) { s = NULL; } else { s = (const stat *)bsearch(&key, stats, num_stats, sizeof *stats, compare); } if (s == NULL) { printf("Unknown stat %s\n", name); continue; } /* Find the range of stats the user wanted. */ for (; s >= stats; s--) { if (compare(&key, s) != 0) break; } s++; for (end = s; end < &stats[num_stats]; end++) { if (compare(&key, end) != 0) break; } /* And print them. */ for (; s < end; s++) { print_stat(s); } } } }
void oneway_nbi_test(int iters, int nbytes, int alignment) {GASNET_BEGIN_FUNCTION(); int i; int64_t begin, end; stat_struct_t st; int pad = (alignment % PAGESZ); /* initialize statistics */ init_stat(&st, nbytes, alignment); memset(locbuf+pad, 1, nbytes); BARRIER(); if (iamsender) { /* measure the throughput of nonblocking implicit bulk put */ begin = TIME(); for (i = 0; i < iters; i++) { gasnet_put_nbi_bulk(peerproc, rembuf, locbuf+pad, nbytes); } gasnet_wait_syncnbi_puts(); end = TIME(); update_stat(&st, (end - begin), iters); } BARRIER(); if (iamsender) { print_stat(myproc, &st, "put_nbi_bulk throughput", PRINT_THROUGHPUT); } /* initialize statistics */ init_stat(&st, nbytes, alignment); if (iamsender) { /* measure the throughput of nonblocking implicit bulk get */ begin = TIME(); for (i = 0; i < iters; i++) { gasnet_get_nbi_bulk(locbuf, peerproc, rembuf+pad, nbytes); } gasnet_wait_syncnbi_gets(); end = TIME(); update_stat(&st, (end - begin), iters); } BARRIER(); if (iamsender) { print_stat(myproc, &st, "get_nbi_bulk throughput", PRINT_THROUGHPUT); } }
static void print_args(t_info *info, t_dlst *headdir) { t_node *tmp; t_dlst *it; it = info->headfile.next; if (GET(info->opt, OPT_L) || GET(info->opt, OPT_1)) { while (it != &info->headfile) { tmp = C_NODE(t_node, it); if (!GET(info->opt, OPT_A) && tmp->namtyp.d_name[0] == '.') { it = it->next; continue ; } if (GET(info->opt, OPT_L)) print_stat(tmp, info); else print_filename(tmp, info); it = it->next; } } else test_col_file(info); if (!dlst_empty(headdir)) ft_putchar('\n'); }
void print_files(t_info *info) { t_node *tmp; t_dlst *it; it = info->headfile.next; if (GET(info->opt, OPT_L) && !dlst_empty(&info->headfile)) ft_printf("total %d\n", info->total); if (GET(info->opt, OPT_L) || GET(info->opt, OPT_1)) { while (it != &info->headfile) { tmp = C_NODE(t_node, it); if (!GET(info->opt, OPT_A) && tmp->namtyp.d_name[0] == '.') { it = it->next; continue ; } if (GET(info->opt, OPT_L)) print_stat(tmp, info); else print_filename(tmp, info); it = it->next; } } else test_col_file(info); }
int main(void) { read_data(); printf("\n"); printf("== 学生数 ==\n"); printf("%d 人\n", max_student); if (max_student <= 0){ printf("データ数が少なすぎます。\n"); return (-1); } printf("\n"); printf("== 出席番号順の名簿 ==\n"); sort_by_id(); print_data(); printf("\n"); printf("== 合計点による成績順位表 ==\n"); sort_by_total(); print_data(); printf("\n"); printf("== 平均点・最高点・最底辺 ==\n"); print_stat(); return (0); }
void merge_stat(const hash_t *day, int type) { hash_t stat; hash_create(&stat, 0, top_hash); load_stat(&stat, type); hash_iter_t *iter; top_t *entry; const top_t *top; for (iter = hash_begin(day); iter; iter = hash_next(iter)) { top = (const top_t *)(iter->entry->key); entry = hash_get(&stat, top, HASH_KEY_STRING); if (entry) { entry->count += top->count; entry->last = top->last; } else { if (top->count) hash_set(&stat, (char *)top, HASH_KEY_STRING, top); } } top_t **tops = sort_stat(&stat); if (tops) { print_stat(&stat, tops, type); save_stat(&stat, tops, type); } }
void bulk_test(int iters) {GASNET_BEGIN_FUNCTION(); int i; int64_t begin, end; stat_struct_t stput; int payload; for (payload = min_payload; payload <= max_payload && payload > 0; payload *= 2) { init_stat(&stput, payload); BARRIER(); if (iamsender) { /* measure the throughput of sending a message */ begin = TIME(); for (i = 0; i < iters; i++) { gasnet_memset(peerproc, tgtmem, 0xaa, payload); } end = TIME(); update_stat(&stput, (end - begin), iters); } BARRIER(); if (iamsender) { print_stat(myproc, &stput, "memset throughput", PRINT_THROUGHPUT); } } }
void bulk_test_nb(int iters) {GASNET_BEGIN_FUNCTION(); int i; int64_t begin, end; stat_struct_t stput; gasnet_handle_t *handles; int payload; handles = (gasnet_handle_t *) test_malloc(sizeof(gasnet_handle_t) * iters); for (payload = min_payload; payload <= max_payload && payload > 0; payload *= 2) { init_stat(&stput, payload); BARRIER(); if (iamsender) { /* measure the throughput of sending a message */ begin = TIME(); for (i = 0; i < iters; i++) { handles[i] = gasnet_memset_nb(peerproc, tgtmem, 0x5a, payload); } gasnet_wait_syncnb_all(handles, iters); end = TIME(); update_stat(&stput, (end - begin), iters); } BARRIER(); if (iamsender) { print_stat(myproc, &stput, "memset_nb throughput", PRINT_THROUGHPUT); } } test_free(handles); }
GTA * st_gta_copy(GTA *g) { Timer temp; if (options.time) { timer_copy.start(); if (options.statistics) temp.start(); } if (options.statistics) { cout << "Copying "; print_stat(g); cout << "\n"; } GTA *result = gtaCopy(g); num_copies++; if (options.time) { timer_copy.stop(); if (options.statistics) { temp.stop(); cout << " Time: "; temp.print(); } } update_largest(result); return result; }
static void try_df (const char *name, const char *uuid, const char *dev, int offset) { struct guestfs_statvfs *stat = NULL; guestfs_error_handler_cb old_error_cb; void *old_error_data; if (verbose) fprintf (stderr, "try_df %s %s %d\n", name, dev, offset); /* Try mounting and stating the device. This might reasonably fail, * so don't show errors. */ old_error_cb = guestfs_get_error_handler (g, &old_error_data); guestfs_set_error_handler (g, NULL, NULL); if (guestfs_mount_ro (g, dev, "/") == 0) { stat = guestfs_statvfs (g, "/"); guestfs_umount_all (g); } guestfs_set_error_handler (g, old_error_cb, old_error_data); if (stat) { print_stat (name, uuid, dev, offset, stat); guestfs_free_statvfs (stat); } }
static int queue_poll_stat_show(void *data, struct seq_file *m) { struct request_queue *q = data; int bucket; for (bucket = 0; bucket < BLK_MQ_POLL_STATS_BKTS/2; bucket++) { seq_printf(m, "read (%d Bytes): ", 1 << (9+bucket)); print_stat(m, &q->poll_stat[2*bucket]); seq_puts(m, "\n"); seq_printf(m, "write (%d Bytes): ", 1 << (9+bucket)); print_stat(m, &q->poll_stat[2*bucket+1]); seq_puts(m, "\n"); } return 0; }
int main (int argc, char ** argv) { DIR * dir; struct dirent * entry; if (argc < 2) { fprintf (stderr, "Too few arguments\n"); return 1; } dir = opendir (argv[1]); if (dir == NULL) { fprintf (stderr, "opendir() error\n"); return 1; } while ((entry = readdir (dir)) != NULL) { printf ("%s\t\t", entry->d_name); if (chdir (argv[1]) == -1) { fprintf (stderr, "chdir() error\n"); return 1; } print_stat (entry->d_name); } closedir (dir); return 0; }
static void testfd(const char *name, int fd) { struct stat __stat, *stat = &__stat; int ret = fstat(fd, stat); assert(ret == 0); print_stat(name, fd, stat); }
void statement(LIST *S, int level) { LIST *list; ATTR *E = (ATTR*)malloc(sizeof(ATTR)); debug(level,"STATEMENT"); if(token == ID) { assignment_stat(S, level+1); } else if(token == TK_IF) { if_stat(S, level+1); backpatch(S, int2string(nextquad())); } else if(token == TK_DO) { while_stat(S, level+1); S->next = NULL; } else if(token == TK_EXIT) { exit_stat(level+1); list = makelist(int2string(nextquad())); list->exitflag = 1; genquad("jump", "_", "_", "_"); S->next = merge(S->next, list); } else if(token == TK_RETURN) { return_stat(E, level+1); S->next = NULL; } else if(token == TK_PRINT) { print_stat(level+1); S->next = NULL; } else if(token == TK_CALL) { call_stat(level+1); S->next = NULL; } else { S->next = NULL; } }
/* Stop playback while seeking if buffer is involved. */ static void seekmode(mpg123_handle *mh, out123_handle *ao) { if(param.usebuffer && !stopped) { int channels = 0; int encoding = 0; int pcmframe; off_t back_samples = 0; stopped = TRUE; out123_pause(ao); mpg123_getformat(mh, NULL, &channels, &encoding); pcmframe = out123_encsize(encoding)*channels; if(pcmframe > 0) back_samples = out123_buffered(ao)/pcmframe; fprintf(stderr, "\nseeking back %"OFF_P" samples from %"OFF_P"\n" , (off_p)back_samples, (off_p)mpg123_tell(mh)); mpg123_seek(mh, -back_samples, SEEK_CUR); out123_drop(ao); fprintf(stderr, "\ndropped, now at %"OFF_P"\n" , (off_p)mpg123_tell(mh)); fprintf(stderr, "%s", MPG123_STOPPED_STRING); if(param.verbose) print_stat(mh, 0, ao); } }
off_t term_control(mpg123_handle *fr, out123_handle *ao) { offset = 0; debug2("control for frame: %li, enable: %i", (long)mpg123_tellframe(fr), term_enable); if(!term_enable) return 0; if(paused) { /* pause_cycle counts the remaining frames _after_ this one, thus <0, not ==0 . */ if(--pause_cycle < 0) pause_recycle(fr); } do { off_t old_offset = offset; term_handle_input(fr, ao, stopped|seeking); if((offset < 0) && (-offset > framenum)) offset = - framenum; if(param.verbose && offset != old_offset) print_stat(fr,offset,ao); } while (!intflag && stopped); /* Make the seeking experience with buffer less annoying. No sound during seek, but at least it is possible to go backwards. */ if(offset) { if((offset = mpg123_seek_frame(fr, offset, SEEK_CUR)) >= 0) debug1("seeked to %li", (long)offset); else error1("seek failed: %s!", mpg123_strerror(fr)); /* Buffer resync already happened on un-stop? */ /* if(param.usebuffer) audio_drop(ao);*/ } return 0; }
/*gen_box() generates a box around a configuration*/ void gen_box(int NTB, int natoms, rvec *x, matrix box, rvec box_space, gmx_bool bCenter) { int i, m; rvec xmin, xmax; real max_box; /*calculate minimum and maximum x[0..DIM-1]*/ for (m = 0; (m < DIM); m++) { xmin[m] = xmax[m] = x[0][m]; } for (i = 1; (i < natoms); i++) { for (m = 0; m < DIM; m++) { xmin[m] = min(xmin[m], x[i][m]); xmax[m] = max(xmax[m], x[i][m]); } } /*calculate the new box sizes for cubic and octahedral ...*/ for (m = 0; (m < DIM); m++) { box[m][m] = xmax[m]-xmin[m]+2*box_space[m]; } /*calculate the box size if NTB=1 (truncated octahedron)*/ if (NTB == 1) { max_box = box[0][0]; for (m = 0; (m < DIM); m++) { max_box = max(max_box, box[m][m]); } for (m = 0; (m < DIM); m++) { box[m][m] = max_box; } } /*move the molecule to the center of the box*/ if (bCenter) { for (i = 0; (i < natoms); i++) { for (m = 0; (m < DIM); m++) { x[i][m] += 0.5*(box[m][m]-xmin[m]-xmax[m]); } } } #ifdef DEBUG /* print data to check this */ print_stat(x, natoms, box); #endif } /*gen_box()*/
int delete_node(zhandle_t* handle, const std::string& path, const std::string& stat_message) { int stat = zoo_delete(handle, path.c_str(), -1); // if (stat == ZOK) return stat; if (stat != ZOK) print_stat(stat, stat_message + " delete_node", path); return stat; }
int main() { //framework_main(kBenchmarkSmall); framework_main(kBenchmarkLarge); print_stat(); return 0; }
GTA * st_gta_project(GTA *g, Ident i, Pos &p, bool quotient) { Timer temp; if (options.time) { timer_project.start(); if (options.statistics) temp.start(); } if (options.statistics) { cout << "Right-quotient\n" << "Projecting #" << i; p.printsource(); cout << "\n "; print_stat(g); cout << " -> "; cout.flush(); } codeTable->begin(); GTA *result = gtaQuotientAndProject(g, offsets.off(i), quotient); codeTable->done(); num_projections++; num_right_quotients++; if (options.statistics) { print_stat(result); cout << "\n"; } if (options.time) { timer_project.stop(); if (options.statistics) { temp.stop(); cout << " Time: "; temp.print(); } } gtaFree(g); update_largest(result); return result; }
GTA * st_gta_minimization(GTA *g) { Timer temp; if (options.time) { timer_minimization.start(); if (options.statistics) temp.start(); } if (options.statistics) { cout << " Minimizing "; print_stat(g); cout << " -> "; cout.flush(); } codeTable->begin(); GTA *result = gtaMinimize(g); codeTable->done(); num_minimizations++; if (options.statistics) { print_stat(result); cout << "\n"; } if (options.time) { timer_minimization.stop(); if (options.statistics) { temp.stop(); cout << " Time: "; temp.print(); } } gtaFree(g); if (options.intermediate) gtaPrintVerbose(result); update_largest(result); return result; }
int delete_dir(zhandle_t* handle, const std::string& name, const std::string& stat_message) { int stat = zoo_delete(handle, name.c_str(), -1); // we are ok if the node is not empty in which case // there are still machines in the name space // if (stat == ZOK || stat == ZNOTEMPTY) return stat; if (stat != ZOK) print_stat(stat, stat_message + " delete_dir", name); return stat; }
int create_dir(zhandle_t* handle, const std::string& name, const std::string& stat_message) { int stat = zoo_create(handle, name.c_str(), NULL, -1, &ZOO_OPEN_ACL_UNSAFE, 0, NULL, 0); // we are ok with ZNODEEXISTS // if (stat == ZOK || stat == ZNODEEXISTS) return stat; if (stat != ZOK) print_stat(stat, stat_message + " create_dir", name); return stat; }
static void emit_struct(definition * def) { decl_list *dl; for (dl = def->def.st.decls; dl != NULL; dl = dl->next) { print_stat(&dl->decl); } }
static void baseline_nothread_mergesort(int * data , int start, int end_exclusive) { int len = end_exclusive - start; if(len <= 256) { qsort(data +start,len,sizeof(int), baseline_compare_fn); if(verbose) print_stat(data,start,end_exclusive); return; } int midpt = (start + end_exclusive)/2; baseline_nothread_mergesort(data, start,midpt); baseline_nothread_mergesort(data, midpt,end_exclusive); int * scratch = malloc(sizeof(int) * len); simple_merge(data, scratch, start, midpt, end_exclusive); free(scratch); if(verbose) print_stat(data,start, end_exclusive); }
void CacheStat::print_total_stat(const cache_stat* stat) { if (stat_valid(stat)) // valid. { fprintf(stderr, "%s\n", "ToTal:"); print_stat(0, stat); fprintf(stderr, "----------------------------------------------------------------------------\n"); } }
int create_ephemeral_node(zhandle_t* handle, const std::string& path, const std::string& value, const std::string& stat_message) { int stat = zoo_create(handle, path.c_str(), value.c_str(), value.length(), &ZOO_OPEN_ACL_UNSAFE, ZOO_EPHEMERAL, NULL, 0); // if (stat == ZOK) return stat; if (stat != ZOK) print_stat(stat, stat_message + " create_ephemeral_node", path); return stat; }