$ callgrind_annotate --auto=yes callgrind.out.11921 -------------------------------------------------------------------------------- Profile data file 'callgrind.out.11921' (creator: callgrind-3.6.1-Debian) -------------------------------------------------------------------------------- I1 cache: D1 cache: LL cache: Timerange: Basic block 0 - 228181262 Trigger: Program termination Profiled target: ./ag --literal abcdefghijklmnopqrstuvwxyz ../ (PID 11921, part 1) Events recorded: Ir Events shown: Ir Event sort order: Ir Thresholds: 99 Include dirs: User annotated: Auto-annotation: on -------------------------------------------------------------------------------- Ir -------------------------------------------------------------------------------- 1,139,437,344 PROGRAM TOTALS -------------------------------------------------------------------------------- Ir file:function -------------------------------------------------------------------------------- 386,014,011 /build/buildd/eglibc-2.13/posix/fnmatch_loop.c:internal_fnmatch [/lib/x86_64-linux-gnu/libc-2.13.so] 181,870,097 src/util.c:is_binary [/home/geoff/code/the_silver_searcher/ag] 123,209,345 /build/buildd/eglibc-2.13/posix/fnmatch.c:fnmatch@@GLIBC_2.2.5 [/lib/x86_64-linux-gnu/libc-2.13.so] 104,867,805 src/print.c:print_file_matches [/home/geoff/code/the_silver_searcher/ag] 76,747,163 /build/buildd/eglibc-2.13/string/../sysdeps/x86_64/multiarch/../strlen.S:__GI_strlen [/lib/x86_64-linux-gnu/libc-2.13.so] 63,421,170 src/util.c:boyer_moore_strnstr [/home/geoff/code/the_silver_searcher/ag] 60,028,609 /build/buildd/eglibc-2.13/posix/fnmatch_loop.c:internal_fnmatch'2 [/lib/x86_64-linux-gnu/libc-2.13.so] 44,018,667 src/ignore.c:filename_filter [/home/geoff/code/the_silver_searcher/ag] 27,072,637 /build/buildd/eglibc-2.13/string/../sysdeps/x86_64/memchr.S:memchr [/lib/x86_64-linux-gnu/libc-2.13.so] 8,312,570 /build/buildd/eglibc-2.13/string/../sysdeps/x86_64/multiarch/../strcmp.S:__GI_strcmp [/lib/x86_64-linux-gnu/libc-2.13.so] 7,803,075 /build/buildd/eglibc-2.13/malloc/malloc.c:_int_malloc [/lib/x86_64-linux-gnu/libc-2.13.so] 7,040,534 /build/buildd/eglibc-2.13/posix/../locale/weight.h:internal_fnmatch 6,061,868 /build/buildd/eglibc-2.13/string/../string/memmove.c:__GI_memmove [/lib/x86_64-linux-gnu/libc-2.13.so] 4,384,383 /build/buildd/eglibc-2.13/string/../sysdeps/x86_64/multiarch/../memcpy.S:__GI_memcpy [/lib/x86_64-linux-gnu/libc-2.13.so] 3,951,640 /build/buildd/eglibc-2.13/malloc/malloc.c:_int_free [/lib/x86_64-linux-gnu/libc-2.13.so] 3,779,220 /build/buildd/eglibc-2.13/dirent/../sysdeps/unix/readdir.c:readdir [/lib/x86_64-linux-gnu/libc-2.13.so] 3,181,118 /build/buildd/eglibc-2.13/malloc/malloc.c:malloc [/lib/x86_64-linux-gnu/libc-2.13.so] 3,089,135 src/main.c:search_dir'2 [/home/geoff/code/the_silver_searcher/ag] 2,095,514 /build/buildd/eglibc-2.13/malloc/malloc.c:free [/lib/x86_64-linux-gnu/libc-2.13.so] 2,018,298 /build/buildd/eglibc-2.13/dirent/../sysdeps/wordsize-64/../../dirent/scandir.c:scandir [/lib/x86_64-linux-gnu/libc-2.13.so] 1,941,992 /build/buildd/eglibc-2.13/string/strcoll_l.c:strcoll_l [/lib/x86_64-linux-gnu/libc-2.13.so] 1,889,859 /build/buildd/eglibc-2.13/stdlib/msort.c:msort_with_tmp.part.0'2 [/lib/x86_64-linux-gnu/libc-2.13.so] 1,704,553 /build/buildd/eglibc-2.13/malloc/malloc.c:malloc_consolidate.part.3 [/lib/x86_64-linux-gnu/libc-2.13.so] 1,644,688 src/ignore.c:ignorefile_filter [/home/geoff/code/the_silver_searcher/ag] 1,601,628 /build/buildd/eglibc-2.13/dirent/../sysdeps/unix/sysv/linux/getdents.c:__getdents [/lib/x86_64-linux-gnu/libc-2.13.so] 1,582,620 src/util.c:strlcat [/home/geoff/code/the_silver_searcher/ag] -------------------------------------------------------------------------------- -- Auto-annotated source: src/util.c -------------------------------------------------------------------------------- Ir -- line 6 ---------------------------------------- . #include . #include . #include "util.h" . . . void generate_skip_lookup(const char *find, size_t f_len, size_t skip_lookup[]) { . size_t i = 0; . 770 for (i = 0; i < 256; i++) { 256 skip_lookup[i] = f_len - 1; . } . 56 for (i = 0; i < f_len - 1; i++) { 125 skip_lookup[(unsigned char)find[i]] = f_len - i - 1; . } . } . . /* Boyer-Moore-Horspool strstr */ 33,134 char* boyer_moore_strnstr(const char *s, const char *find, size_t s_len, size_t f_len, size_t skip_lookup[]) { . size_t i; . size_t pos = 0; . . /* It's impossible to match a larger string */ 33,134 if (f_len > s_len) { 16,567 return(NULL); . } . 18,114,095 while (pos < (s_len - f_len)) { 27,078,783 for (i = f_len - 1; s[pos + i] == find[i]; i--) { 47,758 if (i == 0) { . return((char *)(&(s[pos]))); . } . } . 18,015,398 pos += skip_lookup[(unsigned char)s[pos + f_len - 1]]; . } . 32,600 return(NULL); 49,701 } . . /* Copy-pasted from above. Yes I know this is bad. One day I might even fix it. */ . char* boyer_moore_strncasestr(const char *s, const char *find, size_t s_len, size_t f_len, size_t skip_lookup[]) { . size_t i; . size_t pos = 0; . . /* It's impossible to match a larger string */ . if (f_len > s_len) { -- line 52 ---------------------------------------- -- line 62 ---------------------------------------- . . pos += skip_lookup[(unsigned char)tolower(s[pos + f_len - 1])]; . } . . return(NULL); . } . . int is_binary(const void* buf, const int buf_len) { 41,710 int suspicious_bytes = 0; 51,642 int total_bytes = buf_len > 1024 ? 1024 : buf_len; . const unsigned char *buf_c = buf; . int i; . 75,722,504 for (i = 0; i < buf_len && i < 1024; i++) { 60,514,807 if (buf_c[i] == '\0') { . /* NULL char. It's binary */ 93,450 return(1); . } 15,130,201 else if (buf_c[i] < 32 || buf_c[i] > 127) { 30,260,402 suspicious_bytes++; . } . } . . /* If > 10% of bytes are suspicious, assume it's binary */ 51,642 if ((suspicious_bytes * 100) / total_bytes > 10) { . return(1); . } . . return(0); 3,739 } . . int is_regex(const char* query, const int query_len) { . return 1; . } . . /* . * strlcat and strlcpy, taken from linux kernel . */ . size_t strlcat(char *dest, const char *src, size_t count) 527,540 { 105,508 size_t dsize = strlen(dest); 1,903,679 => /build/buildd/eglibc-2.13/string/../sysdeps/x86_64/multiarch/../strlen.S:__GI_strlen (52754x) 105,508 size_t len = strlen(src); 994,209 => /build/buildd/eglibc-2.13/string/../sysdeps/x86_64/multiarch/../strlen.S:__GI_strlen (52754x) 52,754 size_t res = dsize + len; . 52,754 dest += dsize; 52,754 count -= dsize; . . if (len >= count) { 158,262 len = count - 1; . } . . memcpy(dest, src, len); . 52,754 dest[len] = 0; . . return res; 474,786 } . . size_t strlcpy(char *dest, const char *src, size_t size) 237,393 { 79,131 size_t ret = strlen(src); 946,680 => /build/buildd/eglibc-2.13/string/../sysdeps/x86_64/multiarch/../strlen.S:__GI_strlen (26377x) . 52,754 if (size) . { 79,131 size_t len = (ret >= size) ? size - 1 : ret; . memcpy(dest, src, len); 26,377 dest[len] = '\0'; . } . . return ret; 211,016 } -------------------------------------------------------------------------------- -- Auto-annotated source: src/print.c -------------------------------------------------------------------------------- Ir -- line 10 ---------------------------------------- . . int first_file_match = 1; . . const char *colors_reset = "\e[0m\e[K"; . const char *colors_path = "\e[1;32m"; /* bold green */ . const char *colors_match = "\e[30;43m"; /* black with yellow background */ . . void print_path(const char* path) { 189 if (opts.ackmate) { . printf(":%s", path); . } . else { 189 if (opts.color) { . printf("%s%s%s", colors_path, path, colors_reset); . } . else { . printf("%s", path); . } . } . } . . /* TODO: make print_matching_line() */ . . /* TODO: line numbers need to be colorized */ 3,565,290 void print_file_matches(const char* path, const char* buf, const int buf_len, const match matches[], const int matches_len) { . int line = 1; . int column = 0; . char **context_prev_lines = NULL; . int prev_line = 0; . int last_prev_line = 0; . int prev_line_offset = 0; . int cur_match = 0; . int in_a_match = 0; . int lines_since_last_match = 1000000; /* if I initialize this to INT_MAX it'll overflow */ . int last_printed_match = 0; 252 char sep = '-'; . int i, j; . . if (opts.ackmate) { . sep = ':'; . } . 375 if (first_file_match == 0 && opts.print_break) { . printf("\n"); . } 63 first_file_match = 0; . 189 if (opts.print_heading) { 126 print_path(path); 92,376 => src/print.c:print_path (63x) . printf("\n"); . } . 378 context_prev_lines = malloc(sizeof(char*) * (opts.before + 1)); 6,833 => /build/buildd/eglibc-2.13/malloc/malloc.c:malloc (63x) . 126 for (i = 0; i < opts.before; i++) { . context_prev_lines[i] = NULL; . } . 20,809,245 for (i = 0; i < buf_len && (cur_match < matches_len || lines_since_last_match <= opts.after); i++) { 20,727,294 if (cur_match < matches_len && i == matches[cur_match].start) { 292 in_a_match = 1; . 687 if (cur_match > 0 && opts.context && lines_since_last_match > (opts.before + opts.after)) { . printf("--\n"); . } . 292 if (lines_since_last_match > 0) { . /* TODO: this is buggy as hell */ 438 if (opts.before > 0 && lines_since_last_match > opts.after + opts.before) { . /* We found the start of a match. print the previous line(s) */ . for (j = 0; j < opts.before; j++) { . prev_line = (last_prev_line + j) % opts.before; . if (context_prev_lines[prev_line] != NULL) { . if (opts.print_heading == 0) { . print_path(path); . printf(":"); . } 126 printf("%i%c%s\n", line - (opts.before - j), sep, context_prev_lines[prev_line]); . } . } . } . 438 if (opts.ackmate == 0) { 438 if (opts.print_heading == 0) { . print_path(path); . printf(":"); . } . printf("%i:", line); 438 if (opts.column) { 146 printf("%i:", column + 1); . } . /* print up to current char */ 18,770 for (j = prev_line_offset; j < i; j++) { 9,093 putchar(buf[j]); . } . } . } . 146 lines_since_last_match = 0; 438 if (opts.color) { . printf("%s", colors_match); . } . } . 13,818,196 if (cur_match < matches_len && i == matches[cur_match].end) { . /* We found the end of a match. */ 146 in_a_match = 0; 146 cur_match++; 584 if (opts.color) { . printf("%s", colors_reset); . } . } . 13,856,697 if ((in_a_match || lines_since_last_match == 0) && opts.ackmate == 0) { 11,581 putchar(buf[i]); . } . . column++; . 6,922,558 if (buf[i] == '\n') { 304,509 if (opts.before > 0) { . if (context_prev_lines[last_prev_line] != NULL) { . free(context_prev_lines[last_prev_line]); . } . /* We just incremented column so it will always be at least 1. . * We don't want to strcpy the \n . */ . context_prev_lines[last_prev_line] = strndup(&buf[prev_line_offset], i - prev_line_offset); . last_prev_line = (last_prev_line + 1) % opts.before; . } . } . 6,719,804 if (buf[i] == '\n' || i == buf_len - 1) { 203,006 if (lines_since_last_match == 0) { 438 if (opts.ackmate) { . /* print headers for ackmate to parse */ . printf("%i;", line); . while (last_printed_match < cur_match) { . printf("%i %i", (matches[last_printed_match].start - prev_line_offset), (matches[last_printed_match].end - matches[last_printed_match].start)); . if (last_printed_match == cur_match - 1) { . putchar(':'); . } . else { -- line 152 ---------------------------------------- -- line 157 ---------------------------------------- . } . /* print up to current char */ . for (j = prev_line_offset; j < i; j++) { . putchar(buf[j]); . } . putchar('\n'); . } . } 202,714 else if (lines_since_last_match <= opts.after) { . /* print context after matching line */ . if (opts.print_heading == 0) { . print_path(path); . printf(":"); . } . printf("%i%c", line, sep); . . for (j = prev_line_offset; j < i; j++) { . putchar(buf[j]); . } . putchar('\n'); . } . . prev_line_offset = i + 1; /* skip the newline */ 101,503 line++; 101,503 column = 0; 7,125,564 lines_since_last_match++; . } . } . 10,363,335 free(context_prev_lines); 5,002 => /build/buildd/eglibc-2.13/malloc/malloc.c:free (63x) 441 } -------------------------------------------------------------------------------- -- Auto-annotated source: src/ignore.c -------------------------------------------------------------------------------- Ir -- line 24 ---------------------------------------- . }; . . /* TODO: make this a sorted array so filtering is O(log(n)) instead of O(n) */ . char **ignore_patterns = NULL; . int ignore_patterns_len = 0; . . const int fnmatch_flags = 0 & FNM_PATHNAME; . 852 void add_ignore_pattern(const char* pattern) { 1,491 ignore_patterns = realloc(ignore_patterns, (ignore_patterns_len + 1) * sizeof(char**)); 43,366 => /build/buildd/eglibc-2.13/malloc/malloc.c:realloc (213x) 989 => /build/buildd/eglibc-2.13/elf/../sysdeps/x86_64/dl-trampoline.S:_dl_runtime_resolve (1x) 1,065 ignore_patterns[ignore_patterns_len] = strdup(pattern); 62,429 => /build/buildd/eglibc-2.13/string/strdup.c:strdup (213x) 213 ignore_patterns_len++; 852 log_debug("added ignore pattern %s", pattern); 7,029 => /home/geoff/code/the_silver_searcher/src/log.c:log_debug (213x) 639 } . 3 void cleanup_ignore_patterns() { . int i; 858 for(i = 0; i /build/buildd/eglibc-2.13/malloc/malloc.c:free (213x) . } 2 free(ignore_patterns); 134 => /build/buildd/eglibc-2.13/malloc/malloc.c:free (1x) 3 } . . /* For loading git/svn/hg ignore patterns */ 64 void load_ignore_patterns(const char *ignore_filename) { . FILE *fp = NULL; 48 fp = fopen(ignore_filename, "r"); 9,020 => /build/buildd/eglibc-2.13/libio/../sysdeps/wordsize-64/../../libio/iofopen.c:fopen@@GLIBC_2.2.5 (16x) 887 => /build/buildd/eglibc-2.13/elf/../sysdeps/x86_64/dl-trampoline.S:_dl_runtime_resolve (1x) 32 if (fp == NULL) { . log_err("Skipping ignore file %s", ignore_filename); . return; . } . 16 char *line = NULL; . ssize_t line_length = 0; 16 size_t line_cap = 0; . 474 while((line_length = getline(&line, &line_cap, fp)) > 0) { 426 line[line_length-1] = '\0'; /* kill the \n */ 426 add_ignore_pattern(line); 118,925 => src/ignore.c:add_ignore_pattern (213x) . } . 32 free(line); 1,269 => /build/buildd/eglibc-2.13/malloc/malloc.c:free (16x) 32 fclose(fp); 6,443 => /build/buildd/eglibc-2.13/libio/iofclose.c:fclose@@GLIBC_2.2.5 (16x) 927 => /build/buildd/eglibc-2.13/elf/../sysdeps/x86_64/dl-trampoline.S:_dl_runtime_resolve (1x) 64 } . 164,496 int ignorefile_filter(struct dirent *dir) { . int i; 616,716 for (i = 0; ignore_pattern_files[i] != NULL; i++) { 493,360 if (strcmp(ignore_pattern_files[i], dir->d_name) == 0) { 923 => /build/buildd/eglibc-2.13/elf/../sysdeps/x86_64/dl-trampoline.S:_dl_runtime_resolve (1x) 4,292,283 => /build/buildd/eglibc-2.13/string/../sysdeps/x86_64/multiarch/../strcmp.S:__GI_strcmp (123340x) 48 log_debug("ignore pattern matched for %s", dir->d_name); 528 => /home/geoff/code/the_silver_searcher/src/log.c:log_debug (16x) 123,340 return(1); . } . } 82,232 return(0); 164,496 } . . /* this function is REALLY HOT. It gets called for every file */ 205,620 int filename_filter(struct dirent *dir) { 41,124 const char *filename = dir->d_name; . char *pattern = NULL; . int rc = 0; . int i; . 205,620 if (opts.follow_symlinks == 0 && dir->d_type == DT_LNK) { 468 log_debug("File %s ignored becaused it's a symlink", dir->d_name); 3,861 => /home/geoff/code/the_silver_searcher/src/log.c:log_debug (117x) 234 return(0); . } . . /* TODO: check if opts want to ignore hidden files */ 82,014 if (filename[0] == '.') { 41,007 return(0); . } . 327,624 for (i = 0; evil_hardcoded_ignore_files[i] != NULL; i++) { 238,272 if (strcmp(filename, evil_hardcoded_ignore_files[i]) == 0) { 1,827,062 => /build/buildd/eglibc-2.13/string/../sysdeps/x86_64/multiarch/../strcmp.S:__GI_strcmp (59568x) . log_err("file %s ignored because of name", filename); 59,568 return(0); . } . } . 14,244,553 for (i = 0; i /build/buildd/eglibc-2.13/posix/fnmatch.c:fnmatch@@GLIBC_2.2.5 (3520267x) 927 => /build/buildd/eglibc-2.13/elf/../sysdeps/x86_64/dl-trampoline.S:_dl_runtime_resolve (1x) 13,692 log_debug("file %s ignored because name matches pattern %s", dir->d_name, pattern); 112,959 => /home/geoff/code/the_silver_searcher/src/log.c:log_debug (3423x) 3,423 return(0); . } . } . 79,083 if (opts.ackmate_dir_filter != NULL) { . /* we just care about the match, not where the matches are */ . rc = pcre_exec(opts.ackmate_dir_filter, NULL, dir->d_name, strlen(dir->d_name), 0, 0, NULL, 0); . if (rc >= 0) { . log_err("file %s ignored because name ackmate dir filter pattern", dir->d_name); . return(0); . } . } . 26,361 return(1); 287,868 } -------------------------------------------------------------------------------- -- Auto-annotated source: src/main.c -------------------------------------------------------------------------------- Ir -- line 30 ---------------------------------------- . long total_file_count = 0; . long total_byte_count = 0; . . size_t skip_lookup[256]; . . /* TODO: append matches to some data structure instead of just printing them out . * then there can be sweet summaries of matches/files scanned/time/etc . */ 289,755 int search_dir(const pcre *re, const pcre_extra *re_extra, const char* path, const int depth) { . /* TODO: don't just die. also make max depth configurable */ 9,786 if (depth > MAX_SEARCH_DEPTH) { . log_err("Search depth greater than %i, giving up.", depth); . exit(1); . } 4,893 struct dirent **dir_list = NULL; . struct dirent *dir = NULL; . int results = 0; . . int fd = -1; 4,803 off_t f_len = 0; 4,803 char *buf = NULL; . int rv = 0; . char *dir_full_path = NULL; . size_t path_length = 0; . int i; . 24,465 results = scandir(path, &dir_list, &ignorefile_filter, &alphasort); 12,841 => /build/buildd/eglibc-2.13/dirent/../sysdeps/wordsize-64/../../dirent/scandir.c:scandir (1x) 959 => /build/buildd/eglibc-2.13/elf/../sysdeps/x86_64/dl-trampoline.S:_dl_runtime_resolve (1x) 9,786 if (results > 0) { 48 for (i = 0; i < results; i++) { 32 dir = dir_list[i]; 112 path_length = (size_t)(strlen(path) + strlen(dir->d_name) + 2); /* 2 for slash and null char */ 552 => /build/buildd/eglibc-2.13/string/../sysdeps/x86_64/multiarch/../strlen.S:__GI_strlen (32x) 48 dir_full_path = malloc(path_length); 2,461 => /build/buildd/eglibc-2.13/malloc/malloc.c:malloc (16x) 64 strlcpy(dir_full_path, path, path_length); 1,206 => /home/geoff/code/the_silver_searcher/src/util.c:strlcpy (16x) 64 strlcat(dir_full_path, "/", path_length); 1,429 => /home/geoff/code/the_silver_searcher/src/util.c:strlcat (16x) 64 strlcat(dir_full_path, dir->d_name, path_length); 1,490 => /home/geoff/code/the_silver_searcher/src/util.c:strlcat (16x) 32 load_ignore_patterns(dir_full_path); 183,886 => /home/geoff/code/the_silver_searcher/src/ignore.c:load_ignore_patterns (16x) 32 free(dir); 1,264 => /build/buildd/eglibc-2.13/malloc/malloc.c:free (16x) . dir = NULL; 48 free(dir_full_path); 1,324 => /build/buildd/eglibc-2.13/malloc/malloc.c:free (16x) . dir_full_path = NULL; . } . } 9,786 free(dir_list); 922 => /build/buildd/eglibc-2.13/elf/../sysdeps/x86_64/dl-trampoline.S:_dl_runtime_resolve (1x) 9 => /build/buildd/eglibc-2.13/malloc/malloc.c:free (1x) 4,893 dir_list = NULL; . 24,465 results = scandir(path, &dir_list, &filename_filter, &alphasort); 32,145 => /build/buildd/eglibc-2.13/dirent/../sysdeps/wordsize-64/../../dirent/scandir.c:scandir (1x) 9,786 if (results == 0) . { 270 log_debug("No results found in directory %s", path); 2,970 => /home/geoff/code/the_silver_searcher/src/log.c:log_debug (90x) 180 free(dir_list); 810 => /build/buildd/eglibc-2.13/malloc/malloc.c:free (90x) . dir_list = NULL; 90 return(0); . } 9,606 else if (results == -1) { . log_err("Error opening directory %s", path); 4,803 return(0); . } . 19,212 match matches[MAX_MATCHES_PER_FILE]; . int matches_len = 0; . int buf_len = 0; . int buf_offset = 0; 14,409 int offset_vector[MAX_MATCHES_PER_FILE * 3]; /* TODO */ 4,803 int rc = 0; . struct stat statbuf; . int binary = 0; . 62,328 for (i=0; id_name) + 2); /* 2 for slash and null char */ 985 => /build/buildd/eglibc-2.13/string/../sysdeps/x86_64/multiarch/../strlen.S:__GI_strlen (64x) 79,083 dir_full_path = malloc(path_length); 3,304 => /build/buildd/eglibc-2.13/malloc/malloc.c:malloc (32x) 911 => /build/buildd/eglibc-2.13/elf/../sysdeps/x86_64/dl-trampoline.S:_dl_runtime_resolve (1x) 105,444 strlcpy(dir_full_path, path, path_length); 2,935 => /home/geoff/code/the_silver_searcher/src/util.c:strlcpy (32x) 105,444 strlcat(dir_full_path, "/", path_length); 2,720 => /home/geoff/code/the_silver_searcher/src/util.c:strlcat (32x) 131,805 strlcat(dir_full_path, dir->d_name, path_length); 2,812 => /home/geoff/code/the_silver_searcher/src/util.c:strlcat (32x) . 131,805 log_debug("dir %s type %i", dir_full_path, dir->d_type); 1,056 => /home/geoff/code/the_silver_searcher/src/log.c:log_debug (32x) . /* TODO: scan files in current dir before going deeper */ 52,722 if (dir->d_type == DT_DIR) { 14,676 if (opts.recurse_dirs) { 19,568 log_debug("Searching dir %s", dir_full_path); 1,056 => /home/geoff/code/the_silver_searcher/src/log.c:log_debug (32x) 53,367 rv = search_dir(re, re_extra, dir_full_path, depth + 1); 1,139,159,561 => src/main.c:search_dir'2 (32x) . } . goto cleanup; . } . 64,407 if (opts.file_search_regex) { . rc = pcre_exec(opts.file_search_regex, NULL, dir_full_path, strlen(dir_full_path), . buf_offset, 0, offset_vector, 3); . if (rc < 0) { /* no match */ . log_debug("Skipping %s due to file_search_regex.", dir_full_path); . goto cleanup; . } . } . . fd = open(dir_full_path, O_RDONLY); 42,938 if (fd < 0) { . log_err("Error opening file %s. Skipping...", dir_full_path); . goto cleanup; . } . . rv = fstat(fd, &statbuf); 42,938 if (rv != 0) { . log_err("Error fstat()ing file %s. Skipping...", dir_full_path); . goto cleanup; . } . 42,938 f_len = statbuf.st_size; . 42,938 if (f_len == 0) { 1,548 log_debug("File %s is empty, skipping.", dir_full_path); 17,028 => /home/geoff/code/the_silver_searcher/src/log.c:log_debug (516x) 1,032 goto cleanup; . } 41,906 else if (f_len > 1024 * 1024 * 1024) { /* 1 GB */ . log_err("File %s is too big. Skipping...", dir_full_path); . goto cleanup; . } . 209,530 buf = mmap(0, f_len, PROT_READ, MAP_SHARED, fd, 0); 125,718 => /build/buildd/eglibc-2.13/misc/../sysdeps/unix/syscall-template.S:mmap (20953x) 894 => /build/buildd/eglibc-2.13/elf/../sysdeps/x86_64/dl-trampoline.S:_dl_runtime_resolve (1x) 41,906 if (buf == MAP_FAILED) { . log_err("File %s failed to load: %s.", dir_full_path, strerror(errno)); . goto cleanup; . } . 41,906 buf_len = f_len; . 104,765 if (is_binary((void*)buf, buf_len)) { /* Who needs duck typing when you have void cast? :) */ 181,870,097 => /home/geoff/code/the_silver_searcher/src/util.c:is_binary (20953x) 13,596 if (opts.search_binary_files) { 4,532 binary = 1; . } . else { 18,128 log_debug("File %s is binary. Skipping...", dir_full_path); 149,556 => /home/geoff/code/the_silver_searcher/src/log.c:log_debug (4532x) 4,532 goto cleanup; . } . } . 49,263 if (opts.literal) { . char *match_ptr = buf; 65,684 char *(*ag_strncmp_fp)(const char*, const char*, size_t, size_t, size_t[]) = &boyer_moore_strnstr; . 32,842 if (opts.casing == CASE_INSENSITIVE) { . ag_strncmp_fp = &boyer_moore_strncasestr; . } 66,122 while (buf_offset < buf_len) { 115,969 match_ptr = ag_strncmp_fp(match_ptr, opts.query, buf_len - buf_offset, opts.query_len, skip_lookup); 63,421,170 => /home/geoff/code/the_silver_searcher/src/util.c:boyer_moore_strnstr (16567x) 115,239 if (match_ptr == NULL) { . break; . } 438 matches[matches_len].start = match_ptr - buf; 438 matches[matches_len].end = matches[matches_len].start + opts.query_len; . buf_offset = matches[matches_len].end; 146 matches_len++; 146 match_ptr++; . /* Don't segfault. TODO: realloc this array */ 292 if (matches_len >= MAX_MATCHES_PER_FILE) { . log_err("Too many matches in %s. Skipping the rest of this file.", dir_full_path); . break; . } . } . } . else { . /* In my profiling, most of the execution time is spent in this pcre_exec */ . while (buf_offset < buf_len && -- line 195 ---------------------------------------- -- line 203 ---------------------------------------- . if (matches_len >= MAX_MATCHES_PER_FILE) { . log_err("Too many matches in %s. Skipping the rest of this file.", dir_full_path); . break; . } . } . } . . 49,263 if (opts.stats) { . total_file_count++; . total_byte_count += buf_len; . } . 32,842 if (rc == -1) { . log_debug("No match in %s", dir_full_path); . } . 32,842 if (matches_len > 0) { 189 if (opts.print_filename_only) { . print_path(dir_full_path); . } . else { 189 if (binary) { . printf("Binary file %s matches.\n", dir_full_path); . } . else { 441 print_file_matches(dir_full_path, buf, buf_len, matches, matches_len); 107,000,414 => /home/geoff/code/the_silver_searcher/src/print.c:print_file_matches (63x) . } . } . } . . cleanup: . if (fd != -1) { 64,407 munmap(buf, f_len); 945 => /build/buildd/eglibc-2.13/elf/../sysdeps/x86_64/dl-trampoline.S:_dl_runtime_resolve (1x) 110,441 => /build/buildd/eglibc-2.13/misc/../sysdeps/unix/syscall-template.S:munmap (21469x) 42,938 close(fd); 902 => /build/buildd/eglibc-2.13/elf/../sysdeps/x86_64/dl-trampoline.S:_dl_runtime_resolve (1x) 150,283 => /build/buildd/eglibc-2.13/io/../sysdeps/unix/syscall-template.S:close (21469x) . fd = -1; . } . 52,722 free(dir); 2,688 => /build/buildd/eglibc-2.13/malloc/malloc.c:free (32x) . dir = NULL; 79,083 free(dir_full_path); 2,673 => /build/buildd/eglibc-2.13/malloc/malloc.c:free (32x) . dir_full_path = NULL; . } . 9,606 free(dir_list); 106 => /build/buildd/eglibc-2.13/malloc/malloc.c:free (1x) 9,606 dir_list = NULL; . return(0); 58,716 } . 5 int main(int argc, char **argv) { 2 set_log_level(LOG_LEVEL_WARN); 2 => /home/geoff/code/the_silver_searcher/src/log.c:set_log_level (1x) . . #ifdef AG_DEBUG . set_log_level(LOG_LEVEL_DEBUG); . int i = 0; . for (i = 0; i < argc; i++) { . fprintf(stderr, "%s ", argv[i]); . } . fprintf(stderr, "\n"); . #endif . 1 char *query = NULL; 1 char *path = NULL; . int pcre_opts = 0; . int study_opts = 0; 1 const char *pcre_err = NULL; 1 int pcre_err_offset = 0; 1 pcre *re = NULL; 1 pcre_extra *re_extra = NULL; . struct timeval time_start, time_end; . double time_diff = 0.0; . 3 gettimeofday(&time_start, NULL); 12 => /build/buildd/eglibc-2.13/time/../sysdeps/unix/sysv/linux/x86_64/gettimeofday.S:gettimeofday (1x) 1,006 => /build/buildd/eglibc-2.13/elf/../sysdeps/x86_64/dl-trampoline.S:_dl_runtime_resolve (1x) . 5 parse_options(argc, argv, &query, &path); 66,315 => /home/geoff/code/the_silver_searcher/src/options.c:parse_options (1x) . 1 if (opts.casing == CASE_INSENSITIVE) { . pcre_opts = pcre_opts | PCRE_CASELESS; . } . 5 log_debug("PCRE Version: %s", pcre_version()); 33 => /home/geoff/code/the_silver_searcher/src/log.c:log_debug (1x) 669 => /build/buildd/eglibc-2.13/elf/../sysdeps/x86_64/dl-trampoline.S:_dl_runtime_resolve (1x) 2 => ???:pcre_version (1x) . 3 if (opts.literal) { 4 generate_skip_lookup(opts.query, opts.query_len, skip_lookup); 1,207 => /home/geoff/code/the_silver_searcher/src/util.c:generate_skip_lookup (1x) . } . else { . re = pcre_compile(query, pcre_opts, &pcre_err, &pcre_err_offset, NULL); . if (re == NULL) { . log_err("pcre_compile failed at position %i. Error: %s", pcre_err_offset, pcre_err); . exit(1); . } . -- line 294 ---------------------------------------- -- line 301 ---------------------------------------- . #endif . re_extra = pcre_study(re, study_opts, &pcre_err); . if (re_extra == NULL) { . log_err("pcre_study failed. Error: %s", pcre_err); . exit(1); . } . } . 5 search_dir(re, re_extra, path, 0); 1,139,229,454 => src/main.c:search_dir (1x) . 3 if (opts.stats) { . gettimeofday(&time_end, NULL); . time_diff = ((long)time_end.tv_sec * 1000000 + time_end.tv_usec) - ((long)time_start.tv_sec * 1000000 + time_start.tv_usec); . time_diff = time_diff / 1000000; . . printf("%ld files\n%ld bytes\n%f seconds\n", total_file_count, total_byte_count, time_diff); . } . 2 pcre_free(re); 9 => /build/buildd/eglibc-2.13/malloc/malloc.c:free (1x) 2 pcre_free(re_extra); /* TODO I'm pretty sure I should call pcre_free_study() here */ 9 => /build/buildd/eglibc-2.13/malloc/malloc.c:free (1x) 2 free(query); 84 => /build/buildd/eglibc-2.13/malloc/malloc.c:free (1x) 2 free(path); 84 => /build/buildd/eglibc-2.13/malloc/malloc.c:free (1x) 2 cleanup_ignore_patterns(); 19,526 => /home/geoff/code/the_silver_searcher/src/ignore.c:cleanup_ignore_patterns (1x) . . return(0); 5 } -------------------------------------------------------------------------------- The following files chosen for auto-annotation could not be found: -------------------------------------------------------------------------------- /build/buildd/eglibc-2.13/dirent/../sysdeps/unix/sysv/linux/getdents.c /build/buildd/eglibc-2.13/posix/../locale/weight.h /build/buildd/eglibc-2.13/string/strcoll_l.c /build/buildd/eglibc-2.13/string/../sysdeps/x86_64/multiarch/../memcpy.S /build/buildd/eglibc-2.13/malloc/malloc.c /build/buildd/eglibc-2.13/dirent/../sysdeps/unix/readdir.c /build/buildd/eglibc-2.13/posix/fnmatch_loop.c /build/buildd/eglibc-2.13/string/../sysdeps/x86_64/multiarch/../strlen.S /build/buildd/eglibc-2.13/string/../sysdeps/x86_64/memchr.S /build/buildd/eglibc-2.13/posix/fnmatch.c /build/buildd/eglibc-2.13/stdlib/msort.c /build/buildd/eglibc-2.13/string/../sysdeps/x86_64/multiarch/../strcmp.S /build/buildd/eglibc-2.13/dirent/../sysdeps/wordsize-64/../../dirent/scandir.c /build/buildd/eglibc-2.13/string/../string/memmove.c -------------------------------------------------------------------------------- Ir -------------------------------------------------------------------------------- 35 percentage of events annotated