comparison src/dumpblocks.c @ 360:26c48ea9d896

From Jeffrey Morlan: pst_build_id_ptr reads the Block BTree into a linked list, which pst_getID does a linear scan through. For large PSTs that have millions of blocks, this is extremely slow - almost all time is spent in pst_getID. Since the BTree entries must be in order, this can be dramatically improved by reading into an array and using binary search.
author Carl Byington <carl@five-ten-sg.com>
date Wed, 06 Jul 2016 10:21:08 -0700
parents 201464dd356e
children
comparison
equal deleted inserted replaced
359:a3e674fade6c 360:26c48ea9d896
3 #define OUT_BUF 20 3 #define OUT_BUF 20
4 4
5 int main(int argc, char* const* argv) 5 int main(int argc, char* const* argv)
6 { 6 {
7 pst_file pstfile; 7 pst_file pstfile;
8 pst_index_ll *ptr; 8 size_t i;
9 char *outdir = NULL, *file = NULL, *outname = NULL; 9 char *outdir = NULL, *file = NULL, *outname = NULL;
10 char *buf = NULL; 10 char *buf = NULL;
11 int c; 11 int c;
12 FILE *fp; 12 FILE *fp;
13 13
48 if (chdir(outdir)) { 48 if (chdir(outdir)) {
49 printf("Failed to change into directory %s\n", outdir); 49 printf("Failed to change into directory %s\n", outdir);
50 exit(1); 50 exit(1);
51 } 51 }
52 52
53 ptr = pstfile.i_head;
54 outname = (char *) pst_malloc(OUT_BUF); 53 outname = (char *) pst_malloc(OUT_BUF);
55 printf("Saving blocks\n"); 54 printf("Saving blocks\n");
56 while (ptr != NULL) { 55 for (i = 0; i < pstfile.i_count; i++) {
57 size_t c; 56 pst_index_ll *ptr = &pstfile.i_table[i];
58 c = pst_ff_getIDblock_dec(&pstfile, ptr->i_id, &buf); 57 size_t c = pst_ff_getIDblock_dec(&pstfile, ptr->i_id, &buf);
59 if (c) { 58 if (c) {
60 snprintf(outname, OUT_BUF, "%#"PRIx64, ptr->i_id); 59 snprintf(outname, OUT_BUF, "%#"PRIx64, ptr->i_id);
61 if ((fp = fopen(outname, "wb")) == NULL) { 60 if ((fp = fopen(outname, "wb")) == NULL) {
62 printf("Failed to open file %s\n", outname); 61 printf("Failed to open file %s\n", outname);
63 continue; 62 continue;
65 pst_fwrite(buf, 1, c, fp); 64 pst_fwrite(buf, 1, c, fp);
66 fclose(fp); 65 fclose(fp);
67 } else { 66 } else {
68 printf("Failed to read block i_id %#"PRIx64"\n", ptr->i_id); 67 printf("Failed to read block i_id %#"PRIx64"\n", ptr->i_id);
69 } 68 }
70 ptr = ptr->next;
71 } 69 }
72 pst_close(&pstfile); 70 pst_close(&pstfile);
73 DEBUG_RET(); 71 DEBUG_RET();
74 return 0; 72 return 0;
75 } 73 }