int main(int argc, char **argv) { hrtime_t s0, s, f, f0; uint64_t cnt = 0, icnt = 0; int psize = 0, i = 0; fq_client c; fq_msg *m; char *fq_debug = getenv("FQ_DEBUG"); if(fq_debug) fq_debug_set_bits(atoi(fq_debug)); signal(SIGPIPE, SIG_IGN); fq_client_init(&c, 0, logger); if(argc < 5) { fprintf(stderr, "%s <host> <port> <user> <pass> [size [count]]\n", argv[0]); exit(-1); } fq_client_creds(c, argv[1], atoi(argv[2]), argv[3], argv[4]); fq_client_heartbeat(c, 1000); fq_client_set_backlog(c, 10000, 100); fq_client_connect(c); if(argc > 5) { psize = atoi(argv[5]); } printf("payload size -> %d\n", psize); if(argc > 6) { send_count = atoi(argv[6]); } printf("message count -> %d\n", send_count); s0 = s = fq_gethrtime(); while(i < send_count || fq_client_data_backlog(c) > 0) { if(i < send_count) { m = fq_msg_alloc_BLANK(psize); memset(m->payload, 0, psize); fq_msg_exchange(m, "maryland", 8); fq_msg_route(m, "test.prefix.boo", 15); fq_msg_id(m, NULL); fq_client_publish(c, m); cnt++; i++; fq_msg_free(m); } else usleep(100); f = fq_gethrtime(); if(f-s > 1000000000) { print_rate(c, s, f, cnt, icnt); icnt = 0; cnt = 0; s = f; } } f0 = fq_gethrtime(); print_rate(c, s0, f0, i, 0); (void) argc; return 0; }
static void print_stat(struct btstat *st) { print_percent(st->content_got,st->content_size); print_size(st->downloaded); print_rate(st->rate_down); print_size(st->uploaded); print_rate(st->rate_up); print_ratio(st->tot_up,st->content_size); printf("%4u ",st->peers); printf("\n"); }
static void hashlimit_mt_print(const struct xt_hashlimit_mtinfo1 *info, unsigned int dmask) { if (info->cfg.mode & XT_HASHLIMIT_INVERT) fputs("limit: above ", stdout); else fputs("limit: up to ", stdout); print_rate(info->cfg.avg); printf("burst %u ", info->cfg.burst); if (info->cfg.mode & (XT_HASHLIMIT_HASH_SIP | XT_HASHLIMIT_HASH_SPT | XT_HASHLIMIT_HASH_DIP | XT_HASHLIMIT_HASH_DPT)) { fputs("mode ", stdout); print_mode(info->cfg.mode, '-'); } if (info->cfg.size != 0) printf("htable-size %u ", info->cfg.size); if (info->cfg.max != 0) printf("htable-max %u ", info->cfg.max); if (info->cfg.gc_interval != XT_HASHLIMIT_GCINTERVAL) printf("htable-gcinterval %u ", info->cfg.gc_interval); if (info->cfg.expire != XT_HASHLIMIT_EXPIRE) printf("htable-expire %u ", info->cfg.expire); if (info->cfg.srcmask != dmask) printf("srcmask %u ", info->cfg.srcmask); if (info->cfg.dstmask != dmask) printf("dstmask %u ", info->cfg.dstmask); }
static void hashlimit_mt_save(const struct xt_hashlimit_mtinfo1 *info, unsigned int dmask) { if (info->cfg.mode & XT_HASHLIMIT_INVERT) fputs("--hashlimit-above ", stdout); else fputs("--hashlimit-upto ", stdout); print_rate(info->cfg.avg); if (info->cfg.burst != XT_HASHLIMIT_BURST) printf("--hashlimit-burst %u ", info->cfg.burst); if (info->cfg.mode & (XT_HASHLIMIT_HASH_SIP | XT_HASHLIMIT_HASH_SPT | XT_HASHLIMIT_HASH_DIP | XT_HASHLIMIT_HASH_DPT)) { fputs("--hashlimit-mode ", stdout); print_mode(info->cfg.mode, ','); } printf("--hashlimit-name %s ", info->name); if (info->cfg.size != 0) printf("--hashlimit-htable-size %u ", info->cfg.size); if (info->cfg.max != 0) printf("--hashlimit-htable-max %u ", info->cfg.max); if (info->cfg.gc_interval != XT_HASHLIMIT_GCINTERVAL) printf("--hashlimit-htable-gcinterval %u", info->cfg.gc_interval); if (info->cfg.expire != XT_HASHLIMIT_EXPIRE) printf("--hashlimit-htable-expire %u ", info->cfg.expire); if (info->cfg.srcmask != dmask) printf("--hashlimit-srcmask %u ", info->cfg.srcmask); if (info->cfg.dstmask != dmask) printf("--hashlimit-dstmask %u ", info->cfg.dstmask); }
static void print_info(const struct iwinfo_ops *iw, const char *ifname) { printf("%-9s ESSID: %s\n", ifname, print_ssid(iw, ifname)); printf(" Access Point: %s\n", print_bssid(iw, ifname)); printf(" Type: %s HW Mode(s): %s\n", print_type(iw, ifname), print_hwmodes(iw, ifname)); printf(" Mode: %s Channel: %s (%s)\n", print_mode(iw, ifname), print_channel(iw, ifname), print_frequency(iw, ifname)); printf(" Tx-Power: %s Link Quality: %s/%s\n", print_txpower(iw, ifname), print_quality(iw, ifname), print_quality_max(iw, ifname)); printf(" Signal: %s Noise: %s\n", print_signal(iw, ifname), print_noise(iw, ifname)); printf(" Bit Rate: %s\n", print_rate(iw, ifname)); printf(" Encryption: %s\n", print_encryption(iw, ifname)); printf(" Supports VAPs: %s\n", print_mbssid_supp(iw, ifname)); }
/* dump simulator-specific auxiliary simulator statistics */ void sim_aux_stats(FILE *stream) /* output stream */ { /* nada */ print_counter(stream, "sim_elapsed_time", sim_elapsed_time, "simulation time in seconds"); print_rate(stream, "sim_insn_rate", (double)sim_num_insn/sim_elapsed_time, "simulation speed (insts/sec)"); print_counter(stream, "sim_num_insn", sim_num_insn, "instructions simulated (fast-forwarding included)"); print_counter(stream, "sim_sample_insn", sim_sample_insn, "instructions (in sample)"); print_counter(stream, "sim_sample_int", sim_sample_insn_split[ic_icomp] + sim_sample_insn_split[ic_icomplong], "integer operations"); print_counter(stream, "sim_sample_load", sim_sample_insn_split[ic_load], "loads"); print_counter(stream, "sim_sample_store", sim_sample_insn_split[ic_store], "stores"); print_counter(stream, "sim_sample_branch", sim_sample_insn_split[ic_ctrl], "branches"); print_counter(stream, "sim_sample_fp", sim_sample_insn_split[ic_fcomp] + sim_sample_insn_split[ic_fcomplong], "floating point operations"); print_counter(stream, "sim_sample_prefetch", sim_sample_insn_split[ic_prefetch], "prefetches"); print_counter(stream, "sim_sample_sys", sim_sample_insn_split[ic_sys], "syscalls"); /* register cache stats */ if (cache_dl1) cache_stats_print(cache_dl1, stream); if (dtlb) cache_stats_print(dtlb, stream); if (cache_il1 && cache_il1 != cache_dl1) cache_stats_print(cache_il1, stream); if (itlb && itlb != dtlb) cache_stats_print(itlb, stream); if (cache_l2) cache_stats_print(cache_l2, stream); }
static void limit_print(const void *ip, const struct xt_entry_match *match, int numeric) { const struct xt_rateinfo *r = (const void *)match->data; printf("limit: avg "); print_rate(r->avg); printf("burst %u ", r->burst); }
/* FIXME: Make minimalist: only print rate if not default --RR */ static void save(const struct ipt_ip *ip, const struct ipt_entry_match *match) { struct ipt_rateinfo *r = (struct ipt_rateinfo *)match->data; printf("--limit "); print_rate(r->avg); if (r->burst != IPT_LIMIT_BURST) printf("--limit-burst %u ", r->burst); }
static void limit_save(const void *ip, const struct xt_entry_match *match) { const struct xt_rateinfo *r = (const void *)match->data; printf("--limit "); print_rate(r->avg); if (r->burst != XT_LIMIT_BURST) printf("--limit-burst %u ", r->burst); }
static void print(const struct ebt_u_entry *entry, const struct ebt_entry_match *match) { struct ebt_limit_info *r = (struct ebt_limit_info *)match->data; printf("--limit "); print_rate(r->avg); printf("--limit-burst %u ", r->burst); }
/* Prints out the matchinfo. */ static void print(const struct ipt_ip *ip, const struct ipt_entry_match *match, int numeric) { struct ipt_rateinfo *r = (struct ipt_rateinfo *)match->data; printf("limit: avg "); print_rate(r->avg); printf("burst %u ", r->burst); }
int main(int argc, char **argv) { hrtime_t s, f; uint64_t cnt = 0, icnt = 0, icnt_total = 0; int rcvd = 0; fq_client c; fq_bind_req breq; fq_msg *m; signal(SIGPIPE, SIG_IGN); fq_client_init(&c, 0, logger); if(argc < 5) { fprintf(stderr, "%s <host> <port> <user> <pass> [size [count]]\n", argv[0]); exit(-1); } fq_client_creds(c, argv[1], atoi(argv[2]), argv[3], argv[4]); fq_client_heartbeat(c, 1000); fq_client_set_backlog(c, 10000, 100); fq_client_connect(c); memset(&breq, 0, sizeof(breq)); memcpy(breq.exchange.name, "maryland", 8); breq.exchange.len = 8; breq.peermode = 0; breq.program = (char *)"prefix:\"test.prefix.\""; fq_client_bind(c, &breq); while(breq.out__route_id == 0) usleep(100); printf("route set -> %u\n", breq.out__route_id); if(breq.out__route_id == FQ_BIND_ILLEGAL) { fprintf(stderr, "Failure to bind...\n"); exit(-1); } s = fq_gethrtime(); while(1) { f = fq_gethrtime(); while(m = fq_client_receive(c)) { icnt++; icnt_total++; rcvd++; fq_msg_deref(m); } usleep(1000); if(f-s > 1000000000) { print_rate(c, s, f, cnt, icnt); printf("total: %llu\n", (unsigned long long)icnt_total); icnt = 0; cnt = 0; s = f; } } (void) argc; return 0; }
void * my_thread( void *v ) { long num = ( long ) v; int n; int EventSet = PAPI_NULL; long long value; int retval = PAPI_register_thread( ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval ); pthread_setspecific( key, v ); count[num] = 0; iter[num] = 0; last[num] = start; if ( PAPI_create_eventset( &EventSet ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset failed", 1 ); if ( PAPI_add_event( EventSet, EVENT ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_add_event failed", 1 ); if ( PAPI_overflow( EventSet, EVENT, threshold, 0, my_handler ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow failed", 1 ); if ( PAPI_start( EventSet ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start failed", 1 ); printf( "launched timer in thread %ld\n", num ); for ( n = 1; n <= program_time; n++ ) { do_cycles( num, 1 ); print_rate( num ); } PAPI_stop( EventSet, &value ); retval = PAPI_overflow( EventSet, EVENT, 0, 0, my_handler); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow failed to reset the overflow handler", retval ); if ( PAPI_remove_event( EventSet, EVENT ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_remove_event", 1 ); if ( PAPI_destroy_eventset( &EventSet ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", 1 ); if ( PAPI_unregister_thread( ) != PAPI_OK != retval ) test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", 1 ); return ( NULL ); }
static void print_total_dl_stats(int count, double duration, off_t total_xfer) { const char *rate_label, *xfered_label; double rate, xfered_human, rate_human; int width; rate = total_xfer / duration; xfered_human = humanize_size(total_xfer, '\0', -1, &xfered_label); rate_human = humanize_size(rate, '\0', -1, &rate_label); width = printf(":: download complete in %.2fs", duration); printf("%*s<", 42 - width, ""); print_rate(xfered_human, xfered_label, rate_human, rate_label[0]); printf(" %2d file%c >\n", count, count == 1 ? ' ' : 's'); }
void *thread_cli_fun(void *arg) { double busy; int inx; Msg *msg; struct rusage r_start; struct rusage r_stop; struct timeval t_elapsed_data; struct timeval t_elapsed_total; struct timeval t_start_data; struct timeval t_start_total; struct timeval t_stop; arg = arg; // touch util_time_timer_start(&t_start_total); util_time_timer_start(&t_start_data); util_cpu_timer_start(&r_start); for (inx = 0; inx < loop; inx++) { if (verbose) printf("count=%d\n", inx); msg = msg_queue_remove(&mutex_pool, &queue_pool); assert(msg != NULL); if (csize) { msg->cbuf = (char *) malloc(csize); memcpy(msg->cbuf, send_buffer2, csize); } if (dsize) { msg->dbuf = (char *) malloc(dsize); memcpy(msg->dbuf, send_buffer, dsize); } msg_queue_add(&mutex_srv, &queue_srv, msg); cv_signal(&cv_srv); cv_wait(&cv_cli); msg = msg_queue_remove(&mutex_cli, &queue_cli); assert(msg != NULL); msg_queue_add(&mutex_pool, &queue_pool, msg); } util_cpu_timer_stop(&r_stop); util_time_timer_stop(&t_stop); util_time_elapsed(&t_start_total, &t_stop, &t_elapsed_total); util_time_elapsed(&t_start_data, &t_stop, &t_elapsed_data); util_cpu_timer_busy(&r_start, &r_stop, &t_elapsed_data, &busy); if (!bm) { print_elapsed("", &t_elapsed_total); print_elapsed(" (data)", &t_elapsed_data); } print_rate(bm, "", bidir ? 2 * loop : loop, dsize, &t_elapsed_data, busy); return NULL; }
int main(int argc, char **argv) { hrtime_t s, f; uint64_t cnt = 0, icnt = 0, icnt_total = 0; int rcvd = 0; fq_client c; fq_msg *m; char *fq_debug = getenv("FQ_DEBUG"); if(fq_debug) fq_debug_set_bits(atoi(fq_debug)); signal(SIGPIPE, SIG_IGN); fq_client_init(&c, 0, logger); if(fq_client_hooks(c, &hooks)) { fprintf(stderr, "Can't register hooks\n"); exit(-1); } if(argc < 5) { fprintf(stderr, "%s <host> <port> <user> <pass> [size [count]]\n", argv[0]); exit(-1); } fq_client_hooks(c, &hooks); fq_client_creds(c, argv[1], atoi(argv[2]), argv[3], argv[4]); fq_client_heartbeat(c, 1000); fq_client_set_backlog(c, 10000, 100); fq_client_connect(c); s = fq_gethrtime(); while(1) { f = fq_gethrtime(); while(m = fq_client_receive(c)) { icnt++; icnt_total++; rcvd++; fq_msg_deref(m); } usleep(1000); if(f-s > 1000000000) { print_rate(c, s, f, cnt, icnt); printf("total: %llu\n", (unsigned long long)icnt_total); icnt = 0; cnt = 0; s = f; } } (void) argc; return 0; }
static void hashlimit_print(const void *ip, const struct xt_entry_match *match, int numeric) { const struct xt_hashlimit_info *r = (const void *)match->data; fputs("limit: avg ", stdout); print_rate(r->cfg.avg); printf("burst %u ", r->cfg.burst); fputs("mode ", stdout); print_mode(r->cfg.mode, '-'); if (r->cfg.size) printf("htable-size %u ", r->cfg.size); if (r->cfg.max) printf("htable-max %u ", r->cfg.max); if (r->cfg.gc_interval != XT_HASHLIMIT_GCINTERVAL) printf("htable-gcinterval %u ", r->cfg.gc_interval); if (r->cfg.expire != XT_HASHLIMIT_EXPIRE) printf("htable-expire %u ", r->cfg.expire); }
static void print_download_success(struct repo_t *repo, int remaining) { const char *rate_label, *xfered_label; double rate, xfered_human; int width; rate = repo->tmpfile.size / (now() - repo->dl_time_start); xfered_human = humanize_size(repo->tmpfile.size, '\0', -1, &xfered_label); printf(" download complete: %-20s [", repo->name); if (fabs(rate - INFINITY) < DBL_EPSILON) { width = printf(" [%6.1f %3s %7s ", xfered_human, xfered_label, "----"); } else { double rate_human = humanize_size(rate, '\0', -1, &rate_label); width = print_rate(xfered_human, xfered_label, rate_human, rate_label[0]); } printf(" %*d remaining]\n", 23 - width, remaining); }
static void hashlimit_save(const void *ip, const struct xt_entry_match *match) { const struct xt_hashlimit_info *r = (const void *)match->data; fputs("--hashlimit ", stdout); print_rate(r->cfg.avg); if (r->cfg.burst != XT_HASHLIMIT_BURST) printf("--hashlimit-burst %u ", r->cfg.burst); fputs("--hashlimit-mode ", stdout); print_mode(r->cfg.mode, ','); printf("--hashlimit-name %s ", r->name); if (r->cfg.size) printf("--hashlimit-htable-size %u ", r->cfg.size); if (r->cfg.max) printf("--hashlimit-htable-max %u ", r->cfg.max); if (r->cfg.gc_interval != XT_HASHLIMIT_GCINTERVAL) printf("--hashlimit-htable-gcinterval %u ", r->cfg.gc_interval); if (r->cfg.expire != XT_HASHLIMIT_EXPIRE) printf("--hashlimit-htable-expire %u ", r->cfg.expire); }
static int cbq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) { struct rtattr *tb[TCA_CBQ_MAX+1]; struct tc_ratespec *r = NULL; struct tc_cbq_lssopt *lss = NULL; struct tc_cbq_wrropt *wrr = NULL; struct tc_cbq_fopt *fopt = NULL; struct tc_cbq_ovl *ovl = NULL; if (opt == NULL) return 0; memset(tb, 0, sizeof(tb)); parse_rtattr(tb, TCA_CBQ_MAX, RTA_DATA(opt), RTA_PAYLOAD(opt)); if (tb[TCA_CBQ_RATE]) { if (RTA_PAYLOAD(tb[TCA_CBQ_RATE]) < sizeof(*r)) fprintf(stderr, "CBQ: too short rate opt\n"); else r = RTA_DATA(tb[TCA_CBQ_RATE]); } if (tb[TCA_CBQ_LSSOPT]) { if (RTA_PAYLOAD(tb[TCA_CBQ_LSSOPT]) < sizeof(*lss)) fprintf(stderr, "CBQ: too short lss opt\n"); else lss = RTA_DATA(tb[TCA_CBQ_LSSOPT]); } if (tb[TCA_CBQ_WRROPT]) { if (RTA_PAYLOAD(tb[TCA_CBQ_WRROPT]) < sizeof(*wrr)) fprintf(stderr, "CBQ: too short wrr opt\n"); else wrr = RTA_DATA(tb[TCA_CBQ_WRROPT]); } if (tb[TCA_CBQ_FOPT]) { if (RTA_PAYLOAD(tb[TCA_CBQ_FOPT]) < sizeof(*fopt)) fprintf(stderr, "CBQ: too short fopt\n"); else fopt = RTA_DATA(tb[TCA_CBQ_FOPT]); } if (tb[TCA_CBQ_OVL_STRATEGY]) { if (RTA_PAYLOAD(tb[TCA_CBQ_OVL_STRATEGY]) < sizeof(*ovl)) fprintf(stderr, "CBQ: too short overlimit strategy %u/%u\n", (unsigned) RTA_PAYLOAD(tb[TCA_CBQ_OVL_STRATEGY]), (unsigned) sizeof(*ovl)); else ovl = RTA_DATA(tb[TCA_CBQ_OVL_STRATEGY]); } if (r) { char buf[64]; print_rate(buf, sizeof(buf), r->rate); fprintf(f, "rate %s ", buf); if (show_details) { fprintf(f, "cell %ub ", 1<<r->cell_log); if (r->mpu) fprintf(f, "mpu %ub ", r->mpu); } } if (lss && lss->flags) { int comma=0; fprintf(f, "("); if (lss->flags&TCF_CBQ_LSS_BOUNDED) { fprintf(f, "bounded"); comma=1; } if (lss->flags&TCF_CBQ_LSS_ISOLATED) { if (comma) fprintf(f, ","); fprintf(f, "isolated"); } fprintf(f, ") "); } if (wrr) { if (wrr->priority != TC_CBQ_MAXPRIO) fprintf(f, "prio %u", wrr->priority); else fprintf(f, "prio no-transmit"); if (show_details) { char buf[64]; fprintf(f, "/%u ", wrr->cpriority); if (wrr->weight != 1) { print_rate(buf, sizeof(buf), wrr->weight); fprintf(f, "weight %s ", buf); } if (wrr->allot) fprintf(f, "allot %ub ", wrr->allot); } } if (lss && show_details) { fprintf(f, "\nlevel %u ewma %u avpkt %ub ", lss->level, lss->ewma_log, lss->avpkt); if (lss->maxidle) { fprintf(f, "maxidle %luus ", tc_core_tick2usec(lss->maxidle>>lss->ewma_log)); if (show_raw) fprintf(f, "[%08x] ", lss->maxidle); }
int main(int argc, char *argv[]) { int arg; bool bm = false; char *buf; double busy; bool chook = false; bool client = false; char errnobuf[100]; char error_txt[200]; int event_len; char event_data[MS_MON_MAX_SYNC_DATA]; int ferr; int inx; int key; int lerr; int loop = 10; int msid; int pid; char prog[MS_MON_MAX_PROCESS_PATH]; struct rusage r_start; struct rusage r_stop; const char *server_name = "$SRV"; int server_nid; TPT_DECL (server_phandle); int server_pid; bool shook = false; struct timeval t_elapsed; struct timeval t_start; struct timeval t_stop; TAD zargs[] = { { "-bm", TA_Bool, TA_NOMAX, &bm }, { "-chook", TA_Bool, TA_NOMAX, &chook }, { "-client", TA_Bool, TA_NOMAX, &client }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "-shook", TA_Bool, TA_NOMAX, &shook }, { "", TA_End, TA_NOMAX, NULL } }; ferr = msg_init(&argc, &argv); arg_proc_args(zargs, false, argc, argv); if (chook && client) test_debug_hook("c", "c"); if (shook && !client) test_debug_hook("s", "s"); util_test_start(client); ferr = msg_mon_process_startup(!client); // system messages? TEST_CHK_FEOK(ferr); proc_enable_external_wakeups(); // allow external wakeups if (client) { ferr = msg_mon_get_process_info(NULL, &server_nid, &server_pid); TEST_CHK_FEOK(ferr); sprintf(prog, "%s/%s", getenv("PWD"), argv[0]); for (arg = 0; arg < argc; arg++) if (strcmp(argv[arg], "-client") == 0) // start_process argv[arg] = (char *) "-server"; ferr = msg_mon_start_process(prog, // prog (char *) server_name, // name NULL, // ret name argc, argv, TPT_REF(server_phandle), 0, // open NULL, // oid MS_ProcessType_Generic, // type 0, // priority 0, // debug 0, // backup &server_nid, // nid &server_pid, // pid NULL, // infile NULL); // outfile printf("process started, err=%d\n", ferr); TEST_CHK_FEOK(ferr); } util_gethostname(my_name, sizeof(my_name)); lerr = XWAIT(LREQ, -1); // remove first LREQ assert(lerr == LREQ); ferr = msg_mon_get_my_segid(&key); TEST_CHK_FEOK(ferr); // process-wait for client/server/shell ferr = msfs_util_wait_process_count(MS_ProcessType_Generic, 3, NULL, false); TEST_CHK_FEOK(ferr); if (client) { ferr = msg_mon_event_wait(1, &event_len, event_data); TEST_CHK_FEOK(ferr); msid = shmget(key, sizeof(recv_buffer), 0640); if (msid == -1) { perror("client shmget"); sprintf(error_txt, "client shmget(%d)=%s\n", key, strerror_r(errno, errnobuf, sizeof(errnobuf))); } assert(msid != -1); buf = (char *) shmat(msid, NULL, 0); assert(buf != NULL); } else { msid = shmget(key, sizeof(recv_buffer), IPC_CREAT | 0640); if (msid == -1) { perror("server shmget"); sprintf(error_txt, "server shmget(%d)=%s\n", key, strerror_r(errno, errnobuf, sizeof(errnobuf))); } assert(msid != -1); buf = (char *) shmat(msid, NULL, 0); assert(buf != NULL); ferr = msg_mon_event_send(-1, // nid -1, // pid MS_ProcessType_Undefined, // process-type 1, // event-id 0, // event-len NULL); // event-data TEST_CHK_FEOK(ferr); ferr = msg_mon_event_wait(1, &event_len, event_data); TEST_CHK_FEOK(ferr); } util_time_timer_start(&t_start); util_cpu_timer_start(&r_start); if (client) { pid = server_pid; for (inx = 0; inx < loop; inx++) { lerr = XPROCESS_AWAKE_(pid, LREQ); assert(lerr == XZFIL_ERR_OK); lerr = XWAIT(LDONE, -1); assert(lerr == LDONE); } } else { ferr = msg_mon_get_process_info((char *) "$CLI", &server_nid, &pid); TEST_CHK_FEOK(ferr); for (inx = 0; inx < loop; inx++) { lerr = XWAIT(LREQ, -1); assert(lerr == LREQ); lerr = XPROCESS_AWAKE_(pid, LDONE); assert(lerr == XZFIL_ERR_OK); } } util_cpu_timer_stop(&r_stop); util_time_timer_stop(&t_stop); util_time_elapsed(&t_start, &t_stop, &t_elapsed); util_cpu_timer_busy(&r_start, &r_stop, &t_elapsed, &busy); if (client) { if (!bm) print_elapsed("", &t_elapsed); print_rate(bm, "", loop, 1024, &t_elapsed, busy); } else print_server_busy(bm, "", busy); ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { bool bidir = false; bool bm = false; void *buf; double busy; _xcc_status cc; int count_read; int count_written; int count_xferred; int dsize = 1024; int ferr; short filenum[MAX_SERVERS]; short filenumr; int inx; int loop = 10; int max; int maxsp = 1; bool mq = false; bool nocopy = false; bool nowaitc = false; bool nowaits = false; int pinx; struct rusage r_start; struct rusage r_stop; char *recv_buffer_ptr; RI_Type ri; short sender_len; int sys_msg; struct timeval t_elapsed_data; struct timeval t_elapsed_open; struct timeval t_elapsed_total; struct timeval t_start_data; struct timeval t_start_total; struct timeval t_stop; SB_Tag_Type tag; short tfilenum; int timeout = -1; bool verbose = false; TAD zargs[] = { { "-bidir", TA_Bool, TA_NOMAX, &bidir }, { "-bm", TA_Bool, TA_NOMAX, &bm }, { "-client", TA_Bool, TA_NOMAX, &client }, { "-dsize", TA_Int, MAX_DBUF, &dsize }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-maxcp", TA_Int, MAX_CLIENTS, &maxcp }, { "-maxsp", TA_Int, MAX_SERVERS, &maxsp }, { "-mq", TA_Bool, TA_NOMAX, &mq }, { "-nocopy", TA_Bool, TA_NOMAX, &nocopy }, { "-nowaitc", TA_Bool, TA_NOMAX, &nowaitc }, { "-nowaits", TA_Bool, TA_NOMAX, &nowaits }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "", TA_End, TA_NOMAX, NULL } }; for (inx = 0; inx < MAX_CLIENTS; inx++) account[inx] = 0; signal(SIGUSR2, printaccount); ferr = file_init(&argc, &argv); TEST_CHK_FEOK(ferr); msfs_util_init_fs(&argc, &argv, file_debug_hook); arg_proc_args(zargs, false, argc, argv); if (maxcp < 0) maxcp = 1; if (maxsp < 0) maxsp = 1; util_test_start(client); ferr = file_mon_process_startup(!client); // system messages? TEST_CHK_FEOK(ferr); if (nocopy) { ferr = file_buf_register(buf_alloc, buf_free); TEST_CHK_FEOK(ferr); } ferr = msg_mon_get_my_process_name(my_name, BUFSIZ); TEST_CHK_FEOK(ferr); // process-wait for clients/servers/shell ferr = msfs_util_wait_process_count(MS_ProcessType_Generic, maxcp + maxsp + 1, NULL, verbose); if (client) sleep(1); util_time_timer_start(&t_start_total); if (client) { inx = atoi(&my_name[4]); printf("dsize=%d, loop=%d\n", dsize, loop); for (pinx = 0; pinx < maxsp; pinx++) { sprintf(serv, "$srv%d", pinx); ferr = BFILE_OPEN_(serv, (short) strlen(serv), &filenum[pinx], 0, 0, nowaitc ? (short) 1 : (short) 0, 0, 0, 0, 0, NULL); TEST_CHK_FEOK(ferr); } util_time_timer_start(&t_start_data); util_cpu_timer_start(&r_start); util_time_elapsed(&t_start_total, &t_start_data, &t_elapsed_open); max = loop; for (inx = 0; inx < max; inx++) { for (pinx = 0; pinx < maxsp; pinx++) { if (pinx == 0) { if (verbose) printf("%s-count=%d\n", my_name, inx); else if (mq && ((inx % 1000) == 0)) printf("%s-count=%d\n", my_name, inx); } cc = BWRITEREADX(filenum[pinx], send_buffer, (int) dsize, // cast bidir ? dsize : 0, &count_read, 0); } for (pinx = 0; pinx < maxsp; pinx++) { if (nowaitc) { TEST_CHK_CCEQ(cc); tfilenum = filenum[pinx]; cc = BAWAITIOX(&tfilenum, &buf, &count_xferred, &tag, timeout, NULL); TEST_CHK_CCEQ(cc); } } } } else { ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenumr, 0, 0, nowaits ? (short) 1 : (short) 0, // nowait 1, 0, // sys msg 0, 0, NULL); TEST_CHK_FEOK(ferr); util_time_timer_start(&t_start_data); util_cpu_timer_start(&r_start); max = maxcp * loop; for (inx = 0; inx < max; inx++) { if (nocopy) { cc = file_buf_readupdatex(filenumr, &recv_buffer_ptr, &count_read, 0); buf_free(recv_buffer_ptr); } else cc = BREADUPDATEX(filenumr, recv_buffer, (int) dsize, // cast &count_read, 0); if (nowaits) { tfilenum = -1; cc = BAWAITIOX(&tfilenum, &buf, &count_xferred, &tag, timeout, NULL); // don't check cc - could be sys msg sys_msg = _xstatus_ne(cc); } else sys_msg = _xstatus_ne(cc); if (sys_msg) inx--; if (!sys_msg) { getri(&ri); ferr = XPROCESSHANDLE_DECOMPOSE_(TPT_REF(ri.sender), NULL, // cpu NULL, // pin NULL, // nodenumber NULL, // nodename 0, // nodename NULL, // nodename_length sender, sizeof(sender), &sender_len, NULL); // sequence_number TEST_CHK_FEOK(ferr); sender[sender_len] = 0; if (verbose) printf("sender=%s\n", sender); char *p = &sender[4]; // past $cli int sender_inx = atoi(p); account[sender_inx]++; } cc = BREPLYX(recv_buffer, bidir ? dsize : 0, &count_written, 0, XZFIL_ERR_OK); TEST_CHK_CCEQ(cc); } } util_cpu_timer_stop(&r_stop); util_time_timer_stop(&t_stop); util_time_elapsed(&t_start_total, &t_stop, &t_elapsed_total); util_time_elapsed(&t_start_data, &t_stop, &t_elapsed_data); util_cpu_timer_busy(&r_start, &r_stop, &t_elapsed_data, &busy); if (client) { if (!bm) { print_elapsed("", &t_elapsed_total); print_elapsed(" (data)", &t_elapsed_data); print_elapsed(" (open)", &t_elapsed_open); } print_rate(bm, "", bidir ? 2 * loop : loop, dsize, &t_elapsed_data, busy); } else print_server_busy(bm, "", busy); if (client) { for (pinx = 0; pinx < maxsp; pinx++) { ferr = BFILE_CLOSE_(filenum[pinx], 0); TEST_CHK_FEOK(ferr); } } else { ferr = BFILE_CLOSE_(filenumr, 0); TEST_CHK_FEOK(ferr); ferr = file_mon_process_close(); TEST_CHK_FEOK(ferr); } ferr = file_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); printaccount(0); return 0; }
static void test_block_device (void) { int fd; char tmpfile[] = "/tmp/speedtestXXXXXX"; CLEANUP_FREE char **devices = NULL; char *r; const char *argv[4]; int t = max_time_override > 0 ? max_time_override : TEST_BLOCK_DEVICE_TIME; char tbuf[64]; int64_t bytes_written, bytes_read; if (!block_device_write && !block_device_read) return; snprintf (tbuf, sizeof tbuf, "%d", t); g = guestfs_create (); if (!g) error (EXIT_FAILURE, errno, "guestfs_create"); /* Create a fully allocated backing file. Note we are not testing * the speed of allocation on the host. */ fd = mkstemp (tmpfile); if (fd == -1) error (EXIT_FAILURE, errno, "mkstemp: %s", tmpfile); close (fd); if (guestfs_disk_create (g, tmpfile, "raw", INT64_C (1024*1024*1024), GUESTFS_DISK_CREATE_PREALLOCATION, "full", -1) == -1) exit (EXIT_FAILURE); if (guestfs_add_drive (g, tmpfile) == -1) exit (EXIT_FAILURE); if (guestfs_launch (g) == -1) exit (EXIT_FAILURE); devices = guestfs_list_devices (g); if (devices == NULL) exit (EXIT_FAILURE); if (devices[0] == NULL) { fprintf (stderr, "%s: expected guestfs_list_devices to return at least 1 device\n", guestfs_int_program_name); exit (EXIT_FAILURE); } if (block_device_write) { /* Test write speed. */ argv[0] = devices[0]; argv[1] = "w"; argv[2] = tbuf; argv[3] = NULL; r = guestfs_debug (g, "device_speed", (char **) argv); if (r == NULL) exit (EXIT_FAILURE); if (sscanf (r, "%" SCNi64, &bytes_written) != 1) { fprintf (stderr, "%s: could not parse device_speed output\n", guestfs_int_program_name); exit (EXIT_FAILURE); } print_rate ("block device writes:", bytes_written / t); } if (block_device_read) { /* Test read speed. */ argv[0] = devices[0]; argv[1] = "r"; argv[2] = tbuf; argv[3] = NULL; r = guestfs_debug (g, "device_speed", (char **) argv); if (r == NULL) exit (EXIT_FAILURE); if (sscanf (r, "%" SCNi64, &bytes_read) != 1) { fprintf (stderr, "%s: could not parse device_speed output\n", guestfs_int_program_name); exit (EXIT_FAILURE); } print_rate ("block device reads:", bytes_read / t); } if (guestfs_shutdown (g) == -1) exit (EXIT_FAILURE); guestfs_close (g); /* Remove temporary file. */ unlink (tmpfile); }
static void test_virtio_serial (void) { int fd, r, eh; char tmpfile[] = "/tmp/speedtestXXXXXX"; struct sigaction sa, old_sa; if (!virtio_serial_upload && !virtio_serial_download) return; /* Create a sparse file. We could upload from /dev/zero, but we * won't get progress messages because libguestfs tests if the * source file is a regular file. */ fd = mkstemp (tmpfile); if (fd == -1) error (EXIT_FAILURE, errno, "mkstemp: %s", tmpfile); if (ftruncate (fd, TEST_SERIAL_MAX_SIZE) == -1) error (EXIT_FAILURE, errno, "ftruncate"); if (close (fd) == -1) error (EXIT_FAILURE, errno, "close"); g = guestfs_create (); if (!g) error (EXIT_FAILURE, errno, "guestfs_create"); if (guestfs_add_drive_scratch (g, INT64_C (100*1024*1024), -1) == -1) exit (EXIT_FAILURE); if (guestfs_launch (g) == -1) exit (EXIT_FAILURE); /* Make and mount a filesystem which will be used by the download test. */ if (guestfs_mkfs (g, "ext4", "/dev/sda") == -1) exit (EXIT_FAILURE); if (guestfs_mount (g, "/dev/sda", "/") == -1) exit (EXIT_FAILURE); /* Time out the upload after TEST_SERIAL_MAX_TIME seconds have passed. */ memset (&sa, 0, sizeof sa); sa.sa_handler = stop_transfer; sa.sa_flags = SA_RESTART; sigaction (SIGALRM, &sa, &old_sa); /* Get progress messages, which will tell us how much data has been * transferred. */ eh = guestfs_set_event_callback (g, progress_cb, GUESTFS_EVENT_PROGRESS, 0, NULL); if (eh == -1) exit (EXIT_FAILURE); if (virtio_serial_upload) { gettimeofday (&start, NULL); rate = -1; operation = "upload"; alarm (max_time_override > 0 ? max_time_override : TEST_SERIAL_MAX_TIME); /* For the upload test, upload the sparse file to /dev/null in the * appliance. Hopefully this is mostly testing just virtio-serial. */ guestfs_push_error_handler (g, NULL, NULL); r = guestfs_upload (g, tmpfile, "/dev/null"); alarm (0); unlink (tmpfile); guestfs_pop_error_handler (g); /* It's possible that the upload will finish before the alarm fires, * or that the upload will be stopped by the alarm. */ if (r == -1 && guestfs_last_errno (g) != EINTR) { fprintf (stderr, "%s: expecting upload command to return EINTR\n%s\n", guestfs_int_program_name, guestfs_last_error (g)); exit (EXIT_FAILURE); } if (rate == -1) { rate_error: fprintf (stderr, "%s: internal error: progress callback was not called! (r=%d, errno=%d)\n", guestfs_int_program_name, r, guestfs_last_errno (g)); exit (EXIT_FAILURE); } print_rate ("virtio-serial upload rate:", rate); } if (virtio_serial_download) { /* For the download test, download a sparse file within the * appliance to /dev/null on the host. */ if (guestfs_touch (g, "/sparse") == -1) exit (EXIT_FAILURE); if (guestfs_truncate_size (g, "/sparse", TEST_SERIAL_MAX_SIZE) == -1) exit (EXIT_FAILURE); gettimeofday (&start, NULL); rate = -1; operation = "download"; alarm (max_time_override > 0 ? max_time_override : TEST_SERIAL_MAX_TIME); guestfs_push_error_handler (g, NULL, NULL); r = guestfs_download (g, "/sparse", "/dev/null"); alarm (0); guestfs_pop_error_handler (g); if (r == -1 && guestfs_last_errno (g) != EINTR) { fprintf (stderr, "%s: expecting download command to return EINTR\n%s\n", guestfs_int_program_name, guestfs_last_error (g)); exit (EXIT_FAILURE); } if (rate == -1) goto rate_error; print_rate ("virtio-serial download rate:", rate); } if (guestfs_shutdown (g) == -1) exit (EXIT_FAILURE); guestfs_close (g); /* Restore SIGALRM signal handler. */ sigaction (SIGALRM, &old_sa, NULL); }
// // process_testfile() // // Creates (mode == CREATE) or verifies (mode == VERIFY) a testfile named filename, // filesize uint32_ts long. Uses worker threads to accomplish the actual work, // overlapping I/O with computation. // // If used in VERIFY mode, returns 1 if any corruption was encountered during // the test. Otherwise, returns 0. // // File size parameter is in units of uint32_t, not char. // int process_testfile(testmode mode, const char* filename, off_t filesize, int count) { int found_corruption = 0; pthread_t producer, consumer; pthread_attr_t attr; int fd; if (mode == VERIFY) { fd = open(filename, O_RDONLY|O_LARGEFILE|O_DIRECT, 0); } else { fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE|O_DIRECT, 0644); } if (fd == -1) { fatal("Error: Couldn't open test file (%s).\n", filename); } // On MacOS X, turn off caching. Ideally this should be done on any OS that // supports it, since cache can defeat end-to-end testing. #if defined(__APPLE__) && defined(__MACH__) fcntl(fd, F_NOCACHE, 1); #endif wbuf* buffers = new wbuf[2]; workqueue* q = new workqueue; workorder* wo = new workorder; wo->q = q; wo->mode = mode; wo->fd = fd; wo->filesize = filesize; wo->bmode = (count % 2 == 0) ? COMPLEMENT : REGULAR; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); int p_err = pthread_create(&producer, &attr, (pthread_fn_ptr) producer_fn, (void*) wo); int c_err = pthread_create(&consumer, &attr, (pthread_fn_ptr) consumer_fn, (void*) wo); if (p_err || c_err) { fatal("Error while creating worker threads.\n"); } double start_time = timestamp(); // Give the work queue some empty buffers to get things moving q->release(&(buffers[0])); q->release(&(buffers[1])); // Now wait for the threads to finish p_err = pthread_join(producer, (void**)(&found_corruption)); c_err = pthread_join(consumer, (void**)(&found_corruption)); double end_time = timestamp(); if (p_err || c_err) { fatal("pthread_join() error.\n"); } print_rate(filesize, end_time - start_time); pthread_attr_destroy(&attr); delete wo; delete q; delete [] buffers; close(fd); return found_corruption; }
int main(int argc, char **argv) { hrtime_t s0, s, f, f0; uint64_t cnt = 0, icnt = 0; int psize = 0, i = 0, rcvd = 0; fq_client c; fq_bind_req breq; fq_msg *m; signal(SIGPIPE, SIG_IGN); fq_client_init(&c, 0, logger); if(argc < 5) { fprintf(stderr, "%s <host> <port> <user> <pass> [size [count]]\n", argv[0]); exit(-1); } fq_client_creds(c, argv[1], atoi(argv[2]), argv[3], argv[4]); fq_client_heartbeat(c, 1000); fq_client_set_backlog(c, 10000, 100); fq_client_connect(c); memset(&breq, 0, sizeof(breq)); memcpy(breq.exchange.name, "maryland", 8); breq.exchange.len = 8; breq.peermode = 0; breq.program = (char *)"prefix:\"test.prefix.\""; fq_client_bind(c, &breq); while(breq.out__route_id == 0) usleep(100); printf("route set -> %u\n", breq.out__route_id); if(breq.out__route_id == FQ_BIND_ILLEGAL) { fprintf(stderr, "Failure to bind...\n"); exit(-1); } if(argc > 5) { psize = atoi(argv[5]); } printf("payload size -> %d\n", psize); if(argc > 6) { send_count = atoi(argv[6]); } printf("message count -> %d\n", send_count); s0 = s = fq_gethrtime(); while(i < send_count || fq_client_data_backlog(c) > 0) { if(i < send_count) { m = fq_msg_alloc_BLANK(psize); memset(m->payload, 0, psize); fq_msg_exchange(m, "maryland", 8); fq_msg_route(m, "test.prefix.foo", 15); fq_msg_id(m, NULL); fq_client_publish(c, m); cnt++; i++; fq_msg_free(m); } else usleep(100); f = fq_gethrtime(); while(m = fq_client_receive(c)) { icnt++; rcvd++; fq_msg_deref(m); } if(f-s > 1000000000) { print_rate(c, s, f, cnt, icnt); icnt = 0; cnt = 0; s = f; } } f0 = fq_gethrtime(); print_rate(c, s0, f0, i, 0); do { icnt=0; while(m = fq_client_receive(c)) { icnt++; rcvd++; fq_msg_deref(m); } } while(rcvd < send_count); f0 = fq_gethrtime(); print_rate(c, s0, f0, 0, rcvd); printf("Total received during test: %d\n", rcvd); (void) argc; return 0; }