int measure(pid_t pid) { perf_event_desc_t *fds = NULL; int i, ret, num_fds = 0; char fn[32]; if (pfm_initialize() != PFM_SUCCESS) errx(1, "libpfm initialization failed\n"); ret = perf_setup_list_events(options.events, &fds, &num_fds); if (ret || (num_fds == 0)) exit(1); fds[0].fd = -1; for(i=0; i < num_fds; i++) { fds[i].hw.disabled = 0; /* start immediately */ /* request timing information necessary for scaling counts */ fds[i].hw.read_format = PERF_FORMAT_SCALE; fds[i].hw.pinned = !i && options.pinned; fds[i].fd = perf_event_open(&fds[i].hw, pid, -1, (options.group? fds[0].fd : -1), 0); if (fds[i].fd == -1) errx(1, "cannot attach event %s", fds[i].name); } /* * no notification is generated by perf_counters * when the monitored thread exits. Thus we need * to poll /proc/ to detect it has disappeared, * otherwise we have to wait until the end of the * timeout */ sprintf(fn, "/proc/%d/status", pid); while(access(fn, F_OK) == 0 && options.delay) { sleep(1); options.delay--; if (options.print) print_counts(fds, num_fds, 1); } if (options.delay) warn("thread %d terminated before timeout", pid); if (!options.print) print_counts(fds, num_fds, 0); for(i=0; i < num_fds; i++) close(fds[i].fd); free(fds); /* free libpfm resources cleanly */ pfm_terminate(); return 0; }
int convert_vertex (struct surface *srf, struct vertex *vtx) { int k; struct phnvtx *pv; char message[MAXLINE]; if (vtx -> converted) return(1); sprintf (message, "convert vertex %8ld", vtx -> number); informd2(message); pv = allocate_phnvtx (); if (pv == NULL) { print_counts(); set_error1 ("(convert_vertex): memory allocation failure"); return (0); } if (srf -> head_phnvtx == NULL) srf -> head_phnvtx = pv; else srf -> tail_phnvtx -> next = pv; srf -> tail_phnvtx = pv; srf -> n_phnvtx++; vtx -> pvt = pv; pv -> number = srf -> n_phnvtx; for (k = 0; k < 3; k++) pv -> center[k] = vtx -> center[k]; vtx -> converted = 1; return(1); }
void perf_end(const char* kname) { if (!enabled) return; int i, n; prctl(PR_TASK_PERF_EVENTS_DISABLE); static int first_time = 1; if (first_time) { first_time = 0; char name[128]; for (n = 0; n < g_nthreads; n++) { sprintf (name, mxpa_profile_log, n); FILE* fp = fopen(name, "w"); fclose(fp); } } char name[128]; for (n = 0; n < g_nthreads; n++) { sprintf (name, mxpa_profile_log, n); FILE* fp = open_log_file(name); perf_event_desc_t *fds = g_fds[n]; print_counts(fds, num_fds, kname, fp); for (i = 0; i < num_fds; i++) close(fds[i].fd); perf_free_fds(fds, num_fds); g_fds[n] = fds = NULL; fclose(fp); } }
int main() { std::ifstream in{"list2202.txt"}; if (not in) { std::perror("list2202.txt"); } else { std::locale::global(std::locale{""}); initialise_streams(); count_map counts{}; std::string word{}; while (in >> word) { std::string copy(sanitize(word)); if(not copy.empty()) { ++counts[copy]; } } print_counts(counts); } in.close(); }
void caching_device_stats_t::print_stats(std::string prefix) { print_counts(prefix); print_rates(prefix); print_child_stats(prefix); }
/** * Loads a count matrix from file and converts it to log-odds scores */ PSSMSet load_matrices(char *filename, unsigned int min_length, unsigned int max_length, unsigned int alphlen, unsigned int total) { PSSMSet pssmset = (PSSMSet) malloc(sizeof(struct PSSMSet)); unsigned int i, j, k, order, length; FILE *file; PSSM pssm; file = fopen(filename, "r"); fscanf(file, "# %d\n", &i); pssmset->pssms = (PSSM *) malloc(2 * i * sizeof(PSSM)); pssmset->pssm_count = i; fprintf(stderr, "PSSMs: %i\n", i); /* We need two copies of every matrix to speed up annealing */ for (i = 0; i < 2 * pssmset->pssm_count; i+=2) { fscanf(file, "> %d %d\n", &order, &length); pssmset->pssms[i] = initMatrix(order, max_length, alphlen); pssmset->pssms[i]->length = length; pssm = pssmset->pssms[i]; for (j = 0; j < alphlen; j++) for (k = 0; k < length; k++) fscanf(file, "%d", &pssm->counts[alphlen * k + j]); fscanf(file, "\n"); print_counts(pssm); normalize_pssm(pssm, total); print_counts(pssm); } fclose(file); for (i = 0; i < 2 * pssmset->pssm_count; i += 2) { calcAndSetThresholds(pssmset->pssms[i], 0.0); /* To avoid unitialized values */ pssmset->pssms[i]->max_length = max_length; pssmset->pssms[i]->min_length = min_length; pssmset->pssms[i+1] = clone_pssm(pssmset->pssms[i]); pssmset->pssms[i+1]->max_length = max_length; pssmset->pssms[i+1]->min_length = min_length; } return pssmset; }
void caching_device_stats_t::print_stats(std::string prefix) { std::cerr.imbue(std::locale("")); // Add commas, at least for my locale print_counts(prefix); print_rates(prefix); print_child_stats(prefix); std::cerr.imbue(std::locale("C")); // Reset to avoid affecting later prints. }
int main(int argc, char *argv[]) { int ch; setlocale(LC_ALL, ""); while ((ch = getopt(argc, argv, "lwchm")) != -1) switch((char)ch) { case 'l': doline = 1; break; case 'w': doword = 1; break; case 'c': case 'm': dochar = 1; break; case 'h': humanchar = 1; break; case '?': default: (void)fprintf(stderr, "usage: %s [-c | -m] [-hlw] [file ...]\n", __progname); exit(1); } argv += optind; argc -= optind; /* * wc is unusual in that its flags are on by default, so, * if you don't get any arguments, you have to turn them * all on. */ if (!doline && !doword && !dochar) doline = doword = dochar = 1; if (!*argv) { cnt((char *)NULL); } else { int dototal = (argc > 1); do { cnt(*argv); } while(*++argv); if (dototal) print_counts(tlinect, twordct, tcharct, "total"); } exit(rval); }
void crp_train(int iterations, int burnin, int lag) { struct stringpair *sp; int i, j; for (i = 0; i < iterations; i++) { fprintf(stderr,"Alignment iteration: %i\n", i); print_counts(); for (sp = g_stringpairs; sp != NULL; sp = sp->next) { remove_counts(sp->inaligned, sp->outaligned); /* Remove counts before aligning */ fill_trellis(sp->in, sp->out, &cost_crp, MATRIX_MODE_GS); for (j = 0; g_in_result[j] != -1; j++) { sp->inaligned[j] = g_in_result[j]; sp->outaligned[j] = g_out_result[j]; } sp->inaligned[j] = -1; sp->outaligned[j] = -1; add_counts(sp->inaligned, sp->outaligned); /* Add counts back from new alignment */ } if (i > burnin && i % lag == 0) { add_global_counts(); } } }
/*----------------------------------------------------------------------*/ int main(int argc, char **argv) { /* MBIO status variables */ int status = MB_SUCCESS; int error = MB_ERROR_NO_ERROR; /* MBIO read control parameters */ int read_datalist = MB_NO; void *datalist; int look_processed = MB_DATALIST_LOOK_UNSET; double file_weight; mb_path ifile; /* MBIO read values */ int read_data; /* counting variables */ counts filerecs; counts totrecs; /* processing variables */ options opts; mbdefaults mbdflts; /* set default options */ default_options(&opts); /* mb_mem_debug_on(opts.verbose, &error); */ /* get mbsystem default values */ status = mb_defaults(opts.verbose, &(mbdflts.format), &(mbdflts.pings_get), &(mbdflts.lonflip), mbdflts.bounds, mbdflts.btime_i, mbdflts.etime_i, &(mbdflts.speedmin), &(mbdflts.timegap)); if (status == MB_SUCCESS) { parse_options(opts.verbose, argc, argv, &opts, &error); } if (opts.errflg) { fprintf(stderr, "usage: %s\n", usage_message); fprintf(stderr, "\nProgram <%s> Terminated\n", program_name); error = MB_ERROR_BAD_USAGE; exit(error); } /* print starting debug statements */ if (opts.verbose >= 1) { print_mbdefaults(opts.verbose, &opts, &mbdflts, &error); } /* if help desired then print it and exit */ if (opts.help) { fprintf(stderr, "\nProgram %s\n", program_name); fprintf(stderr, "Version %s\n", rcs_id); fprintf(stderr, "MB-system Version %s\n", MB_VERSION); fprintf(stderr, "\nusage: %s\n", usage_message); fprintf(stderr, "\n%s\n", help_message); exit(error); } /* get format if required */ if (opts.format == 0) { mb_get_format(opts.verbose, opts.read_file, NULL, &(opts.format), &error); } /* determine whether to read one file or a list of files */ if (opts.format < 0) { read_datalist = MB_YES; } /* open file list */ if (read_datalist == MB_YES) { if ((status = mb_datalist_open(opts.verbose, &datalist, opts.read_file, look_processed, &error)) != MB_SUCCESS) { char message[MAX_ERROR_STRING]; sprintf(message, "Unable to open data list file: %s\n", opts.read_file); error_exit(opts.verbose, MB_ERROR_OPEN_FAIL, "mb_datalist_open", message); } if ((status = mb_datalist_read(opts.verbose, datalist, ifile, &(opts.format), &file_weight, &error)) == MB_SUCCESS) { read_data = MB_YES; } else { read_data = MB_NO; } } /* else copy single filename to be read */ else { strcpy(ifile, opts.read_file); read_data = MB_YES; } /* reset total record counter */ zero_counts(opts.verbose, &totrecs, &error); /* loop over files to be read */ while (read_data == MB_YES) { /* reset file record counter */ zero_counts(opts.verbose, &filerecs, &error); /* process the output files */ if (status == MB_SUCCESS) { status = process_output(opts.verbose, &mbdflts, &opts, ifile, &filerecs, &error); } /* output counts */ filerecs.files_read++; if (opts.verbose >= 1) { fprintf(stdout, "\nData records read from: %s\n", ifile); print_counts(opts.verbose, &filerecs, &error); } /* add this file's counts to total */ add_counts(opts.verbose, &totrecs, &filerecs, &error); /* figure out whether and what to read next */ if (read_datalist == MB_YES) { if ((status = mb_datalist_read(opts.verbose, datalist, ifile, &(opts.format), &file_weight, &error)) == MB_SUCCESS) { read_data = MB_YES; } else { read_data = MB_NO; } } else { read_data = MB_NO; } } /* end loop over files in list */ /* output counts */ if (opts.verbose >= 1) { fprintf(stdout, "\nTotal data records read:\n"); print_counts(opts.verbose, &totrecs, &error); } if (read_datalist == MB_YES) { mb_datalist_close(opts.verbose, &datalist, &error); } /* check memory */ status = mb_memory_list(opts.verbose, &error); /* mb_mem_debug_off(opts.verbose, &error); */ return (status); } /* main */
void cnt(char *file) { u_char *C; short gotsp; int len; int64_t linect, wordct, charct; struct stat sbuf; int fd; u_char buf[MAXBSIZE]; linect = wordct = charct = 0; if (file) { if ((fd = open(file, O_RDONLY, 0)) < 0) { warn("%s", file); rval = 1; return; } } else { fd = STDIN_FILENO; } if (!doword) { /* * Line counting is split out because it's a lot * faster to get lines than to get words, since * the word count requires some logic. */ if (doline) { while ((len = read(fd, buf, MAXBSIZE)) > 0) { charct += len; for (C = buf; len--; ++C) if (*C == '\n') ++linect; } if (len == -1) { warn("%s", file); rval = 1; } } /* * If all we need is the number of characters and * it's a directory or a regular or linked file, just * stat the puppy. We avoid testing for it not being * a special device in case someone adds a new type * of inode. */ else if (dochar) { mode_t ifmt; if (fstat(fd, &sbuf)) { warn("%s", file); rval = 1; } else { ifmt = sbuf.st_mode & S_IFMT; if (ifmt == S_IFREG || ifmt == S_IFLNK || ifmt == S_IFDIR) { charct = sbuf.st_size; } else { while ((len = read(fd, buf, MAXBSIZE)) > 0) charct += len; if (len == -1) { warn("%s", file); rval = 1; } } } } } else { /* Do it the hard way... */ gotsp = 1; while ((len = read(fd, buf, MAXBSIZE)) > 0) { /* * This loses in the presence of multi-byte characters. * To do it right would require a function to return a * character while knowing how many bytes it consumed. */ charct += len; for (C = buf; len--; ++C) { if (isspace (*C)) { gotsp = 1; if (*C == '\n') ++linect; } else { /* * This line implements the POSIX * spec, i.e. a word is a "maximal * string of characters delimited by * whitespace." Notice nothing was * said about a character being * printing or non-printing. */ if (gotsp) { gotsp = 0; ++wordct; } } } } if (len == -1) { warn("%s", file); rval = 1; } } print_counts(linect, wordct, charct, file); /* * Don't bother checking doline, doword, or dochar -- speeds * up the common case */ tlinect += linect; twordct += wordct; tcharct += charct; if (close(fd) != 0) { warn("%s", file); rval = 1; } }
static int trace_selftest_ops(struct trace_array *tr, int cnt) { int save_ftrace_enabled = ftrace_enabled; struct ftrace_ops *dyn_ops; char *func1_name; char *func2_name; int len1; int len2; int ret = -1; printk(KERN_CONT "PASSED\n"); pr_info("Testing dynamic ftrace ops #%d: ", cnt); ftrace_enabled = 1; reset_counts(); /* Handle PPC64 '.' name */ func1_name = "*" __stringify(DYN_FTRACE_TEST_NAME); func2_name = "*" __stringify(DYN_FTRACE_TEST_NAME2); len1 = strlen(func1_name); len2 = strlen(func2_name); /* * Probe 1 will trace function 1. * Probe 2 will trace function 2. * Probe 3 will trace functions 1 and 2. */ ftrace_set_filter(&test_probe1, func1_name, len1, 1); ftrace_set_filter(&test_probe2, func2_name, len2, 1); ftrace_set_filter(&test_probe3, func1_name, len1, 1); ftrace_set_filter(&test_probe3, func2_name, len2, 0); register_ftrace_function(&test_probe1); register_ftrace_function(&test_probe2); register_ftrace_function(&test_probe3); /* First time we are running with main function */ if (cnt > 1) { ftrace_init_array_ops(tr, trace_selftest_test_global_func); register_ftrace_function(tr->ops); } DYN_FTRACE_TEST_NAME(); print_counts(); if (trace_selftest_test_probe1_cnt != 1) goto out; if (trace_selftest_test_probe2_cnt != 0) goto out; if (trace_selftest_test_probe3_cnt != 1) goto out; if (cnt > 1) { if (trace_selftest_test_global_cnt == 0) goto out; } DYN_FTRACE_TEST_NAME2(); print_counts(); if (trace_selftest_test_probe1_cnt != 1) goto out; if (trace_selftest_test_probe2_cnt != 1) goto out; if (trace_selftest_test_probe3_cnt != 2) goto out; /* Add a dynamic probe */ dyn_ops = kzalloc(sizeof(*dyn_ops), GFP_KERNEL); if (!dyn_ops) { printk("MEMORY ERROR "); goto out; } dyn_ops->func = trace_selftest_test_dyn_func; register_ftrace_function(dyn_ops); trace_selftest_test_global_cnt = 0; DYN_FTRACE_TEST_NAME(); print_counts(); if (trace_selftest_test_probe1_cnt != 2) goto out_free; if (trace_selftest_test_probe2_cnt != 1) goto out_free; if (trace_selftest_test_probe3_cnt != 3) goto out_free; if (cnt > 1) { if (trace_selftest_test_global_cnt == 0) goto out_free; } if (trace_selftest_test_dyn_cnt == 0) goto out_free; DYN_FTRACE_TEST_NAME2(); print_counts(); if (trace_selftest_test_probe1_cnt != 2) goto out_free; if (trace_selftest_test_probe2_cnt != 2) goto out_free; if (trace_selftest_test_probe3_cnt != 4) goto out_free; ret = 0; out_free: unregister_ftrace_function(dyn_ops); kfree(dyn_ops); out: /* Purposely unregister in the same order */ unregister_ftrace_function(&test_probe1); unregister_ftrace_function(&test_probe2); unregister_ftrace_function(&test_probe3); if (cnt > 1) unregister_ftrace_function(tr->ops); ftrace_reset_array_ops(tr); /* Make sure everything is off */ reset_counts(); DYN_FTRACE_TEST_NAME(); DYN_FTRACE_TEST_NAME(); if (trace_selftest_test_probe1_cnt || trace_selftest_test_probe2_cnt || trace_selftest_test_probe3_cnt || trace_selftest_test_global_cnt || trace_selftest_test_dyn_cnt) ret = -1; ftrace_enabled = save_ftrace_enabled; return ret; }
/* prepare piecewise polynomial molecular surface for writing */ int cvt_surface (struct surface *srf, double surface_center[3]) { int result; short *n_edge_per_cycle; long i, j, y, e, cycned, fcynum, fednum; long *first_cycle_number; long *first_edge_number; char message[MAXLINE]; struct edge *edg; struct face *fac; struct cycle *cyc; srf -> n_variety = srf -> n_atom + srf -> n_tori + srf -> n_probe; if (srf -> n_atom >= MAX_ATOM) { sprintf (message,"maximum number of atoms (%d) exceeded: %ld", MAX_ATOM, srf -> n_atom); set_error1 (message); return (0); } /* converting */ cvt_header (srf); if (error()) return(0); srf -> variety_handles = cvt_varieties (srf, surface_center); if (error()) return(0); srf -> vertex_handles = cvt_vertices (srf); if (error()) return(0); srf -> circle_handles = cvt_circles (srf); if (error()) return(0); srf -> arc_handles = cvt_arcs (srf); if (error()) return(0); if (srf -> n_face > 0) { first_cycle_number = allocate_longs (srf -> n_face, 0, FIRST_CYCLE_NUMBER); if (first_cycle_number == NULL) { print_counts(); set_error1 ("read_surface: memory allocation failure"); return (0); } } else { first_cycle_number = NULL; } srf -> face_handles = cvt_faces (srf, first_cycle_number); if (error()) return(0); if (srf -> n_cycle > 0) { n_edge_per_cycle = allocate_shorts (srf -> n_cycle); if (n_edge_per_cycle == NULL) { print_counts(); set_error1 ("read_surface: memory allocation failure"); return (0); } first_edge_number = allocate_longs (srf -> n_cycle, 0, FIRST_EDGE_NUMBER); if (first_edge_number == NULL) { print_counts(); set_error1 ("read_surface: memory allocation failure"); return (0); } } else { n_edge_per_cycle = NULL; first_edge_number = NULL; } srf -> cycle_handles = cvt_cycles (srf, n_edge_per_cycle, first_edge_number); if (error()) return(0); for (i = 0; i < srf -> n_face; i++) { fac = *(srf -> face_handles + i); fcynum = *(first_cycle_number + i); fac -> first_cycle = (fcynum == 0) ? NULL : *(srf -> cycle_handles + fcynum - 1); } srf -> edge_handles = cvt_edges (srf, n_edge_per_cycle); if (error()) return(0); e = 0; for (y = 0; y < srf -> n_cycle; y++) { cyc = *(srf -> cycle_handles + y); fednum = *(first_edge_number + y); cyc -> first_edge = *(srf -> edge_handles + fednum - 1); cycned = *(n_edge_per_cycle + y); for (j = 0; j < cycned; j++, e++) { edg = *(srf -> edge_handles + e); edg -> next = ((j < cycned - 1) ? *(srf -> edge_handles + e + 1) : NULL); } } result = cvt_components (srf); if (result == 0 || error()) return(0); /* free temporary memory */ free_shorts (n_edge_per_cycle); free_longs (first_edge_number, 0, FIRST_EDGE_NUMBER); free_longs (first_cycle_number, 0, FIRST_CYCLE_NUMBER); return (1); }
int convert_triangle (struct surface *srf, struct face *f) { int j, k, n_e, atm, comp, shape; int orn; int arc_orn[3]; long ofn; long arc_number[3]; double radius, circumference; double tri_center[3], tri_normal[3]; char message[MAXLINE]; char shape_string[24]; struct vertex *tri_vtx[3]; struct arc *arc_ptrs[3]; struct arc *a; struct edge *ed; struct cycle *cyc, *fcyc; struct face *fac; struct variety *vty; struct phnvtx *pv; struct phnedg *pe; struct phntri *pt; struct phntri **head_phntri; struct phntri **tail_phntri; for (k = 0; k < 3; k++) tri_normal[k] = 0.0; if (f -> converted) return(1); pt = allocate_phntri (); if (pt == NULL) { print_counts(); set_error1 ("(convert_triangle): memory allocation failure"); print_counts(); return (0); } comp = f -> comp; ofn = f -> ofn; if (ofn <= 0) { sprintf(message, "convert_triangle: ofn = %8ld", ofn); set_error1(message); return(0); } cyc = f -> first_cycle; if (cyc == NULL) { inform("convert_triangle: no cycles"); return (0); } n_e = 0; for (ed = cyc -> first_edge; ed != NULL; ed = ed -> next) { n_e++; } if (n_e > 3) { sprintf (message, "(convert_triangle): face with %d sides", n_e); set_error1 (message); sprintf (message, "ofn = %ld, lfn = %ld", f -> ofn, f -> lfn); set_error2 (message); return (0); } n_e = 0; for (ed = cyc -> first_edge; ed != NULL; ed = ed -> next) { a = ed -> arcptr; if (a == NULL) { set_error1 ("(convert_triangle): null arc"); return (0); } if (n_e > 2) { sprintf (message, "(convert_triangle): face with %d sides", n_e); set_error1 (message); sprintf (message, "ofn = %ld, lfn = %ld", f -> ofn, f -> lfn); set_error2 (message); return (0); } orn = ed -> orn; arc_orn[n_e] = orn; arc_number[n_e] = a -> number; arc_ptrs[n_e] = a; tri_vtx[n_e] = a -> vtx[orn]; if (tri_vtx[n_e] == NULL) { set_error1 ("(convert_triangle): null vertex"); return (0); } n_e++; } fac = *(srf -> face_handles + ofn - 1); if (fac == NULL) { inform("convert_triangle: face_handles array has null face pointer"); return (0); } fcyc = fac -> first_cycle; circumference = circum (fcyc); shape = fac -> shape; vty = fac -> vty; if (vty == NULL) { inform("convert_triangle: variety pointer is null"); return (0); } radius = vty -> radii[0]; get_tri_center (tri_vtx, tri_center, n_e); atm = point_choice (srf, tri_center, vty, shape); if (error()) { inform("convert_triangle: point_choice fails"); return(0); } if (n_e < 3) { sprintf (message, "atom %d triangle has only %d sides, %hd cycles, %hd arcs", atm, n_e, fac -> n_cycle, fac -> n_arc); set_error1 (message); if (shape == CONVEX) strcpy (shape_string, "face shape = convex"); else if (shape == SADDLE) strcpy (shape_string, "face shape = saddle"); else if (shape == CONCAVE) strcpy (shape_string, "face shape = concave"); else if (shape == FLAT) strcpy (shape_string, "face shape = flat"); else if (shape == CYLINDRICAL) strcpy (shape_string, "face shape = cylindrical"); sprintf (message, "%s, omega = %12.6f, circumference = %12.6f", shape_string, fac -> area / (radius * radius), circumference); set_error2 (message); return (0); } if(!get_normal (tri_vtx, tri_normal)) { informd2("warning: degenerate triangle, no normal computed"); } /* store the data in the new structure */ for (j = 0; j < 3; j++) { pt -> axis[j] = tri_normal[j]; pt -> edg[j] = arc_ptrs[j] -> ped; pt -> orns[j] = arc_orn[j]; } pt -> comp = (short) comp; pt -> atm = (short) atm; pt -> shape = (short) shape; /* property of each of three vertices */ for (j = 0; j < 3; j++) { pe = pt -> edg[j]; orn = pt -> orns[j]; pv = pe -> pvt[orn]; pv -> degree++; for (k = 0; k < 3; k++) pv -> outward[k] += tri_normal[k]; } f -> converted = 1; head_phntri = srf -> heads + atm - 1; tail_phntri = srf -> tails + atm - 1; if (*head_phntri == (struct phntri *) NULL) *head_phntri = pt; else (*tail_phntri) -> next = pt; *tail_phntri = pt; srf -> n_phntri++; return(1); }
int parent(char **arg) { perf_event_desc_t *fds = NULL; int status, ret, i, num_fds = 0, grp, group_fd; int ready[2], go[2]; char buf; pid_t pid; // output_file = fopen(file_name, "w"); //if (chroot("/home/pittdvs/cpu2006/benchspec/CPU2006/464.h264ref/run/run_base_ref_amd64-m64-gcc42-nn.0000")) // err(1, "err on chroot()"); if (pfm_initialize() != PFM_SUCCESS) errx(1, "libpfm initialization failed"); for (grp = 0; grp < options.num_groups; grp++) { int ret; ret = perf_setup_list_events(options.events[grp], &fds, &num_fds); if (ret || !num_fds) exit(1); } pid = options.pid; if (!pid) { ret = pipe(ready); if (ret) err(1, "cannot create pipe ready"); ret = pipe(go); if (ret) err(1, "cannot create pipe go"); /* * Create the child task */ if ((pid=fork()) == -1) err(1, "Cannot fork process"); /* * and launch the child code * * The pipe is used to avoid a race condition * between for() and exec(). We need the pid * of the new tak but we want to start measuring * at the first user level instruction. Thus we * need to prevent exec until we have attached * the events. */ if (pid == 0) { close(ready[0]); close(go[1]); /* * let the parent know we exist */ close(ready[1]); if (read(go[0], &buf, 1) == -1) err(1, "unable to read go_pipe"); exit(child(arg)); } close(ready[1]); close(go[0]); if (read(ready[0], &buf, 1) == -1) err(1, "unable to read child_ready_pipe"); close(ready[0]); } for(i=0; i < num_fds; i++) { int is_group_leader; /* boolean */ is_group_leader = perf_is_group_leader(fds, i); if (is_group_leader) { /* this is the group leader */ group_fd = -1; } else { group_fd = fds[fds[i].group_leader].fd; } /* * create leader disabled with enable_on-exec */ if (!options.pid) { fds[i].hw.disabled = is_group_leader; fds[i].hw.enable_on_exec = is_group_leader; } fds[i].hw.read_format = PERF_FORMAT_SCALE; /* request timing information necessary for scaling counts */ if (is_group_leader && options.format_group) fds[i].hw.read_format |= PERF_FORMAT_GROUP; if (options.inherit) fds[i].hw.inherit = 1; if (options.pin && is_group_leader) fds[i].hw.pinned = 1; fds[i].fd = perf_event_open(&fds[i].hw, pid, -1, group_fd, 0); if (fds[i].fd == -1) { warn("cannot attach event%d %s", i, fds[i].name); goto error; } } if (!options.pid) close(go[1]); if (options.print) { if (!options.pid) { while(waitpid(pid, &status, WNOHANG) == 0 && quit == 0) { //sleep(1); //usleep(10000); msleep(100); //better_sleep(0.05); // 50ms print_counts(fds, num_fds); } } else { while(quit == 0) { sleep(1); print_counts(fds, num_fds); } } } else { if (!options.pid) waitpid(pid, &status, 0); else pause(); print_counts(fds, num_fds); } for(i=0; i < num_fds; i++) close(fds[i].fd); free(fds); /* free libpfm resources cleanly */ pfm_terminate(); // fclose(output_file); return 0; error: free(fds); if (!options.pid) kill(SIGKILL, pid); /* free libpfm resources cleanly */ pfm_terminate(); // fclose(output_file); return -1; }
int main (int argc, char **argv) { heapelement_t **CDheap=NULL; hashelement_t **CDhash=NULL; phnhashelement_t **CIhash=NULL; dicthashelement_t **dicthash=NULL; int32 cilistsize=0, cdheapsize=0, threshold, tph_list_given, ncd; char *phnlist, *incimdef, *triphnlist, *incdmdef; char *lsnfile, *dictfn, *fillerdictfn, **CIlist=NULL; char *cimdeffn, *alltphnmdeffn, *untiedmdeffn, *countfn; parse_cmd_ln(argc,argv); /* Test all flags before beginning */ cimdeffn = (char *)cmd_ln_access("-ocimdef"); alltphnmdeffn = (char *)cmd_ln_access("-oalltphnmdef"); untiedmdeffn = (char *)cmd_ln_access("-ountiedmdef"); countfn = (char *)cmd_ln_access("-ocountfn"); if (cimdeffn) E_INFO("Will write CI mdef file %s\n",cimdeffn); if (alltphnmdeffn) E_INFO("Will write alltriphone mdef file %s\n",alltphnmdeffn); if (untiedmdeffn) E_INFO("Will write untied mdef file %s\n",untiedmdeffn); if (countfn) E_INFO("Will write triphone counts file %s\n",countfn); if (!cimdeffn && !alltphnmdeffn && !untiedmdeffn && !countfn) E_FATAL("No output mdef files or count files specified!\n"); dictfn = (char *)cmd_ln_access("-dictfn"); fillerdictfn = (char *)cmd_ln_access("-fdictfn"); lsnfile = (char*)cmd_ln_access("-lsnfn"); if ((untiedmdeffn || countfn) && (!lsnfile || !dictfn)) { E_WARN("Either dictionary or transcript file not given!\n"); if (untiedmdeffn) E_WARN("Untied mdef will not be made\n"); if (countfn) E_WARN("Phone counts will not be generated\n"); untiedmdeffn = countfn = NULL; } phnlist = (char *)cmd_ln_access("-phnlstfn"); triphnlist = (char *)cmd_ln_access("-triphnlstfn"); incimdef = (char *)cmd_ln_access("-inCImdef"); incdmdef = (char *)cmd_ln_access("-inCDmdef"); if (!incdmdef && !incimdef && !phnlist && !triphnlist) E_FATAL("No input mdefs or phone list given\n"); if (triphnlist) { if (phnlist) E_WARN("Both -triphnlist %s and -phnlist given.\n",triphnlist); E_WARN("Ignoring -phnlist %s\n",phnlist); phnlist = triphnlist; } tph_list_given = (triphnlist || incdmdef) ? 1 : 0; if (incdmdef) { if (incimdef || phnlist){ E_WARN("Using only input CD mdef %s!\n",incdmdef); E_WARN("Using only triphones from input CD mdef %s!\n",incdmdef); if (incimdef) E_WARN("CImdef %s will be ignored\n",incimdef); if (phnlist) E_WARN("phonelist %s will be ignored\n",phnlist); incimdef = phnlist = NULL; } make_ci_list_cd_hash_frm_mdef(incdmdef,&CIlist,&cilistsize, &CDhash,&ncd); } else{ if (phnlist) make_ci_list_cd_hash_frm_phnlist(phnlist,&CIlist, &cilistsize,&CDhash,&ncd); if (incimdef) { if (CIlist) ckd_free_2d((void**)CIlist); make_ci_list_frm_mdef(incimdef,&CIlist,&cilistsize); } } if (cimdeffn) make_mdef_from_list(cimdeffn,CIlist,cilistsize,NULL,0,argv[0]); if (!tph_list_given && !cimdeffn) { read_dict(dictfn, fillerdictfn, &dicthash); if (CDhash) freehash(CDhash); make_dict_triphone_list (dicthash, &CDhash); } if (alltphnmdeffn){ threshold = -1; make_CD_heap(CDhash,threshold,&CDheap,&cdheapsize); make_mdef_from_list(alltphnmdeffn,CIlist,cilistsize, CDheap,cdheapsize,argv[0]); } if (countfn || untiedmdeffn) count_triphones(lsnfile, dicthash, CDhash, &CIhash); if (countfn){ print_counts(countfn,CIhash,CDhash); } if (untiedmdeffn){ threshold = find_threshold(CDhash); make_CD_heap(CDhash,threshold,&CDheap,&cdheapsize); make_mdef_from_list(untiedmdeffn,CIlist,cilistsize, CDheap,cdheapsize,argv[0]); } return 0; }
static void gc_finish_event(void) { print_counts(); jvmpi->RawMonitorExit(lock); }
int main(int argc, char * argv[]) { #ifdef DEBUG open_debug(); #endif init_static_control_simple(); void ask(addr_t addr) { char str[DEFAULT_TRANSFER]; struct args args = { .log_addr = addr, .log_len = DEFAULT_TRANSFER, .phys_addr = (unsigned long)str, .direction = direct_read }; root_strategy->ops[0][opcode_trans]((void*)root_strategy, &args, ""); if(args.success) { printf("%s", str); } } bool cmd(addr_t addr, char * str, char * param) { struct args args = { .log_addr = addr, .log_len = strlen(str), .phys_addr = (unsigned long)str, .direction = direct_write }; root_strategy->ops[0][opcode_trans]((void*)root_strategy, &args, param); return args.success; } addr_t boot(char * str, char * param) { struct args args = { .log_len = DEFAULT_TRANSFER, .reader = FALSE, .exclu = TRUE, .action = action_wait, .melt = TRUE, .try_len = DEFAULT_TRANSFER, .op_code = opcode_gadr }; root_strategy->ops[0][opcode_gadr]((void*)root_strategy, &args, param); if(!args.success) { printf("!!!!! gadrcreateget failed\n"); exit(-1); } args.log_len = strlen(str); args.phys_addr = (unsigned long)str; args.direction = direct_write; args.op_code = opcode_trans; root_strategy->ops[0][opcode_trans]((void*)root_strategy, &args, param); if(!args.success) { printf("!!!!! trans '%s' failed\n", str); exit(-1); } return args.log_addr; } char str[256]; addr_t control = DEFAULT_TRANSFER; cmd(control, "output:=control\n", ""); // basic level #if 0 addr_t dev = boot("brick:=device_dummy_linux\n output:=out", "testfile"); sprintf(str, "brick:=buffer_dummy_linux\n \n connect dev:=%llx:out\n output:=out {\n", dev); addr_t buffer = boot(str, ""); sprintf(str, "brick:=map_simple\n connect in:=%llx:out\noutput:=out", buffer); #else sprintf(str, "brick:=map_dummy\n output:=out{\n"); #endif addr_t map = boot(str, ""); sprintf(str, "brick:=adapt_meta\n connect in:=%llx:out\n output:=out\n", map); addr_t meta = boot(str, ""); #if 0 sprintf(str, "brick:=spy_trace\n connect in:=%llx:out\n output:=out\n", meta); meta = boot(str, "spylog"); #endif // create root hook cmd(0, "output:=_root", ""); cmd(meta, "connect hook:=0:_root", ""); // strategy level sprintf(str, "brick:=fs_simple\n connect strat:=%llx:control\n output:=control{\n", control); addr_t fs = boot(str, "_root"); // testing sprintf(str, "brick:=bench_fs\n connect strat:=%llx:control\n", fs); addr_t bench = boot(str, ""); #if 1 ask(0); ask(DEFAULT_TRANSFER); ask(0x3000); #endif printf("================== STARTING BENCH ================\n"); cmd(bench, "output:=dummy", "1000"); printf("================== END BENCH ================\n"); #ifdef MOVE_COUNT extern void print_counts(void); print_counts(); printf("------------------------------------\n"); printf("_makespace: shortcuts: %d count1: %d count2: %d\n", count_0, count_1, count_2); printf("creates (count_c1) = %d, triggering creates (count_c2) = %d\n", count_c1, count_c2); #endif cmd(meta, "brick/=adapt_meta", ""); cmd(map, "brick/=map_dummy", ""); #ifdef DEBUG close_debug(); #endif return 0; }
void process_trace(Trace* itrace, Trace* otrace, void* itr_buf, void* otr_buf) { int i, ntr, buffer_instrs; itrace->set_tr(itr_buf); if (otrace != NULL) { otrace->set_tr(otr_buf); } if (gbl.skipRecs) { if (0 && (gbl.infp != stdin)) { off_t offset; off_t filesize; fseeko(gbl.infp, 0, SEEK_END); filesize = ftello(gbl.infp); offset = gbl.skipRecs * gbl.fromsize; if (offset < filesize) { fseeko(gbl.infp, offset, SEEK_SET); } else { fprintf(stderr, "Fewer than %lld records in file '%s' (%lld).\n", gbl.skipRecs, gbl.infile, filesize / gbl.fromsize); exit(2); } } else { master_64bit_trace_t *buf; buf = (master_64bit_trace_t*) malloc(BUFFER_SIZE * sizeof(master_64bit_trace_t)); for (i = 0; i < gbl.skipRecs / BUFFER_SIZE; i++) { if (fread(buf, gbl.fromsize, BUFFER_SIZE, gbl.infp) < BUFFER_SIZE) { fprintf(stderr, "Fewer than %lld records in file '%s'.\n", gbl.skipRecs, gbl.infile); exit(2); if (gbl.fromtype == RST) { rstf_unionT * ru = (rstf_unionT *) buf; if (ru->proto.rtype == RSTHEADER_T) { if (ru->header.majorVer*1000+ru->header.minorVer <= 2011) { gbl.rstf_pre212 = true; } } // if rstheader } // if fromtype==rst } // if not end-of-file } // for skip recs if (fread(buf, gbl.fromsize, (uint32_t)(gbl.skipRecs % BUFFER_SIZE), gbl.infp) < gbl.skipRecs % BUFFER_SIZE) { fprintf(stderr, "Fewer than %lld records in file '%s'.\n", gbl.skipRecs, gbl.infile); exit(2); } free(buf); } } else if (gbl.skipInstrs) { // if from type is rst, first record must be rstheader while ((ntr = fread(itr_buf, gbl.fromsize, BUFFER_SIZE, gbl.infp))) { if (gbl.fromtype == RST) { rstf_unionT * ru = (rstf_unionT *) itr_buf; if (ru->proto.rtype == RSTHEADER_T) { if (ru->header.majorVer*1000+ru->header.minorVer <= 2011) { gbl.rstf_pre212 = true; } } } for (i = 0; gbl.icount < gbl.skipInstrs && i < ntr; i++) { itrace->count(); // -patchcleanrst done here itrace->inc_tr(); } if (gbl.icount == gbl.skipInstrs) { break; } itrace->reset_tr(); } buffer_instrs = process_buffer(itrace, otrace, itr_buf, otr_buf, i, ntr); if (gbl.verify) { itrace->verify(); } itrace->reset_tr(); gbl.skipInstrsRecs = gbl.rcount; gbl.rcount = 0; gbl.icount = 0; } while (gbl.rcount < gbl.maxRecs && gbl.icount < gbl.maxInstrs && (ntr = fread(itr_buf, gbl.fromsize, BUFFER_SIZE, gbl.infp))) { buffer_instrs = process_buffer(itrace, otrace, itr_buf, otr_buf, 0, ntr); if (gbl.verify) { itrace->verify(); } itrace->reset_tr(); } // any leftover instrs to fwrite...? if (buffer_instrs) { fwrite(otr_buf, gbl.tosize, buffer_instrs, gbl.outfp); } if (gbl.verbose || gbl.countOnly) { print_counts(gbl.msgfp); } }
int convert_edge (struct surface *srf, struct arc *a) { long ofn; int comp, atm, shape; double di_center[3]; char message[MAXLINE]; struct vertex *vtx0, *vtx1; struct variety *vty; struct face *fac; struct phnedg *pe; if (a -> converted) return(1); pe = allocate_phnedg (); if (pe == NULL) { print_counts(); set_error1 ("(convert_edge): memory allocation failure"); return (0); } if (srf -> head_phnedg == (struct phnedg *) NULL) srf -> head_phnedg = pe; else srf -> tail_phnedg -> next = pe; srf -> tail_phnedg = pe; srf -> n_phnedg++; a -> ped = pe; pe -> number = srf -> n_phnedg; vtx0 = a -> vtx[0]; vtx1 = a -> vtx[1]; if (vtx0 == NULL || vtx1 == NULL) { sprintf (message, "(convert_edge) null vertex"); set_error1 (message); return (0); } if (!vtx0 -> converted) { sprintf (message, "(convert_edge) vertex not converted %8ld", vtx0 -> number); set_error1 (message); sprintf (message, "center: %8.3f %8.3f %8.3f; cusp: %d", vtx0 -> center[0], vtx0 -> center[1], vtx0 -> center[2], vtx0 -> cusp); set_error2 (message); return (0); } if (!vtx1 -> converted) { sprintf (message, "(convert_edge) vertex not converted %8ld", vtx1 -> number); set_error1 (message); sprintf (message, "center: %8.3f %8.3f %8.3f; cusp: %d", vtx1 -> center[0], vtx1 -> center[1], vtx1 -> center[2], vtx1 -> cusp); set_error2 (message); return (0); } if (vtx0 -> pvt == NULL) { sprintf (message, "(convert_edge) null vertex --> phnvtx %8ld", vtx0 -> number); set_error1 (message); return (0); } if (vtx1 -> pvt == NULL) { sprintf (message, "(convert_edge) null vertex --> phnvtx %8ld", vtx1 -> number); set_error1 (message); return (0); } get_di_center (a -> vtx, di_center); ofn = a -> ofn; if (ofn <= 0) { sprintf(message, "convert_edge: ofn = %8ld", ofn); set_error1(message); return(0); } fac = *(srf -> face_handles + ofn - 1); shape = fac -> shape; vty = fac -> vty; atm = point_choice (srf, di_center, vty, shape); if (error()) return(0); comp = fac -> comp; pe -> pvt[0] = vtx0 -> pvt; pe -> pvt[1] = vtx1 -> pvt; pe -> comp = (short) comp; pe -> atm = (short) atm; atm = point_choice (srf, vtx0 -> center, vty, shape); if (error()) return(0); vtx0 -> pvt -> comp = (short) comp; vtx0 -> pvt -> atm = (short) atm; atm = point_choice (srf, vtx1 -> center, vty, shape); if (error()) return(0); vtx1 -> pvt -> comp = (short) comp; vtx1 -> pvt -> atm = (short) atm; a -> converted = 1; return (1); }
int main(int argc, char *argv[]) { int floatingPoint = 0; int integer = 0; int trials = 0; int arrLength = 0; int range = 0; char* endptr; struct timespec start, stop; int opt; while ((opt = getopt( argc, argv, "fin:a:r:")) != -1) { switch (opt) { case 'f': floatingPoint = 1; break; case 'i': integer = 1; break; case 'n': trials = strtol( optarg, &endptr, 10); break; case 'a': arrLength = strtol( optarg, &endptr, 10); break; case 'r': range = strtol( optarg, &endptr, 10); break; case '?': display_usage(); break; } } // printf( "float: %u, int: %u, trials: %u, array length: %u\n", floatingPoint, integer, trials, arrLength); int k = 0; int i = 0; if( integer == 1) { int a[arrLength]; int b[arrLength]; int c[arrLength]; srand(time(0)); for( i = 0; i < arrLength; i++) { a[i] = rand() % range; b[i] = rand() % range; } //"Warm-up" to remove initial memory-acces overhead intAdd( a, b, c, arrLength); //clock_gettime(CLOCK_REALTIME, &start); start_counting(ARMV6_EVENT_INSTR_EXEC, ARMV6_EVENT_CPU_CYCLES) ; //start_counting(ARMV6_EVENT_DTLB_MISS, ARMV6_EVENT_MAIN_TLB_MISS) ; //start_counting(ARMV6_EVENT_DCACHE_CACCESS, ARMV6_EVENT_DCACHE_MISS) ; for( k = trials; k > 0; k--) { intAdd( a, b, c, arrLength); } stop_counting() ; if (create_result_file("output.dat") == 0) { printf ("Error cannot create file"); exit( EXIT_FAILURE ) ; } fprintf(result_file,"Performance Monitor events\n") ; print_counts(result_file) ; //clock_gettime(CLOCK_REALTIME, &stop); double diff = ( stop.tv_sec - start.tv_sec ) + ( stop.tv_nsec - start.tv_nsec ) / 1E9; printf( "%u, %u, %lf\n", trials, arrLength, diff); }else if ( floatingPoint == 1) { double a[arrLength]; double b[arrLength]; double c[arrLength]; srand(time(0)); for( i = 0; i < arrLength; i++) { a[i] = (double)rand() / (double)(RAND_MAX/range); b[i] = (double)rand() / (double)(RAND_MAX/range); } /*"Warm-up" to remove initial memory-acces overhead fpAdd( a, b, c, arrLength); clock_gettime(CLOCK_REALTIME, &start); for( k = trials; k > 0; k--) { fpAdd( a, b, c, arrLength); } clock_gettime(CLOCK_REALTIME, &stop); */ double diff = ( stop.tv_sec - start.tv_sec ) + ( stop.tv_nsec - start.tv_nsec ) / 1E9; printf( "%u, %u, %lf\n", trials, arrLength, diff); } return 0; }
static int trace_selftest_ops(int cnt) { int save_ftrace_enabled = ftrace_enabled; struct ftrace_ops *dyn_ops; char *func1_name; char *func2_name; int len1; int len2; int ret = -1; printk(KERN_CONT "PASSED\n"); pr_info("Testing dynamic ftrace ops #%d: ", cnt); ftrace_enabled = 1; reset_counts(); /* */ func1_name = "*" __stringify(DYN_FTRACE_TEST_NAME); func2_name = "*" __stringify(DYN_FTRACE_TEST_NAME2); len1 = strlen(func1_name); len2 = strlen(func2_name); /* */ ftrace_set_filter(&test_probe1, func1_name, len1, 1); ftrace_set_filter(&test_probe2, func2_name, len2, 1); ftrace_set_filter(&test_probe3, func1_name, len1, 1); ftrace_set_filter(&test_probe3, func2_name, len2, 0); register_ftrace_function(&test_probe1); register_ftrace_function(&test_probe2); register_ftrace_function(&test_probe3); register_ftrace_function(&test_global); DYN_FTRACE_TEST_NAME(); print_counts(); if (trace_selftest_test_probe1_cnt != 1) goto out; if (trace_selftest_test_probe2_cnt != 0) goto out; if (trace_selftest_test_probe3_cnt != 1) goto out; if (trace_selftest_test_global_cnt == 0) goto out; DYN_FTRACE_TEST_NAME2(); print_counts(); if (trace_selftest_test_probe1_cnt != 1) goto out; if (trace_selftest_test_probe2_cnt != 1) goto out; if (trace_selftest_test_probe3_cnt != 2) goto out; /* */ dyn_ops = kzalloc(sizeof(*dyn_ops), GFP_KERNEL); if (!dyn_ops) { printk("MEMORY ERROR "); goto out; } dyn_ops->func = trace_selftest_test_dyn_func; register_ftrace_function(dyn_ops); trace_selftest_test_global_cnt = 0; DYN_FTRACE_TEST_NAME(); print_counts(); if (trace_selftest_test_probe1_cnt != 2) goto out_free; if (trace_selftest_test_probe2_cnt != 1) goto out_free; if (trace_selftest_test_probe3_cnt != 3) goto out_free; if (trace_selftest_test_global_cnt == 0) goto out; if (trace_selftest_test_dyn_cnt == 0) goto out_free; DYN_FTRACE_TEST_NAME2(); print_counts(); if (trace_selftest_test_probe1_cnt != 2) goto out_free; if (trace_selftest_test_probe2_cnt != 2) goto out_free; if (trace_selftest_test_probe3_cnt != 4) goto out_free; ret = 0; out_free: unregister_ftrace_function(dyn_ops); kfree(dyn_ops); out: /* */ unregister_ftrace_function(&test_probe1); unregister_ftrace_function(&test_probe2); unregister_ftrace_function(&test_probe3); unregister_ftrace_function(&test_global); /* */ reset_counts(); DYN_FTRACE_TEST_NAME(); DYN_FTRACE_TEST_NAME(); if (trace_selftest_test_probe1_cnt || trace_selftest_test_probe2_cnt || trace_selftest_test_probe3_cnt || trace_selftest_test_global_cnt || trace_selftest_test_dyn_cnt) ret = -1; ftrace_enabled = save_ftrace_enabled; return ret; }