-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscancvm.c
More file actions
89 lines (70 loc) · 1.95 KB
/
scancvm.c
File metadata and controls
89 lines (70 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* scancvm.c: Scan the content of the CVM database and print statistics
*
* Copyright (c) 2005 Tiankai Tu
* All rights reserved. May not be used, modified, or copied
* without permission.
*
* Contact:
* Tiankai Tu
* Computer Science Department
* Carnegie Mellon University
* 5000 Forbes Avenue
* Pittsburgh, PA 15213
* tutk@cs.cmu.edu
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include "etree.h"
#include "cvm.h"
#define KEYSIZE 13
int main(int argc, char **argv)
{
char * cvmetree;
etree_t *cvmEp;
cvmpayload_t rawElem;
int64_t totalcount;
int32_t mycount;
struct timeval starttime, endtime;
int scantime;
if (argc != 2) {
printf("\nusage: scancvm cvmetree\n");
exit(1);
}
cvmetree = argv[1];
cvmEp = etree_open(cvmetree, O_RDONLY, 0, 0, 0);
if (!cvmEp) {
fprintf(stderr, "Cannot open CVM material database %s\n", cvmetree);
exit(1);
}
/* go through all the records stored in the underlying btree */
totalcount = 0;
mycount = 0;
memset(cvmEp->key, 0, KEYSIZE);
gettimeofday(&starttime, NULL);
if (btree_initcursor(cvmEp->bp, cvmEp->key) != 0) {
fprintf(stderr, "Cannot set cursor in the underlying database\n");
exit(1);
}
do {
if (btree_getcursor(cvmEp->bp, cvmEp->hitkey, "*", &rawElem) != 0) {
fprintf(stderr, "Read cursor error\n");
exit(1);
}
totalcount++;
mycount++;
if (mycount == 1000000) {
fprintf(stderr, "1 million records scanned\n");
mycount = 0;
}
} while (btree_advcursor(cvmEp->bp) == 0);
gettimeofday(&endtime, NULL);
scantime = (endtime.tv_sec - starttime.tv_sec);
printf("Scanned the CVM database in %d seconds\n", scantime);
printf("Scanned %qd octants\n", totalcount);
etree_close(cvmEp);
return 0;
}