static unsigned long long events;
static int max_cpus;
-static int nfiles;
static char *dev, *output_name;
break;
default:
fprintf(stderr, "Bad fs action %x\n", t->action);
- return;
+ break;
}
}
} while ((n = rb_next(n)) != NULL);
}
+static int read_data(int fd, void *buffer, int bytes, int block)
+{
+ int ret, bytes_left, fl;
+ void *p;
+
+ fl = fcntl(fd, F_GETFL);
+
+ if (!block)
+ fcntl(fd, F_SETFL, fl | O_NONBLOCK);
+ else
+ fcntl(fd, F_SETFL, fl & ~O_NONBLOCK);
+
+ bytes_left = bytes;
+ p = buffer;
+ while (bytes_left > 0) {
+ ret = read(fd, p, bytes_left);
+ if (!ret)
+ return 1;
+ else if (ret < 0) {
+ if (errno != EAGAIN)
+ perror("read");
+ return -1;
+ } else {
+ p += ret;
+ bytes_left -= ret;
+ }
+ }
+
+ return 0;
+}
+
static int do_file(void)
{
- int i, ret;
+ int i, ret, nfiles;
- for (max_cpus = 0, i = 0; i < MAX_CPUS; i++, nfiles++, max_cpus++) {
+ nfiles = 0;
+ max_cpus = 0;
+ for (i = 0; i < MAX_CPUS; i++, nfiles++, max_cpus++) {
struct per_cpu_info *pci = &per_cpu_info[i];
struct stat st;
void *tb;
break;
}
- if (read(pci->fd, tb, st.st_size) != st.st_size) {
- fprintf(stderr, "error reading\n");
+ if (read_data(pci->fd, tb, st.st_size, 1))
break;
- }
ret = sort_entries(tb, st.st_size, ~0U);
if (ret == -1)
return 0;
}
-static int read_data(int fd, void *buffer, int bytes, int block)
-{
- int ret, bytes_left, fl;
- void *p;
-
- fl = fcntl(fd, F_GETFL);
-
- if (!block)
- fcntl(fd, F_SETFL, fl | O_NONBLOCK);
- else
- fcntl(fd, F_SETFL, fl & ~O_NONBLOCK);
-
- bytes_left = bytes;
- p = buffer;
- while (bytes_left > 0) {
- ret = read(fd, p, bytes_left);
- if (!ret)
- return 1;
- else if (ret < 0) {
- if (errno != EAGAIN)
- perror("read");
- return -1;
- } else {
- p += ret;
- bytes_left -= ret;
- }
- }
-
- return 0;
-}
-
static void resize_buffer(void **buffer, long *old_size)
{
long cur_size = *old_size;
int fd;
void *ptr;
- fd = dup(0);
+ fd = dup(STDIN_FILENO);
do {
int events;
return 0;
}
-void flush_output(void)
+static void flush_output(void)
{
int i;
}
}
-void handle_sigint(int sig)
+static void handle_sigint(int sig)
{
done = 1;
flush_output();
}
+static void usage(char *prog)
+{
+ fprintf(stderr, "Usage: %s -i <name> [-o <output>]\n", prog);
+}
+
int main(int argc, char *argv[])
{
int c, ret;
output_name = strdup(optarg);
break;
default:
- fprintf(stderr, "Usage: %s -i <dev>\n", argv[0]);
+ usage(argv[0]);
return 1;
}
}
if (!dev) {
- fprintf(stderr, "Usage: %s -i <dev>\n", argv[0]);
+ usage(argv[0]);
return 1;
}
static pthread_mutex_t stdout_mutex = PTHREAD_MUTEX_INITIALIZER;
-int find_mask_map(char *string)
+static int find_mask_map(char *string)
{
int i;
{
struct blk_user_trace_setup buts;
- memset(&buts, sizeof(buts), 0);
+ memset(&buts, 0, sizeof(buts));
buts.buf_size = BUF_SIZE;
buts.buf_nr = BUF_NR;
buts.act_mask = act_mask;
ncpus = sysconf(_SC_NPROCESSORS_ONLN);
if (ncpus < 0) {
fprintf(stderr, "sysconf(_SC_NPROCESSORS_ONLN) failed\n");
- return 1;
+ return 0;
}
thread_information = malloc(ncpus * sizeof(struct thread_information));
tip->events_processed = 0;
if (!strcmp(output_name, "-")) {
- tip->ofd = dup(1);
+ tip->ofd = dup(STDOUT_FILENO);
tip->fd_lock = &stdout_mutex;
} else {
sprintf(op, "%s_out.%d", output_name, tip->cpu);
if (tip->ofd < 0) {
perror(op);
- return 1;
+ return 0;
}
if (pthread_create(&tip->thread, NULL, extract, tip)) {
}
}
-void show_stats(void)
+static void show_stats(void)
{
int i;
struct thread_information *tip;
printf("Total: %20ld events\n", events_processed);
}
-void handle_sigint(int sig)
+static void handle_sigint(int sig)
{
done = 1;
}