diff options
author | Jin Qian <jinqian@google.com> | 2016-12-22 09:53:03 -0800 |
---|---|---|
committer | Jin Qian <jinqian@google.com> | 2016-12-22 09:53:03 -0800 |
commit | 2716fdd9b83cc9b703d44fcc3baf456853c585cc (patch) | |
tree | d47bf4d219c94336322c07168e190963a9bc2ad2 /ioshark/compile_ioshark.c | |
parent | bdd6e6beb10619a5d3ecd163dc9035037f4f1400 (diff) | |
download | extras-2716fdd9b83cc9b703d44fcc3baf456853c585cc.tar.gz |
Revert "ioshark: A Repeatable Application Workload Based Storage Benchmark."
This reverts commit 99c8f98f2a9c76fabb19cdbc5b495978cfc479b3.
Change-Id: Id205f175802d55b8f12342f82199db5743e479dc
Diffstat (limited to 'ioshark/compile_ioshark.c')
-rw-r--r-- | ioshark/compile_ioshark.c | 577 |
1 files changed, 0 insertions, 577 deletions
diff --git a/ioshark/compile_ioshark.c b/ioshark/compile_ioshark.c deleted file mode 100644 index 0708dc4b..00000000 --- a/ioshark/compile_ioshark.c +++ /dev/null @@ -1,577 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <stdio.h> -#include <sys/time.h> -#include <sys/types.h> -#include <unistd.h> -#include <stdlib.h> -#include <signal.h> -#include <string.h> -#include <sys/stat.h> -#include <sys/errno.h> -#include <fcntl.h> -#include <ctype.h> -#include "ioshark.h" -#include "compile_ioshark.h" - -char *progname; - -char in_buf[2048]; - -struct flags_map_s { - char *flag_str; - int flag; -}; - -#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) - -struct flags_map_s open_flags_map[] = { - { "O_RDONLY", O_RDONLY }, - { "O_WRONLY", O_WRONLY }, - { "O_RDWR", O_RDWR }, - { "O_CREAT", O_CREAT }, - { "O_SYNC", O_SYNC }, - { "O_TRUNC", O_TRUNC }, - { "O_EXCL", O_EXCL }, - { "O_APPEND", O_APPEND }, - { "O_NOATIME", O_NOATIME }, - { "O_ASYNC", O_ASYNC }, - { "O_CLOEXEC", O_CLOEXEC }, - { "O_DIRECT", O_DIRECT }, - { "O_DIRECTORY", O_DIRECTORY }, - { "O_LARGEFILE", O_LARGEFILE }, - { "O_NOCTTY", O_NOCTTY }, - { "O_NOFOLLOW", O_NOFOLLOW }, - { "O_NONBLOCK", O_NONBLOCK }, - { "O_NDELAY", O_NDELAY }, - { "O_PATH", O_PATH } -}; - -struct flags_map_s lseek_action_map[] = { - { "SEEK_SET", SEEK_SET }, - { "SEEK_CUR", SEEK_CUR }, - { "SEEK_END", SEEK_END } -}; - -struct flags_map_s fileop_map[] = { - { "lseek", IOSHARK_LSEEK }, - { "_llseek", IOSHARK_LLSEEK }, - { "pread64", IOSHARK_PREAD64 }, - { "pwrite64", IOSHARK_PWRITE64 }, - { "read", IOSHARK_READ }, - { "write", IOSHARK_WRITE }, - { "mmap", IOSHARK_MMAP }, - { "mmap2", IOSHARK_MMAP2 }, - { "openat", IOSHARK_OPEN }, - { "fsync", IOSHARK_FSYNC }, - { "fdatasync", IOSHARK_FDATASYNC }, - { "close", IOSHARK_CLOSE } -}; - -struct in_mem_file_op { - struct ioshark_file_operation disk_file_op; - struct in_mem_file_op *next; -}; - -struct in_mem_file_op *in_mem_file_op_head = NULL, *in_mem_file_op_tail = NULL; - -void usage(void) -{ - fprintf(stderr, "%s in_file out_file\n", progname); -} - -u_int64_t -get_delta_ts(char *buf, struct timeval *start_tv) -{ - struct timeval op_tv, tv_res; - - sscanf(buf, "%lu.%lu", &op_tv.tv_sec, &op_tv.tv_usec); - timersub(&op_tv, start_tv, &tv_res); - return (tv_res.tv_usec + (tv_res.tv_sec * 1000000)); -} - -void -get_pathname(char *buf, char *pathname, enum file_op file_op) -{ - char *s, *s2, save; - - if (file_op == IOSHARK_OPEN) - s = strchr(buf, '"'); - else - s = strchr(buf, '<'); - if (s == NULL) { - fprintf(stderr, "%s: Malformed line: %s\n", - __func__, buf); - exit(EXIT_FAILURE); - } - s += 1; - if (file_op == IOSHARK_OPEN) - s2 = strchr(s, '"'); - else - s2 = strchr(s, '>'); - if (s2 == NULL) { - fprintf(stderr, "%s: Malformed line: %s\n", - __func__, buf); - exit(EXIT_FAILURE); - } - save = *s2; - *s2 = '\0'; - strcpy(pathname, s); - *s2 = save; -} - -void -get_syscall(char *buf, char *syscall) -{ - char *s, *s2; - - s = strchr(buf, ' '); - if (s == NULL) { - fprintf(stderr, "%s: Malformed line: %s\n", - __func__, buf); - exit(EXIT_FAILURE); - } - s += 1; - s2 = strchr(s, '('); - if (s2 == NULL) { - fprintf(stderr, "%s: Malformed line: %s\n", - __func__, buf); - exit(EXIT_FAILURE); - } - *s2 = '\0'; - strcpy(syscall, s); - *s2 = '('; -} - -void -get_mmap_offset_len_prot(char *buf, int *prot, off_t *offset, u_int64_t *len) -{ - char *s, *s1; - int i; - char protstr[128]; - - s = strchr(buf, ','); - if (s == NULL) { - fprintf(stderr, "%s: Malformed line: %s\n", - __func__, buf); - exit(EXIT_FAILURE); - } - s += 2; - sscanf(s, "%lu", len); - s1 = strchr(s, ','); - if (s1 == NULL) { - fprintf(stderr, "%s: Malformed line: %s\n", - __func__, buf); - exit(EXIT_FAILURE); - } - s1 += 2; - s = strchr(s1, ','); - if (s == NULL) { - fprintf(stderr, "%s: Malformed line: %s\n", - __func__, buf); - exit(EXIT_FAILURE); - } - *s = '\0'; - strcpy(protstr, s1); - *prot = 0; - if (strstr(protstr, "PROT_READ")) - *prot |= IOSHARK_PROT_READ; - if (strstr(protstr, "PROT_WRITE")) - *prot |= IOSHARK_PROT_WRITE; - *s = ','; - s += 2; - for (i = 0 ; i < 2 ; i++) { - s = strchr(s, ','); - if (s == NULL) { - fprintf(stderr, "%s: Malformed line: %s\n", - __func__, buf); - exit(EXIT_FAILURE); - } - s += 2; - } - sscanf(s, "%lx", offset); -} - -void -get_lseek_offset_action(char *buf, enum file_op op, - off_t *offset, char *action) -{ - char *s, *s2; - - s = strchr(buf, ','); - if (s == NULL) { - fprintf(stderr, "%s: Malformed line: %s\n", - __func__, buf); - exit(EXIT_FAILURE); - } - s += 2; - sscanf(s, "%lu", offset); - s = strchr(s, ','); - if (s == NULL) { - fprintf(stderr, "%s: Malformed line: %s\n", - __func__, buf); - exit(EXIT_FAILURE); - } - s += 2; - if (op == IOSHARK_LLSEEK) { - s = strchr(s, ','); - if (s == NULL) { - fprintf(stderr, "%s: Malformed line: %s\n", - __func__, buf); - exit(EXIT_FAILURE); - } - s += 2; - } - s2 = strchr(s, ')'); - if (s2 == NULL) { - fprintf(stderr, "%s: Malformed line: %s\n", - __func__, buf); - exit(EXIT_FAILURE); - } - *s2 = '\0'; - strcpy(action, s); - *s2 = ')'; -} - -void -get_rw_len(char *buf, - u_int64_t *len) -{ - char *s_len; - - s_len = strrchr(buf, ','); - if (s_len == NULL) { - fprintf(stderr, "%s: Malformed line: %s\n", - __func__, buf); - exit(EXIT_FAILURE); - } - sscanf(s_len + 2, "%lu", len); -} - -void -get_prw64_offset_len(char *buf, - off_t *offset, - u_int64_t *len) -{ - char *s_offset, *s_len; - - s_offset = strrchr(buf, ','); - if (s_offset == NULL) { - fprintf(stderr, "%s: Malformed line 1: %s\n", - __func__, buf); - exit(EXIT_FAILURE); - } - *s_offset = '\0'; - s_len = strrchr(buf, ','); - if (s_len == NULL) { - fprintf(stderr, "%s: Malformed line 2: %s\n", - __func__, buf); - exit(EXIT_FAILURE); - } - *s_offset = ','; - sscanf(s_len + 2, "%lu", len); - sscanf(s_offset + 2, "%lu", offset); -} - -void -get_openat_flags_mode(char *buf, char *flags, mode_t *mode) -{ - char *s, *s2, lookfor; - - s = strchr(buf, ','); - if (s == NULL) { - fprintf(stderr, "%s: Malformed line: %s\n", - __func__, buf); - exit(EXIT_FAILURE); - } - s += 2; - s = strchr(s, ','); - if (s == NULL) { - fprintf(stderr, "%s: Malformed line: %s\n", - __func__, buf); - exit(EXIT_FAILURE); - } - s += 2; - if (strstr(s, "O_CREAT") == NULL) - lookfor = ')'; - else - lookfor = ','; - s2 = strchr(s, lookfor); - if (s2 == NULL) { - fprintf(stderr, "%s: Malformed line: %s\n", - __func__, buf); - exit(EXIT_FAILURE); - } - *s2 = '\0'; - strcpy(flags, s); - *s2 = lookfor; - if (strstr(s, "O_CREAT") != NULL) { - s = s2 + 2; - s2 = strchr(s, ')'); - if (s2 == NULL) { - fprintf(stderr, "%s: Malformed line: %s\n", - __func__, buf); - exit(EXIT_FAILURE); - } - *s2 = '\0'; - sscanf(s, "%o", mode); - *s2 = ')'; - } -} - -int -lookup_map(char *s, struct flags_map_s *flags_map, int maplen) -{ - int found = 0, flag = 0; - int i; - - while (isspace(*s)) - s++; - for (i = 0 ; i < maplen ; i++) { - if (strcmp(flags_map[i].flag_str, s) == 0) { - flag = flags_map[i].flag; - found = 1; - break; - } - } - if (found == 0) { - fprintf(stderr, "%s: Unknown syscall %s\n", - __func__, s); - exit(1); - } - return flag; -} - -int -map_open_flags(char *s) -{ - int flags = 0; - char *s1; - - while ((s1 = strchr(s, '|'))) { - *s1 = '\0'; - flags |= lookup_map(s, open_flags_map, - ARRAY_SIZE(open_flags_map)); - *s1 = '|'; - s = s1 + 1; - } - /* Last option */ - flags |= lookup_map(s, open_flags_map, - ARRAY_SIZE(open_flags_map)); - return flags; -} - -int -map_lseek_action(char *s) -{ - int flags = 0; - char *s1; - - while ((s1 = strchr(s, '|'))) { - *s1 = '\0'; - flags |= lookup_map(s, lseek_action_map, - ARRAY_SIZE(lseek_action_map)); - *s1 = '|'; - s = s1 + 1; - } - /* Last option */ - flags |= lookup_map(s, lseek_action_map, - ARRAY_SIZE(lseek_action_map)); - return flags; -} - -enum file_op -map_syscall(char *syscall) -{ - return lookup_map(syscall, fileop_map, - ARRAY_SIZE(fileop_map)); -} - -void -get_start_time(struct timeval *tv) -{ - FILE *fp; - - tv->tv_usec = 0; - fp = fopen("trace.begin", "r"); - if (fp == NULL) { - fprintf(stderr, "%s Can't open trace.begin\n", - __func__); - exit(EXIT_FAILURE); - } - if (fscanf(fp, "%lu", &tv->tv_sec) != 1) { - fprintf(stderr, "%s Can't read seconds from trace.begin\n", - __func__); - exit(EXIT_FAILURE); - } -} - -/* - * For each tracefile, we first create in-memory structures, then once - * we've processed each tracefile completely, we write out the in-memory - * structures and free them. - */ -int main(int argc, char **argv) -{ - FILE *fp; - char path[512]; - char syscall[512]; - char lseek_action_str[512]; - char *s; - char open_flags_str[64]; - void *db_node; - int num_io_operations = 0; - struct ioshark_header header; - struct ioshark_file_operation *disk_file_op; - struct in_mem_file_op *in_mem_fop; - struct stat st; - char *infile, *outfile; - struct timeval start_time; - - progname = argv[0]; - if (argc != 3) { - usage(); - exit(EXIT_FAILURE); - } - infile = argv[1]; - outfile = argv[2]; - if (stat(infile, &st) < 0) { - fprintf(stderr, "%s Can't stat %s\n", - progname, infile); - exit(EXIT_FAILURE); - } - if (st.st_size == 0) { - fprintf(stderr, "%s Empty file %s\n", - progname, infile); - exit(EXIT_FAILURE); - } - get_start_time(&start_time); - fp = fopen(infile, "r"); - if (fp == NULL) { - fprintf(stderr, "%s Can't open %s\n", - progname, infile); - exit(EXIT_FAILURE); - } - while (fgets(in_buf, 2048, fp)) { - s = in_buf; - while (isspace(*s)) - s++; - in_mem_fop = malloc(sizeof(struct in_mem_file_op)); - disk_file_op = &in_mem_fop->disk_file_op; - disk_file_op->delta_us = get_delta_ts(s, &start_time); - get_syscall(s, syscall); - disk_file_op->file_op = map_syscall(syscall); - get_pathname(s, path, disk_file_op->file_op); - db_node = files_db_add(path); - disk_file_op->fileno = files_db_get_fileno(db_node); - switch (disk_file_op->file_op) { - case IOSHARK_LLSEEK: - case IOSHARK_LSEEK: - get_lseek_offset_action(s, - disk_file_op->file_op, - &disk_file_op->lseek_offset, - lseek_action_str); - disk_file_op->lseek_action = - map_lseek_action(lseek_action_str); - if (disk_file_op->lseek_action == SEEK_SET) - files_db_update_size(db_node, - disk_file_op->lseek_offset); - break; - case IOSHARK_PREAD64: - case IOSHARK_PWRITE64: - get_prw64_offset_len(s, - &disk_file_op->prw_offset, - &disk_file_op->prw_len); - files_db_update_size(db_node, - disk_file_op->prw_offset + - disk_file_op->prw_len); - break; - case IOSHARK_READ: - case IOSHARK_WRITE: - get_rw_len(s, &disk_file_op->rw_len); - files_db_add_to_size(db_node, - disk_file_op->rw_len); - break; - case IOSHARK_MMAP: - case IOSHARK_MMAP2: - get_mmap_offset_len_prot(s, - &disk_file_op->mmap_prot, - &disk_file_op->mmap_offset, - &disk_file_op->mmap_len); - files_db_update_size(db_node, - disk_file_op->mmap_offset + - disk_file_op->mmap_len); - break; - case IOSHARK_OPEN: - disk_file_op->open_mode = 0; - get_openat_flags_mode(s, open_flags_str, - &disk_file_op->open_mode); - disk_file_op->open_flags = - map_open_flags(open_flags_str); - break; - case IOSHARK_FSYNC: - case IOSHARK_FDATASYNC: - break; - case IOSHARK_CLOSE: - break; - default: - break; - } - /* Chain at the end */ - num_io_operations++; - in_mem_fop->next = NULL; - if (in_mem_file_op_head == NULL) { - in_mem_file_op_tail = in_mem_fop; - in_mem_file_op_head = in_mem_fop; - } else { - in_mem_file_op_tail->next = in_mem_fop; - in_mem_file_op_tail = in_mem_fop; - } - } - fclose(fp); - /* - * Now we can write everything out to the output tracefile. - */ - fp = fopen(outfile, "w+"); - if (fp == NULL) { - fprintf(stderr, "%s Can't open trace.outfile\n", - progname); - exit(EXIT_FAILURE); - } - header.num_io_operations = num_io_operations; - header.num_files = files_db_get_total_obj(); - if (fwrite(&header, sizeof(struct ioshark_header), 1, fp) != 1) { - fprintf(stderr, "%s Write error trace.outfile\n", - progname); - exit(EXIT_FAILURE); - } - files_db_write_objects(fp); - while (in_mem_file_op_head != NULL) { - struct in_mem_file_op *temp; - - disk_file_op = &in_mem_file_op_head->disk_file_op; - if (fwrite(disk_file_op, - sizeof(struct ioshark_file_operation), 1, fp) != 1) { - fprintf(stderr, "%s Write error trace.outfile\n", - progname); - exit(EXIT_FAILURE); - } - temp = in_mem_file_op_head; - in_mem_file_op_head = in_mem_file_op_head->next; - free(temp); - } -} |