void eval_calls(std::vector<strvcfentry> entries, std::vector<strsimul> simul, int max_allowed_dist, std::string output) { strreport notfound = init_report(); strreport additional = init_report(); strreport found = init_report(); FILE * right; FILE * addition; std::string out = output; out += "_right.vcf"; right = fopen(out.c_str(), "w"); out = output; out += "addition.vcf"; addition = fopen(out.c_str(), "w"); //for (size_t i = 0; i < entries.size(); i++) { // std::cout<<entries[i].start.chr<<" "<<entries[i].start.pos<<" "<<entries[i].stop.chr<<" "<<entries[i].stop.pos<<" "<<entries[i].type<<std::endl; //} // std::cout<<"type dv"<<" "<<"rv"<<" "<<"dr"<<" "<<"rr"<<" "<<"gq"<<std::endl; for (size_t i = 0; i < entries.size(); i++) { bool found = false; for (size_t j = 0; j < simul.size(); j++) { if (simul[j].type == entries[i].type) { if (match_coords(simul[j], entries[i], max_allowed_dist)) { //check if order is perserved! simul[j].identified = true; found = true; } } } if (!found) { fprintf(addition, "%s", entries[i].header.c_str()); for (std::map<std::string, std::string>::iterator tz = entries[i].calls.begin(); tz != entries[i].calls.end(); tz++) { fprintf(addition, "%s", (*tz).second.c_str()); } fprintf(addition, "%c", '\n'); add_to_report(additional, entries[i].type); // std::cout<<"additional found: "<<entries[i].type<<" "<<entries[i].start.chr<<" "<<entries[i].start.pos<<" "<<entries[i].stop.chr<<" "<<entries[i].stop.pos<<std::endl; } else { fprintf(right, "%s", entries[i].header.c_str()); for (std::map<std::string, std::string>::iterator tz = entries[i].calls.begin(); tz != entries[i].calls.end(); tz++) { fprintf(right, "%s", (*tz).second.c_str()); } fprintf(right, "%c", '\n'); } } for (size_t j = 0; j < simul.size(); j++) { if (!simul[j].identified) { add_to_report(notfound, simul[j].type); std::cout<<simul[j].type<<" "<<simul[j].start.chr<<" "<<simul[j].start.pos<<" END: "<<simul[j].stop.chr<<" "<<simul[j].stop.pos<<std::endl; } else { add_to_report(found, simul[j].type); } } std::cout << " Overall: " << simul.size() << " " << print_report(found) << " " << print_report(notfound) << " " << print_report(additional) << " " << get_TP(simul.size(), found) << " " << get_FP(found, additional) << std::endl; }
static void tls_endpoint_estab_handler(const char *cipher, void *arg) { int err; (void)arg; re_fprintf(stderr, "\r[ %u .. %c ]", tlsperf.count, 0x20 + tlsperf.count % 0x60); if (tls_endpoint_established(tlsperf.ep_cli) && tls_endpoint_established(tlsperf.ep_srv)) { if (tlsperf.count >= tlsperf.num) { tlsperf.ts_estab = tmr_jiffies(); re_printf("\nDONE!\n"); re_printf("cipher: %s\n", cipher); print_report(); re_cancel(); } else { stop_test(); err = start_test(); if (err) abort_test(err); } } }
static void aio_write_done(void *opaque, int ret) { struct aio_ctx *ctx = opaque; struct timeval t2; gettimeofday(&t2, NULL); if (ret < 0) { printf("aio_write failed: %s\n", strerror(-ret)); goto out; } if (ctx->qflag) { goto out; } /* Finally, report back -- -C gives a parsable format */ t2 = tsub(t2, ctx->t1); print_report("wrote", &t2, ctx->offset, ctx->qiov.size, ctx->qiov.size, 1, ctx->Cflag); out: qemu_io_free(ctx->buf); qemu_iovec_destroy(&ctx->qiov); g_free(ctx); }
static void aio_write_done(void *opaque, int ret) { struct aio_ctx *ctx = opaque; struct timeval t2; gettimeofday(&t2, NULL); if (ret < 0) { printf("aio_write failed: %s\n", strerror(-ret)); goto out; } if (ctx->qflag) { goto out; } t2 = tsub(t2, ctx->t1); print_report("wrote", &t2, ctx->offset, ctx->qiov.size, ctx->qiov.size, 1, ctx->Cflag); out: qemu_io_free(ctx->buf); free(ctx); }
int send_probes (int ttl) { /* Removed to compile cleanly with -Wall */ //int i; int probe, code, done; Setsockopt (sendfd, IPPROTO_IP, IP_TTL, &ttl, sizeof(int)); bzero (salast, salen); printf ("%2d ", ttl); fflush (stdout); done = 0; /* count the number of probes that generate an ICMP_DEST_UNREACH */ for (probe = 0; probe < nprobes; probe++) { send_dgram (ttl); code = recv_dgram (); if (code == -3) { printf (" *"); } else { print_report (); } if (code == -1) done++; fflush (stdout); } printf ("ms\n"); return done; }
int main (void){ // Checks users input and exectutes task based on selection int choice = 0; // As long as user hasnt quit while (choice != QUIT) { // Prints menu, prompts user for selection choice = get_menu_choice(); if (choice == 1) printf("\nBeeping the computer \a\a\a"); else{ if (choice == 2) print_report(); } } printf("You chose to quit!\n"); return 0; }
static void mono_portability_iomap_event (MonoProfiler *prof, const char *report, const char *pathname, const char *new_pathname) { guint32 hash, pathnameHash; MismatchedFilesStats *stats; if (!runtime_initialized) return; mono_os_mutex_lock (&mismatched_files_section); hash = calc_strings_hash (pathname, new_pathname, &pathnameHash); stats = (MismatchedFilesStats*)g_hash_table_lookup (prof->mismatched_files_hash, &hash); if (stats == NULL) { guint32 *hashptr; stats = (MismatchedFilesStats*) g_malloc (sizeof (MismatchedFilesStats)); stats->count = 1; stats->requestedName = g_strdup (pathname); stats->actualName = g_strdup (new_pathname); hashptr = (guint32*)g_malloc (sizeof (guint32)); if (hashptr) { *hashptr = hash; g_hash_table_insert (prof->mismatched_files_hash, (gpointer)hashptr, stats); } else g_error ("Out of memory allocating integer pointer for mismatched files hash table."); store_string_location (prof, (const gchar*)stats->requestedName, pathnameHash, strlen (stats->requestedName)); mono_os_mutex_unlock (&mismatched_files_section); print_report ("%s - Found file path: '%s'\n", report, new_pathname); } else { mono_os_mutex_unlock (&mismatched_files_section); stats->count++; } }
/* * preserve_rec() - writes record into the pacct0 file. */ static int preserve_rec(struct acctjob *jh, int type, char *name) { /* * Read the next record. */ if (readacctent(sfd, &acctent, FORWARD) <= 0) { acct_err(ACCT_ABORT, _("An error occurred during the reading of file '%s' %s."), spacct, name); } if (acctent.csa && (acctent.csa->ac_jid == 0) ) { return(-1); } if (db_flag > 1) { Ndebug("preserve_rec(4): %s record, offset(%d, %#o), type %d:", name, rcd_offset, rcd_offset, type); Dump_acct_hdr(acctent.prime); } if (do_report) { print_report(type, &acctent); do_report = 0; if (A_opt) { write_ok = query(); } } if (write_ok) { if (first_rec) { /* * Create and write an uptime record if needed. */ if (jh->aj_btime > uptime_stop) { Uptime_record(TRUE); } if ((rcd_offset = seekacct(pfd0, 0, SEEK_CUR)) < 0) { acct_perr(ACCT_ABORT, errno, _("An error occurred during the positioning of file '%s' %s."), pacct0, "for the job entry"); } first_rec = FALSE; } if (writeacctent(pfd0, &acctent) <= 0) { acct_perr(ACCT_ABORT, errno, _("An error occurred during the writing of file '%s'."), pacct0); } } return(0); }
static int discard_f(int argc, char **argv) { struct timeval t1, t2; int Cflag = 0, qflag = 0; int c, ret; int64_t offset; int count; while ((c = getopt(argc, argv, "Cq")) != EOF) { switch (c) { case 'C': Cflag = 1; break; case 'q': qflag = 1; break; default: return command_usage(&discard_cmd); } } if (optind != argc - 2) { return command_usage(&discard_cmd); } offset = cvtnum(argv[optind]); if (offset < 0) { printf("non-numeric length argument -- %s\n", argv[optind]); return 0; } optind++; count = cvtnum(argv[optind]); if (count < 0) { printf("non-numeric length argument -- %s\n", argv[optind]); return 0; } gettimeofday(&t1, NULL); ret = bdrv_discard(bs, offset >> BDRV_SECTOR_BITS, count >> BDRV_SECTOR_BITS); gettimeofday(&t2, NULL); if (ret < 0) { printf("discard failed: %s\n", strerror(-ret)); goto out; } /* Finally, report back -- -C gives a parsable format */ if (!qflag) { t2 = tsub(t2, t1); print_report("discard", &t2, offset, count, count, 1, Cflag); } out: return 0; }
void spawner_new_c::run() { begin_report(); for (auto& i : runners) { i->run_process_async(); } for (auto& i : runners) { i->wait_for(); } print_report(); }
int main(int argc, char **argv) { int opt, sprofdiff = 0; #ifdef DEBUG /* disable buffering so the output mixes correctly */ setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0); #endif /* parse arguments */ while ((opt = getopt(argc, argv, "b:dp:s:")) != -1) { switch (opt) { case 'b': /* additional binary specified */ binary_add(optarg); break; case 'd': /* generate output for sprofdiff */ sprofdiff = 1; break; case 'p': /* minimum percentage specified */ minimum_perc = atof(optarg); if (minimum_perc < 0 || minimum_perc > 100) { fprintf(stderr, "error: cut-off percentage " "makes no sense: %g\n", minimum_perc); exit(1); } break; case 's': /* source tree directory specified */ src_path = optarg; break; default: usage(argv[0]); } } /* load samples */ if (optind >= argc) usage(argv[0]); for (; optind < argc; optind++) { struct endpoint_info *e; load_trace(argv[optind]); for(e = endpoints; e; e = e->next) e->seen = 0; } /* print report */ if (sprofdiff) { print_diff(); } else { print_report(); } return 0; }
/* * Top Level Flow Control */ int main(int argc, char **argv) { grok_args(argc, argv); if (do_input()) { set_fuel_type(); print_report(); rocksim_report(); } putchar('\n'); save_text_dump(stdout); exit(0); }
static void event_handler(json_object *obj) { json_object *child, *data, *body, *event; char *ev, *type, *message; if (!json_object_object_get_ex(obj, "data", &data)) { Warning("data not found"); return; } if (!json_object_object_get_ex(data, "event", &event)) { Warning("event not found"); return; } if (!json_object_object_get_ex(data, "body", &body)) { Warning("body not found"); return; } ev = (char *)json_object_get_string(event); if (!strcmp(ev, "client_data_ready")) { if (!json_object_object_get_ex(body, "type", &child)) { Warning("type not found"); return; } type = (char *)json_object_get_string(child); if (type != NULL) { if (!strcmp("report", type)) { print_report(body); } else if (!strcmp("misc", type)) { download_file(body); } } } else if (!strcmp(ev, "announcement")) { if (!json_object_object_get_ex(body, "message", &child)) { Warning("message not found"); return; } message = (char *)json_object_get_string(child); Notify(_("orca cloud announce"), message, "gtk-dialog-info", 30); } else if (!strcmp(ev, "websocket_reconnect")) { Notify(_("websocket_reconnect"), _("websocket_reconnect_message"), "gtk-dialog-warning", 30); } else if (!strcmp(ev, "websocket_disconnect")) { Notify(_("websocket_disconnect"), _("websocket_disconnect_message"), "gtk-dialog-warning", 30); } else { Warning("unknown event:%s", ev); } }
exception::exception(std::string message, bool print) : m_message(message), m_stack_trace(stack_trace::get()) { // Construct default message if none is provided if (m_message.empty()) { std::stringstream ss("LBANN exception"); const auto& rank = get_rank_in_world(); if (rank >= 0) { ss << " on rank " << rank; } m_message = ss.str(); } // Print report to standard error stream if (print) { print_report(std::cerr); } }
static void aio_read_done(void *opaque, int ret) { struct aio_ctx *ctx = opaque; struct timeval t2; gettimeofday(&t2, NULL); if (ret < 0) { printf("readv failed: %s\n", strerror(-ret)); goto out; } if (ctx->Pflag) { void *cmp_buf = malloc(ctx->qiov.size); memset(cmp_buf, ctx->pattern, ctx->qiov.size); if (memcmp(ctx->buf, cmp_buf, ctx->qiov.size)) { printf("Pattern verification failed at offset %" PRId64 ", %zd bytes\n", ctx->offset, ctx->qiov.size); } free(cmp_buf); } if (ctx->qflag) { goto out; } if (ctx->vflag) { dump_buffer(ctx->buf, ctx->offset, ctx->qiov.size); } /* Finally, report back -- -C gives a parsable format */ t2 = tsub(t2, ctx->t1); print_report("read", &t2, ctx->offset, ctx->qiov.size, ctx->qiov.size, 1, ctx->Cflag); out: qemu_io_free(ctx->buf); free(ctx); }
void osm_dump_all(osm_opensm_t * osm) { if (OSM_LOG_IS_ACTIVE_V2(&osm->log, OSM_LOG_ROUTING)) { /* unicast routes */ osm_dump_qmap_to_file(osm, "opensm-lid-matrix.dump", &osm->subn.sw_guid_tbl, dump_lid_matrix, osm); osm_dump_qmap_to_file(osm, "opensm-lfts.dump", &osm->subn.sw_guid_tbl, dump_ucast_lfts, osm); if (OSM_LOG_IS_ACTIVE_V2(&osm->log, OSM_LOG_DEBUG)) dump_qmap(stdout, &osm->subn.sw_guid_tbl, dump_ucast_path_distribution, osm); /* An attempt to get osm_switch_recommend_path to report the same routes that a sweep would assign. */ if (osm->subn.opt.scatter_ports) srandom(osm->subn.opt.scatter_ports); osm_dump_qmap_to_file(osm, "opensm.fdbs", &osm->subn.sw_guid_tbl, dump_ucast_routes, osm); /* multicast routes */ osm_dump_qmap_to_file(osm, "opensm.mcfdbs", &osm->subn.sw_guid_tbl, dump_mcast_routes, osm); /* SL2VL tables */ if (osm->subn.opt.qos || (osm->routing_engine_used && osm->routing_engine_used->update_sl2vl)) osm_dump_qmap_to_file(osm, "opensm-sl2vl.dump", &osm->subn.port_guid_tbl, dump_sl2vl_tbl, osm); } osm_dump_qmap_to_file(osm, "opensm-subnet.lst", &osm->subn.node_guid_tbl, dump_topology_node, osm); if (OSM_LOG_IS_ACTIVE_V2(&osm->log, OSM_LOG_VERBOSE)) print_report(osm, stdout); }
void spawner_new_c::run() { begin_report(); LOG("initialize..."); for (auto i : runners) { i->run_process_async(); } for (auto i : runners) { if (!i->wait_for_init(1000)) { PANIC("Failed to init process"); } } for (const auto& file_pipe : file_pipes) { file_pipe.second->start_read(); } for (auto i : runners) { i->get_pipe(std_stream_input)->check_parents(); } if (control_mode_enabled) { runners[controller_index_]->resume(); } else { for (auto i : runners) { i->resume(); } } LOG("initialized"); for (auto i : runners) { i->wait_for(); } for (auto i : runners) { i->finalize(); } for (const auto& file_pipe : file_pipes) { file_pipe.second->finalize(); } print_report(); }
static int write_f(int argc, char **argv) { struct timeval t1, t2; int Cflag = 0, pflag = 0, qflag = 0, bflag = 0, Pflag = 0, zflag = 0; int cflag = 0; int c, cnt; char *buf = NULL; int64_t offset; int count; /* Some compilers get confused and warn if this is not initialized. */ int total = 0; int pattern = 0xcd; while ((c = getopt(argc, argv, "bcCpP:qz")) != EOF) { switch (c) { case 'b': bflag = 1; break; case 'c': cflag = 1; break; case 'C': Cflag = 1; break; case 'p': pflag = 1; break; case 'P': Pflag = 1; pattern = parse_pattern(optarg); if (pattern < 0) { return 0; } break; case 'q': qflag = 1; break; case 'z': zflag = 1; break; default: return command_usage(&write_cmd); } } if (optind != argc - 2) { return command_usage(&write_cmd); } if (bflag + pflag + zflag > 1) { printf("-b, -p, or -z cannot be specified at the same time\n"); return 0; } if (zflag && Pflag) { printf("-z and -P cannot be specified at the same time\n"); return 0; } offset = cvtnum(argv[optind]); if (offset < 0) { printf("non-numeric length argument -- %s\n", argv[optind]); return 0; } optind++; count = cvtnum(argv[optind]); if (count < 0) { printf("non-numeric length argument -- %s\n", argv[optind]); return 0; } if (!pflag) { if (offset & 0x1ff) { printf("offset %" PRId64 " is not sector aligned\n", offset); return 0; } if (count & 0x1ff) { printf("count %d is not sector aligned\n", count); return 0; } } if (!zflag) { buf = qemu_io_alloc(count, pattern); } gettimeofday(&t1, NULL); if (pflag) { cnt = do_pwrite(buf, offset, count, &total); } else if (bflag) { cnt = do_save_vmstate(buf, offset, count, &total); } else if (zflag) { cnt = do_co_write_zeroes(offset, count, &total); } else if (cflag) { cnt = do_write_compressed(buf, offset, count, &total); } else { cnt = do_write(buf, offset, count, &total); } gettimeofday(&t2, NULL); if (cnt < 0) { printf("write failed: %s\n", strerror(-cnt)); goto out; } if (qflag) { goto out; } /* Finally, report back -- -C gives a parsable format */ t2 = tsub(t2, t1); print_report("wrote", &t2, offset, count, total, cnt, Cflag); out: if (!zflag) { qemu_io_free(buf); } return 0; }
static int readv_f(int argc, char **argv) { struct timeval t1, t2; int Cflag = 0, qflag = 0, vflag = 0; int c, cnt; char *buf; int64_t offset; /* Some compilers get confused and warn if this is not initialized. */ int total = 0; int nr_iov; QEMUIOVector qiov; int pattern = 0; int Pflag = 0; while ((c = getopt(argc, argv, "CP:qv")) != EOF) { switch (c) { case 'C': Cflag = 1; break; case 'P': Pflag = 1; pattern = parse_pattern(optarg); if (pattern < 0) { return 0; } break; case 'q': qflag = 1; break; case 'v': vflag = 1; break; default: return command_usage(&readv_cmd); } } if (optind > argc - 2) { return command_usage(&readv_cmd); } offset = cvtnum(argv[optind]); if (offset < 0) { printf("non-numeric length argument -- %s\n", argv[optind]); return 0; } optind++; if (offset & 0x1ff) { printf("offset %" PRId64 " is not sector aligned\n", offset); return 0; } nr_iov = argc - optind; buf = create_iovec(&qiov, &argv[optind], nr_iov, 0xab); if (buf == NULL) { return 0; } gettimeofday(&t1, NULL); cnt = do_aio_readv(&qiov, offset, &total); gettimeofday(&t2, NULL); if (cnt < 0) { printf("readv failed: %s\n", strerror(-cnt)); goto out; } if (Pflag) { void *cmp_buf = g_malloc(qiov.size); memset(cmp_buf, pattern, qiov.size); if (memcmp(buf, cmp_buf, qiov.size)) { printf("Pattern verification failed at offset %" PRId64 ", %zd bytes\n", offset, qiov.size); } g_free(cmp_buf); } if (qflag) { goto out; } if (vflag) { dump_buffer(buf, offset, qiov.size); } /* Finally, report back -- -C gives a parsable format */ t2 = tsub(t2, t1); print_report("read", &t2, offset, qiov.size, total, cnt, Cflag); out: qemu_iovec_destroy(&qiov); qemu_io_free(buf); return 0; }
static int read_f(int argc, char **argv) { struct timeval t1, t2; int Cflag = 0, pflag = 0, qflag = 0, vflag = 0; int Pflag = 0, sflag = 0, lflag = 0, bflag = 0; int c, cnt; char *buf; int64_t offset; int count; /* Some compilers get confused and warn if this is not initialized. */ int total = 0; int pattern = 0, pattern_offset = 0, pattern_count = 0; while ((c = getopt(argc, argv, "bCl:pP:qs:v")) != EOF) { switch (c) { case 'b': bflag = 1; break; case 'C': Cflag = 1; break; case 'l': lflag = 1; pattern_count = cvtnum(optarg); if (pattern_count < 0) { printf("non-numeric length argument -- %s\n", optarg); return 0; } break; case 'p': pflag = 1; break; case 'P': Pflag = 1; pattern = parse_pattern(optarg); if (pattern < 0) { return 0; } break; case 'q': qflag = 1; break; case 's': sflag = 1; pattern_offset = cvtnum(optarg); if (pattern_offset < 0) { printf("non-numeric length argument -- %s\n", optarg); return 0; } break; case 'v': vflag = 1; break; default: return command_usage(&read_cmd); } } if (optind != argc - 2) { return command_usage(&read_cmd); } if (bflag && pflag) { printf("-b and -p cannot be specified at the same time\n"); return 0; } offset = cvtnum(argv[optind]); if (offset < 0) { printf("non-numeric length argument -- %s\n", argv[optind]); return 0; } optind++; count = cvtnum(argv[optind]); if (count < 0) { printf("non-numeric length argument -- %s\n", argv[optind]); return 0; } if (!Pflag && (lflag || sflag)) { return command_usage(&read_cmd); } if (!lflag) { pattern_count = count - pattern_offset; } if ((pattern_count < 0) || (pattern_count + pattern_offset > count)) { printf("pattern verification range exceeds end of read data\n"); return 0; } if (!pflag) { if (offset & 0x1ff) { printf("offset %" PRId64 " is not sector aligned\n", offset); return 0; } if (count & 0x1ff) { printf("count %d is not sector aligned\n", count); return 0; } } buf = qemu_io_alloc(count, 0xab); gettimeofday(&t1, NULL); if (pflag) { cnt = do_pread(buf, offset, count, &total); } else if (bflag) { cnt = do_load_vmstate(buf, offset, count, &total); } else { cnt = do_read(buf, offset, count, &total); } gettimeofday(&t2, NULL); if (cnt < 0) { printf("read failed: %s\n", strerror(-cnt)); goto out; } if (Pflag) { void *cmp_buf = g_malloc(pattern_count); memset(cmp_buf, pattern, pattern_count); if (memcmp(buf + pattern_offset, cmp_buf, pattern_count)) { printf("Pattern verification failed at offset %" PRId64 ", %d bytes\n", offset + pattern_offset, pattern_count); } g_free(cmp_buf); } if (qflag) { goto out; } if (vflag) { dump_buffer(buf, offset, count); } /* Finally, report back -- -C gives a parsable format */ t2 = tsub(t2, t1); print_report("read", &t2, offset, count, total, cnt, Cflag); out: qemu_io_free(buf); return 0; }
static int multiwrite_f(int argc, char **argv) { struct timeval t1, t2; int Cflag = 0, qflag = 0; int c, cnt; char **buf; int64_t offset, first_offset = 0; int total = 0; int nr_iov; int nr_reqs; int pattern = 0xcd; QEMUIOVector *qiovs; int i; BlockRequest *reqs; while ((c = getopt(argc, argv, "CqP:")) != EOF) { switch (c) { case 'C': Cflag = 1; break; case 'q': qflag = 1; break; case 'P': pattern = parse_pattern(optarg); if (pattern < 0) return 0; break; default: return command_usage(&writev_cmd); } } if (optind > argc - 2) return command_usage(&writev_cmd); nr_reqs = 1; for (i = optind; i < argc; i++) { if (!strcmp(argv[i], ";")) { nr_reqs++; } } reqs = qemu_malloc(nr_reqs * sizeof(*reqs)); buf = qemu_malloc(nr_reqs * sizeof(*buf)); qiovs = qemu_malloc(nr_reqs * sizeof(*qiovs)); for (i = 0; i < nr_reqs; i++) { int j; offset = cvtnum(argv[optind]); if (offset < 0) { printf("non-numeric offset argument -- %s\n", argv[optind]); return 0; } optind++; if (offset & 0x1ff) { printf("offset %lld is not sector aligned\n", (long long)offset); return 0; } if (i == 0) { first_offset = offset; } for (j = optind; j < argc; j++) { if (!strcmp(argv[j], ";")) { break; } } nr_iov = j - optind; reqs[i].qiov = &qiovs[i]; buf[i] = create_iovec(reqs[i].qiov, &argv[optind], nr_iov, pattern); reqs[i].sector = offset >> 9; reqs[i].nb_sectors = reqs[i].qiov->size >> 9; optind = j + 1; offset += reqs[i].qiov->size; pattern++; } gettimeofday(&t1, NULL); cnt = do_aio_multiwrite(reqs, nr_reqs, &total); gettimeofday(&t2, NULL); if (cnt < 0) { printf("aio_multiwrite failed: %s\n", strerror(-cnt)); goto out; } if (qflag) goto out; t2 = tsub(t2, t1); print_report("wrote", &t2, first_offset, total, total, cnt, Cflag); out: for (i = 0; i < nr_reqs; i++) { qemu_io_free(buf[i]); qemu_iovec_destroy(&qiovs[i]); } qemu_free(buf); qemu_free(reqs); qemu_free(qiovs); return 0; }
//MAIN int main(int argc, char **argv) { //mtrace();//to check memory leakage problems //Initialize prev_rusage with 0 values struct rusage usage; int status = 0;//return from wait function int background = FALSE;//flag that indicate if a command is supposed to run on background or not char str[129];//input string char* cmd_args[32]; //vector of strings (arguments for the shell) struct timeval init, end; //checkpoint to measure wall-clock time bgprocessLL bgpLL = init_bgprocessLL();//store the background processes (LL: linked list) while(1) { printf(">");//prompt character //Get input if(fgets(str,129,stdin)==NULL){//EOF or error (to be able to pipe input files) wait4bgprocess(&bgpLL); break; } //parse commands in str to cmd_args (array of string) to be used in exec functions int n_args = args_from_str(str, cmd_args); //check if cmd_args has built-in commands int builtin_effect = treat_builtin_cmds(cmd_args, n_args, &bgpLL); if(builtin_effect==CONTINUE) continue; else if (builtin_effect==BREAK) break; //else: continue normally //Check if the process is supposed to run in background if(strcmp(cmd_args[n_args-1],"&") == 0) { free(cmd_args[n_args-1]);//transparent to the rest cmd_args[n_args-1]=NULL;//necesary condition for exec functions n_args--; background = TRUE; }else background = FALSE; gettimeofday(&init,NULL);//get time right before creating the child pid_t pid = fork(); //create a new process //CHILD if (pid == 0) { if(execvp(cmd_args[0], cmd_args) == -1){ //error with de command perror(NULL);//print error message //free_args(cmd_args);//free memory allocaded in args_from_cmdline function exit(EXIT_FAILURE); } }else if (pid > 0) { //PARENT if(background == FALSE) {//false while(1) { int pid_done = wait3(&status, 0, &usage);//wait for any children gettimeofday(&end, NULL);//get end time if(pid_done!=pid) {//it's not the calling non-background child (a background process has finished) bgprocess bgp = remove_bgprocess(&bgpLL, pid_done);//get the information about it print_bgprocess(bgp, "completed");//show which one has finished print_report(diff_time(bgp.init_time,end), usage, status);//print running status free_bgprocess_name(&bgp);//to avoid memory leak }else {//it's not the calling non-background child (pid_done==pid) print_report(diff_time(init,end), usage, status);//print running status break; } } }else {//It is a background process bgprocess bgp = init_bgprocess(pid, init, cmd_args[0],0,NULL);//bgp null initialization add2bgprocessLL(&bgpLL, bgp);//add the information to the linked list free_bgprocess_name(&bgp);//avoid memory leaks print_bgprocess(*bgpLL.first, "");//print the information about the background process } free_args(cmd_args);//free memory allocaded in args_from_str function }else { //error perror(NULL);//error in fork free_args(cmd_args);//free memory allocaded in args_from_str function exit(EXIT_FAILURE); } //Check for completed background processes and print their status check_background_processes(&bgpLL, WNOHANG); } //free_args(cmd_args);//free memory allocaded in args_from_str function return 0; }
int main(void) { printf("\n==== TML Parser Test Suite ====\n\n"); /* test errors */ test_tml("", NULL, true); test_tml("must-begin-with-a-list", NULL, true); test_tml("[only one root] [node is allowed]", NULL, true); test_tml("only one root node is allowed", NULL, true); test_tml("[forgot to [close | my] bracket", NULL, true); test_tml("a b", NULL, true); test_tml("[", NULL, true); test_tml("[[]", NULL, true); test_tml("]", NULL, true); test_tml("|", NULL, true); test_tml("[|", NULL, true); test_tml("[|[a b]|", NULL, true); test_tml("[a b", NULL, true); /* test string conversion */ test_tml("[]", "", false); test_tml("[test]", "test", false); test_tml("[this [is [a [test]]]]", "this is a test", false); test_tml("[bold | hello [italic | this] is a test]", "bold hello italic this is a test", false); /* test tml code parsing / generation */ test_tml("[]", "[]", true); test_tml("[test]", "[test]", true); test_tml("[|]", "[[] []]", true); test_tml("[a|]", "[[a] []]", true); test_tml("[|a]", "[[] [a]]", true); test_tml("[| |]", "[[] [] []]", true); test_tml("[a b c]", "[a b c]", true); test_tml("[a [] b]", "[a [] b]", true); test_tml("[[[]]]", "[[[]]]", true); test_tml("[a b c | d e f]", "[[a b c] [d e f]]", true); test_tml("[a | b | c | d | e]", "[[a] [b] [c] [d] [e]]", true); test_tml("[bold | hello [italic | this] is a test]", "[[bold] [hello [[italic] [this]] is a test]]", true); test_node_to_string("[this [is [a [test]]]]", "[this [is [a [test]]]]", true); test_node_to_string("[[]]", "[[]]", true); test_node_to_string("[[] []]", "[[] []]", true); test_node_to_string("[[a]]", "[[a]]", true); test_node_to_string("[[a] [b]]", "[[a] [b]]", true); test_node_to_string("[a [b [c] d] e]", "[a [b [c] d] e]", true); test_node_to_string("[this [is [a [test]]]]", "this is a test", false); test_node_to_string("[[]]", "", false); test_node_to_string("[[] []]", "", false); test_node_to_string("[[a]]", "a", false); test_node_to_string("[[a] [b]]", "a b", false); test_node_to_string("[a [b [c] d] e]", "a b c d e", false); /* test pattern matching */ test_pattern_match("[]", "[]", true); test_pattern_match("[|]", "[[][]]", true); test_pattern_match("[a b c]", "[a b c]", true); test_pattern_match("[a [b] c]", "[a [b] c]", true); test_pattern_match("[|]", "[]", false); test_pattern_match("[a b c]", "[a b c d]", false); test_pattern_match("[a b c d]", "[a b c]", false); test_pattern_match("[a b c]", "[c b a]", false); test_pattern_match("[a b c]", "[a b d]", false); test_pattern_match("[c a b]", "[d a b]", false); test_pattern_match("[]", "[\\*]", true); test_pattern_match("[a]", "[\\*]", true); test_pattern_match("[a b c]", "[\\*]", true); test_pattern_match("[[a] [b c]]", "[\\*]", true); test_pattern_match("[]", "[\\? \\*]", false); test_pattern_match("[a b]", "[\\? \\*]", true); test_pattern_match("[a b]", "[\\? \\? \\*]", true); test_pattern_match("[a b c]", "[\\? \\? \\*]", true); test_pattern_match("[a b c]", "[\\? \\*]", true); test_pattern_match("[a b c d]", "[\\? \\*]", true); test_pattern_match("[[]]", "[\\?]", true); test_pattern_match("[this is tml]", "[this is \\?]", true); test_pattern_match("[this is tml]", "[this \\? tml]", true); test_pattern_match("[this is tml]", "[\\? is tml]", true); test_pattern_match("[this is tml]", "[\\? is \\?]", true); test_pattern_match("[test is tml]", "[this is \\?]", false); test_pattern_match("[test is tml]", "[this \\? tml]", false); test_pattern_match("[[a b] [c d] [e f]]", "[[\\? b] [c \\?] [\\? f]]", true); test_pattern_match("[[a b] [c d] [e f]]", "[ \\? \\? | \\? \\? | \\? \\? ]", true); test_pattern_match("[[a b] [c d] [e f]]", "[[\\*] [\\? \\*] [\\? \\? \\*]]", true); test_pattern_match("[bold | hello, this is a test!]", "[bold|\\*]", true); test_pattern_match("[bold | hello, this is a test!]", "[italic|\\*]", false); test_pattern_match("[bold | hello, [italic | this] is a test!]", "[bold|\\*]", true); print_report(); return 0; }
void dvmrp_print(netdissect_options *ndo, register const u_char *bp, register u_int len) { register const u_char *ep; register u_char type; ep = (const u_char *)ndo->ndo_snapend; if (bp >= ep) return; ND_TCHECK(bp[1]); type = bp[1]; /* Skip IGMP header */ bp += 8; len -= 8; switch (type) { case DVMRP_PROBE: ND_PRINT((ndo, " Probe")); if (ndo->ndo_vflag) { if (print_probe(ndo, bp, ep, len) < 0) goto trunc; } break; case DVMRP_REPORT: ND_PRINT((ndo, " Report")); if (ndo->ndo_vflag > 1) { if (print_report(ndo, bp, ep, len) < 0) goto trunc; } break; case DVMRP_ASK_NEIGHBORS: ND_PRINT((ndo, " Ask-neighbors(old)")); break; case DVMRP_NEIGHBORS: ND_PRINT((ndo, " Neighbors(old)")); if (print_neighbors(ndo, bp, ep, len) < 0) goto trunc; break; case DVMRP_ASK_NEIGHBORS2: ND_PRINT((ndo, " Ask-neighbors2")); break; case DVMRP_NEIGHBORS2: ND_PRINT((ndo, " Neighbors2")); /* * extract version and capabilities from IGMP group * address field */ bp -= 4; ND_TCHECK2(bp[0], 4); target_level = (bp[0] << 24) | (bp[1] << 16) | (bp[2] << 8) | bp[3]; bp += 4; if (print_neighbors2(ndo, bp, ep, len) < 0) goto trunc; break; case DVMRP_PRUNE: ND_PRINT((ndo, " Prune")); if (print_prune(ndo, bp) < 0) goto trunc; break; case DVMRP_GRAFT: ND_PRINT((ndo, " Graft")); if (print_graft(ndo, bp) < 0) goto trunc; break; case DVMRP_GRAFT_ACK: ND_PRINT((ndo, " Graft-ACK")); if (print_graft_ack(ndo, bp) < 0) goto trunc; break; default: ND_PRINT((ndo, " [type %d]", type)); break; } return; trunc: ND_PRINT((ndo, "[|dvmrp]")); return; }
int main(int argc, char *argv[]) { int i = 0; struct report_options report = {}; struct pingpong_context ctx; struct ibv_device *ib_dev; struct perftest_parameters user_param; struct pingpong_dest my_dest,rem_dest; struct perftest_comm user_comm; /* init default values to user's parameters */ memset(&ctx,0,sizeof(struct pingpong_context)); memset(&user_param,0,sizeof(struct perftest_parameters)); memset(&user_comm,0,sizeof(struct perftest_comm)); memset(&my_dest,0,sizeof(struct pingpong_dest)); memset(&rem_dest,0,sizeof(struct pingpong_dest)); user_param.verb = READ; user_param.tst = LAT; user_param.r_flag = &report; user_param.version = VERSION; // Configure the parameters values according to user arguments or defalut values. if (parser(&user_param,argv,argc)) { fprintf(stderr," Parser function exited with Error\n"); return FAILURE; } // Finding the IB device selected (or defalut if no selected). ib_dev = ctx_find_dev(user_param.ib_devname); if (!ib_dev) { fprintf(stderr," Unable to find the Infiniband/RoCE deivce\n"); return FAILURE; } // Getting the relevant context from the device ctx.context = ibv_open_device(ib_dev); if (!ctx.context) { fprintf(stderr, " Couldn't get context for the device\n"); return 1; } // See if MTU and link type are valid and supported. if (check_link_and_mtu(ctx.context,&user_param)) { fprintf(stderr, " Couldn't get context for the device\n"); return FAILURE; } // Print basic test information. ctx_print_test_info(&user_param); // copy the rellevant user parameters to the comm struct + creating rdma_cm resources. if (create_comm_struct(&user_comm,&user_param)) { fprintf(stderr," Unable to create RDMA_CM resources\n"); return 1; } // Create (if nessacery) the rdma_cm ids and channel. if (user_param.work_rdma_cm == ON) { if (create_rdma_resources(&ctx,&user_param)) { fprintf(stderr," Unable to create the rdma_resources\n"); return FAILURE; } if (user_param.machine == CLIENT) { if (rdma_client_connect(&ctx,&user_param)) { fprintf(stderr,"Unable to perform rdma_client function\n"); return FAILURE; } } else { if (rdma_server_connect(&ctx,&user_param)) { fprintf(stderr,"Unable to perform rdma_client function\n"); return FAILURE; } } } else { // create all the basic IB resources (data buffer, PD, MR, CQ and events channel) if (ctx_init(&ctx,&user_param)) { fprintf(stderr, " Couldn't create IB resources\n"); return FAILURE; } } // Set up the Connection. if (set_up_connection(&ctx,&user_param,&my_dest)) { fprintf(stderr," Unable to set up socket connection\n"); return 1; } ctx_print_pingpong_data(&my_dest,&user_comm); // Init the connection and print the local data. if (establish_connection(&user_comm)) { fprintf(stderr," Unable to init the socket connection\n"); return 1; } // shaking hands and gather the other side info. if (ctx_hand_shake(&user_comm,&my_dest,&rem_dest)) { fprintf(stderr,"Failed to exchange date between server and clients\n"); return 1; } user_comm.rdma_params->side = REMOTE; ctx_print_pingpong_data(&rem_dest,&user_comm); if (user_param.work_rdma_cm == OFF) { if (pp_connect_ctx(&ctx,my_dest.psn,&rem_dest,my_dest.out_reads,&user_param)) { fprintf(stderr," Unable to Connect the HCA's through the link\n"); return 1; } } // An additional handshake is required after moving qp to RTR. if (ctx_hand_shake(&user_comm,&my_dest,&rem_dest)) { fprintf(stderr,"Failed to exchange date between server and clients\n"); return 1; } ALLOCATE(tstamp,cycles_t,user_param.iters); // Only Client post read request. if (user_param.machine == SERVER) { if (ctx_close_connection(&user_comm,&my_dest,&rem_dest)) { fprintf(stderr,"Failed to close connection between server and client\n"); return 1; } printf(RESULT_LINE); return 0; // destroy_ctx(&ctx,&user_param); } if (user_param.use_event) { if (ibv_req_notify_cq(ctx.send_cq, 0)) { fprintf(stderr, "Couldn't request CQ notification\n"); return 1; } } printf(RESULT_LINE); printf(RESULT_FMT_LAT); if (user_param.all == ON) { for (i = 1; i < 24 ; ++i) { user_param.size = 1 << i; if(run_iter(&ctx,&user_param,&rem_dest)) return 17; print_report(&user_param); } } else { if(run_iter(&ctx,&user_param,&rem_dest)) return 18; print_report(&user_param); } if (ctx_close_connection(&user_comm,&my_dest,&rem_dest)) { fprintf(stderr,"Failed to close connection between server and client\n"); return 1; } printf(RESULT_LINE); return 0; // destroy_ctx(&ctx,&user_param); }
void dvmrp_print(netdissect_options *ndo, const u_char *bp, u_int len) { const u_char *ep; u_char type; uint8_t major_version, minor_version; ndo->ndo_protocol = "dvmrp"; ep = ndo->ndo_snapend; if (bp >= ep) return; ND_TCHECK_1(bp + 1); type = GET_U_1(bp + 1); /* Skip IGMP header */ bp += 8; len -= 8; switch (type) { case DVMRP_PROBE: ND_PRINT(" Probe"); if (ndo->ndo_vflag) { if (print_probe(ndo, bp, ep, len) < 0) goto trunc; } break; case DVMRP_REPORT: ND_PRINT(" Report"); if (ndo->ndo_vflag > 1) { if (print_report(ndo, bp, ep, len) < 0) goto trunc; } break; case DVMRP_ASK_NEIGHBORS: ND_PRINT(" Ask-neighbors(old)"); break; case DVMRP_NEIGHBORS: ND_PRINT(" Neighbors(old)"); if (print_neighbors(ndo, bp, ep, len) < 0) goto trunc; break; case DVMRP_ASK_NEIGHBORS2: ND_PRINT(" Ask-neighbors2"); break; case DVMRP_NEIGHBORS2: ND_PRINT(" Neighbors2"); /* * extract version from IGMP group address field */ bp -= 4; ND_TCHECK_4(bp); major_version = GET_U_1(bp + 3); minor_version = GET_U_1(bp + 2); bp += 4; if (print_neighbors2(ndo, bp, ep, len, major_version, minor_version) < 0) goto trunc; break; case DVMRP_PRUNE: ND_PRINT(" Prune"); if (print_prune(ndo, bp) < 0) goto trunc; break; case DVMRP_GRAFT: ND_PRINT(" Graft"); if (print_graft(ndo, bp) < 0) goto trunc; break; case DVMRP_GRAFT_ACK: ND_PRINT(" Graft-ACK"); if (print_graft_ack(ndo, bp) < 0) goto trunc; break; default: ND_PRINT(" [type %u]", type); break; } return; trunc: nd_print_trunc(ndo); return; }
int main(int argc, char *argv[]) { struct ibv_device *ib_dev; struct pingpong_context ctx; struct pingpong_dest *my_dest,*rem_dest; struct perftest_parameters user_param; struct perftest_comm user_comm; int i = 0; memset(&ctx,0,sizeof(struct pingpong_context)); memset(&user_param, 0, sizeof(struct perftest_parameters)); memset(&user_comm,0,sizeof(struct perftest_comm)); user_param.verb = WRITE; user_param.tst = BW; user_param.spec = PL; user_param.version = VERSION; // Configure the parameters values according to user arguments or defalut values. if (parser(&user_param,argv,argc)) { fprintf(stderr," Parser function exited with Error\n"); return 1; } // Finding the IB device selected (or defalut if no selected). ib_dev = ctx_find_dev(user_param.ib_devname); if (!ib_dev) { fprintf(stderr," Unable to find the Infiniband/RoCE deivce\n"); return 1; } // Getting the relevant context from the device ctx.context = ibv_open_device(ib_dev); if (!ctx.context) { fprintf(stderr, " Couldn't get context for the device\n"); return 1; } // See if MTU and link type are valid and supported. if (check_link_and_mtu(ctx.context,&user_param)) { fprintf(stderr, " Couldn't get context for the device\n"); return FAILURE; } // Print basic test information. ctx_print_test_info(&user_param); ALLOCATE(my_dest , struct pingpong_dest , user_param.num_of_qps); memset(my_dest, 0, sizeof(struct pingpong_dest)*user_param.num_of_qps); ALLOCATE(rem_dest , struct pingpong_dest , user_param.num_of_qps); memset(rem_dest, 0, sizeof(struct pingpong_dest)*user_param.num_of_qps); // copy the rellevant user parameters to the comm struct + creating rdma_cm resources. if (create_comm_struct(&user_comm,&user_param)) { fprintf(stderr," Unable to create RDMA_CM resources\n"); return 1; } // Create (if nessacery) the rdma_cm ids and channel. if (user_param.work_rdma_cm == ON) { if (create_rdma_resources(&ctx,&user_param)) { fprintf(stderr," Unable to create the rdma_resources\n"); return FAILURE; } if (user_param.machine == CLIENT) { if (rdma_client_connect(&ctx,&user_param)) { fprintf(stderr,"Unable to perform rdma_client function\n"); return FAILURE; } } else { if (rdma_server_connect(&ctx,&user_param)) { fprintf(stderr,"Unable to perform rdma_client function\n"); return FAILURE; } } } else { // create all the basic IB resources (data buffer, PD, MR, CQ and events channel) if (ctx_init(&ctx,&user_param)) { fprintf(stderr, " Couldn't create IB resources\n"); return FAILURE; } } // Set up the Connection. if (set_up_connection(&ctx,&user_param,my_dest)) { fprintf(stderr," Unable to set up socket connection\n"); return FAILURE; } // Print this machine QP information for (i=0; i < user_param.num_of_qps; i++) ctx_print_pingpong_data(&my_dest[i],&user_comm); // Init the connection and print the local data. if (establish_connection(&user_comm)) { fprintf(stderr," Unable to init the socket connection\n"); return FAILURE; } // shaking hands and gather the other side info. for (i=0; i < user_param.num_of_qps; i++) { if (ctx_hand_shake(&user_comm,&my_dest[i],&rem_dest[i])) { fprintf(stderr," Failed to exchange date between server and clients\n"); return 1; } // Print remote machine QP information user_comm.rdma_params->side = REMOTE; ctx_print_pingpong_data(&rem_dest[i],&user_comm); if (user_param.work_rdma_cm == OFF) { if (pp_connect_ctx(&ctx,my_dest[i].psn,&rem_dest[i],&user_param,i)) { fprintf(stderr," Unable to Connect the HCA's through the link\n"); return FAILURE; } } // An additional handshake is required after moving qp to RTR. if (ctx_hand_shake(&user_comm,&my_dest[i],&rem_dest[i])) { fprintf(stderr," Failed to exchange date between server and clients\n"); return FAILURE; } } printf(RESULT_LINE); printf(RESULT_FMT); // For half duplex tests, server just waits for client to exit if (user_param.machine == SERVER && !user_param.duplex) { if (ctx_close_connection(&user_comm,&my_dest[0],&rem_dest[0])) { fprintf(stderr,"Failed to close connection between server and client\n"); return 1; } printf(RESULT_LINE); return 0; } ALLOCATE(tposted,cycles_t,user_param.iters*user_param.num_of_qps); ALLOCATE(tcompleted,cycles_t,user_param.iters*user_param.num_of_qps); if (user_param.all == ON) { for (i = 1; i < 24 ; ++i) { user_param.size = 1 << i; if(run_iter(&ctx,&user_param,rem_dest)) return 17; print_report(&user_param); } } else { if(run_iter(&ctx,&user_param,rem_dest)) return 18; print_report(&user_param); } free(tposted); free(tcompleted); // Closing connection. if (ctx_close_connection(&user_comm,&my_dest[0],&rem_dest[0])) { fprintf(stderr,"Failed to close connection between server and client\n"); return 1; } free(my_dest); free(rem_dest); printf(RESULT_LINE); return 0; }
static int writev_f(int argc, char **argv) { struct timeval t1, t2; int Cflag = 0, qflag = 0; int c, cnt; char *buf; int64_t offset; /* Some compilers get confused and warn if this is not initialized. */ int total = 0; int nr_iov; int pattern = 0xcd; QEMUIOVector qiov; while ((c = getopt(argc, argv, "CqP:")) != EOF) { switch (c) { case 'C': Cflag = 1; break; case 'q': qflag = 1; break; case 'P': pattern = parse_pattern(optarg); if (pattern < 0) { return 0; } break; default: return command_usage(&writev_cmd); } } if (optind > argc - 2) { return command_usage(&writev_cmd); } offset = cvtnum(argv[optind]); if (offset < 0) { printf("non-numeric length argument -- %s\n", argv[optind]); return 0; } optind++; if (offset & 0x1ff) { printf("offset %" PRId64 " is not sector aligned\n", offset); return 0; } nr_iov = argc - optind; buf = create_iovec(&qiov, &argv[optind], nr_iov, pattern); if (buf == NULL) { return 0; } gettimeofday(&t1, NULL); cnt = do_aio_writev(&qiov, offset, &total); gettimeofday(&t2, NULL); if (cnt < 0) { printf("writev failed: %s\n", strerror(-cnt)); goto out; } if (qflag) { goto out; } /* Finally, report back -- -C gives a parsable format */ t2 = tsub(t2, t1); print_report("wrote", &t2, offset, qiov.size, total, cnt, Cflag); out: qemu_iovec_destroy(&qiov); qemu_io_free(buf); return 0; }
static int multiwrite_f(int argc, char **argv) { struct timeval t1, t2; int Cflag = 0, qflag = 0; int c, cnt; char **buf; int64_t offset, first_offset = 0; /* Some compilers get confused and warn if this is not initialized. */ int total = 0; int nr_iov; int nr_reqs; int pattern = 0xcd; QEMUIOVector *qiovs; int i; BlockRequest *reqs; while ((c = getopt(argc, argv, "CqP:")) != EOF) { switch (c) { case 'C': Cflag = 1; break; case 'q': qflag = 1; break; case 'P': pattern = parse_pattern(optarg); if (pattern < 0) { return 0; } break; default: return command_usage(&writev_cmd); } } if (optind > argc - 2) { return command_usage(&writev_cmd); } nr_reqs = 1; for (i = optind; i < argc; i++) { if (!strcmp(argv[i], ";")) { nr_reqs++; } } reqs = g_malloc0(nr_reqs * sizeof(*reqs)); buf = g_malloc0(nr_reqs * sizeof(*buf)); qiovs = g_malloc(nr_reqs * sizeof(*qiovs)); for (i = 0; i < nr_reqs && optind < argc; i++) { int j; /* Read the offset of the request */ offset = cvtnum(argv[optind]); if (offset < 0) { printf("non-numeric offset argument -- %s\n", argv[optind]); goto out; } optind++; if (offset & 0x1ff) { printf("offset %lld is not sector aligned\n", (long long)offset); goto out; } if (i == 0) { first_offset = offset; } /* Read lengths for qiov entries */ for (j = optind; j < argc; j++) { if (!strcmp(argv[j], ";")) { break; } } nr_iov = j - optind; /* Build request */ buf[i] = create_iovec(&qiovs[i], &argv[optind], nr_iov, pattern); if (buf[i] == NULL) { goto out; } reqs[i].qiov = &qiovs[i]; reqs[i].sector = offset >> 9; reqs[i].nb_sectors = reqs[i].qiov->size >> 9; optind = j + 1; pattern++; } /* If there were empty requests at the end, ignore them */ nr_reqs = i; gettimeofday(&t1, NULL); cnt = do_aio_multiwrite(reqs, nr_reqs, &total); gettimeofday(&t2, NULL); if (cnt < 0) { printf("aio_multiwrite failed: %s\n", strerror(-cnt)); goto out; } if (qflag) { goto out; } /* Finally, report back -- -C gives a parsable format */ t2 = tsub(t2, t1); print_report("wrote", &t2, first_offset, total, total, cnt, Cflag); out: for (i = 0; i < nr_reqs; i++) { qemu_io_free(buf[i]); if (reqs[i].qiov != NULL) { qemu_iovec_destroy(&qiovs[i]); } } g_free(buf); g_free(reqs); g_free(qiovs); return 0; }
int main(int argc, char **argv) { pid_t cpid; child_t *child; int i, status, event, lclock; char *PEGASUS_HOME; char kickstart[BUFSIZ]; struct user_regs_struct regs; /* check for kickstart in local dir */ sprintf(kickstart, "./kickstart"); if (access(kickstart, X_OK) < 0) { /* check for PEGASUS_HOME env var */ PEGASUS_HOME = getenv("PEGASUS_HOME"); if (PEGASUS_HOME == NULL) { fprintf(stderr, "Please set PEGASUS_HOME\n"); exit(1); } /* check for kickstart in $PEGASUS_HOME/bin */ sprintf(kickstart, "%s/bin/kickstart", PEGASUS_HOME); if (access(kickstart, X_OK) < 0) { fprintf(stderr, "cannot execute kickstart: %s\n", kickstart); exit(1); } } /* Get transformation name if possible */ for (i=0; i<argc; i++) { if (strcmp(argv[i], "-n") == 0) { strcpy(XFORM, argv[i+1]); break; } } /* Fork kickstart */ cpid = fork(); if (cpid < 0) { perror("fork"); exit(1); } else if(cpid == 0) { if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) < 0) { perror("PTRACE_TRACEME"); exit(1); } dup2(1, 2); /* redirect stderr to stdout */ argv[0] = "kickstart"; execv(kickstart, argv); _exit(0); } else { /* initialize logical clock */ lclock = 0; print_header(); while (1) { /* __WALL is needed so that we can wait on threads too */ cpid = waitpid(0, &status, __WALL); /* find the child */ child = find_child(cpid); /* if not found, then it is new, so add it */ if (child == NULL) { child = add_child(cpid); child->tstart = get_time(); child->lstart = lclock++; if (ptrace(PTRACE_SETOPTIONS, cpid, NULL, PTRACE_O_TRACESYSGOOD|PTRACE_O_TRACEEXIT| PTRACE_O_TRACEFORK|PTRACE_O_TRACEVFORK| PTRACE_O_TRACECLONE)) { perror("PTRACE_SETOPTIONS"); exit(1); } } /* child exited */ if (WIFEXITED(status)) { remove_child(cpid); if (no_children()) break; } /* child was stopped */ if (WIFSTOPPED(status)) { /* Because of a special event we wanted to see */ if(WSTOPSIG(status) == SIGTRAP) { event = status >> 16; if (event == PTRACE_EVENT_EXIT) { child->tstop = get_time(); child->lstop = lclock++; /* fill in exe name */ if (read_exeinfo(child) < 0) { perror("read_exeinfo"); exit(1); } /* fill in memory info */ if (read_meminfo(child) < 0) { perror("read_meminfo"); exit(1); } /* fill in stat info */ if (read_statinfo(child) < 0) { perror("read_statinfo"); exit(1); } /* print stats */ print_report(child); } if (ptrace(PTRACE_SYSCALL, cpid, NULL, NULL)) { perror("PTRACE_SYSCALL event"); exit(1); } } /* Because of a system call */ else if(WSTOPSIG(status) == (SIGTRAP|0x80)) { if (ptrace(PTRACE_GETREGS, cpid, NULL, ®s)) { perror("PTRACE_GETREGS"); exit(1); } if (child->insyscall) { child->sc_rval = SC_RVAL(regs); int (*handler)(child_t *c) = syscalls[child->sc_nr].handler; if (handler) handler(child); child->insyscall = 0; } else { child->sc_nr = SC_NR(regs); child->sc_args[0] = SC_ARG0(regs); child->sc_args[1] = SC_ARG1(regs); child->sc_args[2] = SC_ARG2(regs); child->sc_args[3] = SC_ARG3(regs); child->sc_args[4] = SC_ARG4(regs); child->sc_args[5] = SC_ARG5(regs); child->insyscall = 1; } if (ptrace(PTRACE_SYSCALL, cpid, NULL, NULL)) { perror("PTRACE_SYSCALL syscall"); exit(1); } } /* Because it got a signal */ else { /* pass the signal on to the child */ if (ptrace(PTRACE_SYSCALL, cpid, 0, WSTOPSIG(status))) { perror("PTRACE_SYSCALL signal"); exit(1); } } } }