int main(int argc, char** argv) { Opts options; int out_start = argc; Input in = { 0, -1, 0 }; Output *outputs = malloc((argc - 1) * sizeof(Output)); int *regular = malloc((argc - 1) * sizeof(int)); int *pipes = malloc((argc - 1) * sizeof(int)); SpillControl spillage = { NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0 }; /* Spillage info. */ int nregular = 0, npipes = 0; struct sigaction sig; if (NULL == outputs || NULL == regular || NULL == pipes) { perror("malloc"); return EXIT_FAILURE; } /* Ignore SIGPIPEs, we want write(2) to get EPIPE instead. */ sig.sa_handler = SIG_IGN; if (0 != sigaction(SIGPIPE, &sig, NULL)) { perror("sigaction"); return EXIT_FAILURE; } if (0 != get_options(argc, argv, &options, &out_start)) { return EXIT_FAILURE; } if (verbosity > 0) { fprintf(stderr, "%.3f Started.\n", get_time()); } if (0 != open_input(&options, &in, &spillage)) { return EXIT_FAILURE; } if (out_start >= argc) { fprintf(stderr, "No output files specified\n"); return EXIT_FAILURE; } /* Open the output files */ if (open_outputs(argc - out_start, argv + out_start, outputs, regular, pipes, &nregular, &npipes) != 0) { return EXIT_FAILURE; } /* Copy input to all outputs */ if (do_copy(&options, &in, argc - out_start, outputs, nregular, regular, npipes, pipes, &spillage) != 0) { return EXIT_FAILURE; } if (verbosity > 0) { fprintf(stderr, "%.3f Finished.\n", get_time()); } return EXIT_SUCCESS; }
int spe_record__record(struct spe_record__conf *conf) { signal(SIGCHLD, spe_record__handler); print_spe_record__conf(conf); spe__prepare_workload(conf->wl_args); /* * Set affinity masks */ check_return(sched_setaffinity(0, sizeof(cpu_set_t), &conf->record_aff_mask), "Failed to set record process affinity mask, Error: %d\n", errno); check_return(sched_setaffinity(wl_state.pid, sizeof(cpu_set_t), &conf->load_aff_mask), "Failed to set load process affinity mask, Error: %d\n", errno); sc_init(conf, pe_handler); check_return(initialize_groups(&g_groups, conf, wl_state.pid), "Error initializing groups.\n"); check_return(open_outputs(&g_groups, conf->output_preffix), "Error opening outputs.\n"); check_return(open_pe_group(&g_groups), "Error opening groups.\n"); printf("Ready to go.\n"); check_return(start_pe_group(&g_groups), "Error starting groups.\n"); check_return(spe__start_workload(), "Error start_workload.\n"); int awaken = 0, bytes_curr = 0; int bytes_written = 0; //TODO: How to improve efficiency of polling? int nr_signal_to_wait = 20; int i; while (wl_state.wait_child) { for (i = 0; wl_state.wait_child && i < nr_signal_to_wait; ++i) pause(); ++awaken; bytes_curr = perf_mmap_read_all(&g_groups); if (bytes_curr < 0) { REPORTERROR("Error reading mmap.\n"); } else { bytes_written += bytes_curr; } } perf_mmap_read_all(&g_groups); check_return(stop_pe_group(&g_groups), "Error stopping groups.\n"); printf("End. Written %d bytes. Awaken %d times\n", bytes_written, awaken); check_return(stop_pe_group(&g_groups), "Error stopping groups\n"); check_return(print_summaries(&g_groups, conf->output_preffix), "Error printing outputs.\n"); check_return(close_outputs(&g_groups), "Error closing outputs.\n"); check_return(close_pe_group(&g_groups), "Error closing groups\n"); return 0; }