diff options
Diffstat (limited to 'src/datacache/perf_datacache.c')
-rw-r--r-- | src/datacache/perf_datacache.c | 140 |
1 files changed, 74 insertions, 66 deletions
diff --git a/src/datacache/perf_datacache.c b/src/datacache/perf_datacache.c index b470ceaa6..1656ac91c 100644 --- a/src/datacache/perf_datacache.c +++ b/src/datacache/perf_datacache.c | |||
@@ -29,7 +29,9 @@ | |||
29 | #include <gauger.h> | 29 | #include <gauger.h> |
30 | 30 | ||
31 | 31 | ||
32 | #define ASSERT(x) do { if (!(x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE; } } while (0) | 32 | #define ASSERT(x) do { if (! (x)) { printf ("Error at %s:%d\n", __FILE__, \ |
33 | __LINE__); goto FAILURE; \ | ||
34 | } } while (0) | ||
33 | 35 | ||
34 | #define ITERATIONS 10000 | 36 | #define ITERATIONS 10000 |
35 | 37 | ||
@@ -44,22 +46,23 @@ static const char *plugin_name; | |||
44 | 46 | ||
45 | 47 | ||
46 | static int | 48 | static int |
47 | checkIt(void *cls, | 49 | checkIt (void *cls, |
48 | const struct GNUNET_HashCode * key, size_t size, const char *data, | 50 | const struct GNUNET_HashCode *key, size_t size, const char *data, |
49 | enum GNUNET_BLOCK_Type type, | 51 | enum GNUNET_BLOCK_Type type, |
50 | struct GNUNET_TIME_Absolute exp, | 52 | struct GNUNET_TIME_Absolute exp, |
51 | unsigned int path_len, | 53 | unsigned int path_len, |
52 | const struct GNUNET_PeerIdentity *path) | 54 | const struct GNUNET_PeerIdentity *path) |
53 | { | 55 | { |
54 | if ((size == sizeof(struct GNUNET_HashCode)) && (0 == memcmp(data, cls, size))) | 56 | if ((size == sizeof(struct GNUNET_HashCode)) && (0 == memcmp (data, cls, |
57 | size))) | ||
55 | found++; | 58 | found++; |
56 | return GNUNET_OK; | 59 | return GNUNET_OK; |
57 | } | 60 | } |
58 | 61 | ||
59 | 62 | ||
60 | static void | 63 | static void |
61 | run(void *cls, char *const *args, const char *cfgfile, | 64 | run (void *cls, char *const *args, const char *cfgfile, |
62 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 65 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
63 | { | 66 | { |
64 | struct GNUNET_DATACACHE_Handle *h; | 67 | struct GNUNET_DATACACHE_Handle *h; |
65 | struct GNUNET_HashCode k; | 68 | struct GNUNET_HashCode k; |
@@ -70,67 +73,72 @@ run(void *cls, char *const *args, const char *cfgfile, | |||
70 | char gstr[128]; | 73 | char gstr[128]; |
71 | 74 | ||
72 | ok = 0; | 75 | ok = 0; |
73 | h = GNUNET_DATACACHE_create(cfg, "perfcache"); | 76 | h = GNUNET_DATACACHE_create (cfg, "perfcache"); |
74 | 77 | ||
75 | if (h == NULL) | 78 | if (h == NULL) |
76 | { | 79 | { |
77 | fprintf(stderr, "%s", "Failed to initialize datacache. Database likely not setup, skipping test.\n"); | 80 | fprintf (stderr, "%s", |
78 | ok = 77; /* mark test as skipped */ | 81 | "Failed to initialize datacache. Database likely not setup, skipping test.\n"); |
79 | return; | 82 | ok = 77; /* mark test as skipped */ |
80 | } | 83 | return; |
81 | exp = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS); | 84 | } |
82 | start = GNUNET_TIME_absolute_get(); | 85 | exp = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS); |
83 | memset(&k, 0, sizeof(struct GNUNET_HashCode)); | 86 | start = GNUNET_TIME_absolute_get (); |
87 | memset (&k, 0, sizeof(struct GNUNET_HashCode)); | ||
84 | for (i = 0; i < ITERATIONS; i++) | 88 | for (i = 0; i < ITERATIONS; i++) |
85 | { | 89 | { |
86 | if (0 == i % (ITERATIONS / 80)) | 90 | if (0 == i % (ITERATIONS / 80)) |
87 | fprintf(stderr, "%s", "."); | 91 | fprintf (stderr, "%s", "."); |
88 | GNUNET_CRYPTO_hash(&k, sizeof(struct GNUNET_HashCode), &n); | 92 | GNUNET_CRYPTO_hash (&k, sizeof(struct GNUNET_HashCode), &n); |
89 | ASSERT(GNUNET_OK == | 93 | ASSERT (GNUNET_OK == |
90 | GNUNET_DATACACHE_put(h, &k, sizeof(struct GNUNET_HashCode), | 94 | GNUNET_DATACACHE_put (h, &k, sizeof(struct GNUNET_HashCode), |
91 | (const char *)&n, 1 + i % 16, exp, | 95 | (const char *) &n, 1 + i % 16, exp, |
92 | 0, NULL)); | 96 | 0, NULL)); |
93 | k = n; | 97 | k = n; |
94 | } | 98 | } |
95 | fprintf(stderr, "%s", "\n"); | 99 | fprintf (stderr, "%s", "\n"); |
96 | fprintf(stdout, "Stored %u items in %s\n", ITERATIONS, | 100 | fprintf (stdout, "Stored %u items in %s\n", ITERATIONS, |
97 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration(start), GNUNET_YES)); | 101 | GNUNET_STRINGS_relative_time_to_string ( |
98 | GNUNET_snprintf(gstr, sizeof(gstr), "DATACACHE-%s", plugin_name); | 102 | GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); |
99 | GAUGER(gstr, "Time to PUT item in datacache", | 103 | GNUNET_snprintf (gstr, sizeof(gstr), "DATACACHE-%s", plugin_name); |
100 | GNUNET_TIME_absolute_get_duration(start).rel_value_us / 1000LL / ITERATIONS, | 104 | GAUGER (gstr, "Time to PUT item in datacache", |
101 | "ms/item"); | 105 | GNUNET_TIME_absolute_get_duration (start).rel_value_us / 1000LL |
102 | start = GNUNET_TIME_absolute_get(); | 106 | / ITERATIONS, |
103 | memset(&k, 0, sizeof(struct GNUNET_HashCode)); | 107 | "ms/item"); |
108 | start = GNUNET_TIME_absolute_get (); | ||
109 | memset (&k, 0, sizeof(struct GNUNET_HashCode)); | ||
104 | for (i = 0; i < ITERATIONS; i++) | 110 | for (i = 0; i < ITERATIONS; i++) |
105 | { | 111 | { |
106 | if (0 == i % (ITERATIONS / 80)) | 112 | if (0 == i % (ITERATIONS / 80)) |
107 | fprintf(stderr, "%s", "."); | 113 | fprintf (stderr, "%s", "."); |
108 | GNUNET_CRYPTO_hash(&k, sizeof(struct GNUNET_HashCode), &n); | 114 | GNUNET_CRYPTO_hash (&k, sizeof(struct GNUNET_HashCode), &n); |
109 | GNUNET_DATACACHE_get(h, &k, 1 + i % 16, &checkIt, &n); | 115 | GNUNET_DATACACHE_get (h, &k, 1 + i % 16, &checkIt, &n); |
110 | k = n; | 116 | k = n; |
111 | } | 117 | } |
112 | fprintf(stderr, "%s", "\n"); | 118 | fprintf (stderr, "%s", "\n"); |
113 | fprintf(stdout, | 119 | fprintf (stdout, |
114 | "Found %u/%u items in %s (%u were deleted during storage processing)\n", | 120 | "Found %u/%u items in %s (%u were deleted during storage processing)\n", |
115 | found, ITERATIONS, | 121 | found, ITERATIONS, |
116 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration(start), GNUNET_YES), | 122 | GNUNET_STRINGS_relative_time_to_string ( |
117 | ITERATIONS - found); | 123 | GNUNET_TIME_absolute_get_duration (start), GNUNET_YES), |
124 | ITERATIONS - found); | ||
118 | if (found > 0) | 125 | if (found > 0) |
119 | GAUGER(gstr, "Time to GET item from datacache", | 126 | GAUGER (gstr, "Time to GET item from datacache", |
120 | GNUNET_TIME_absolute_get_duration(start).rel_value_us / 1000LL / found, | 127 | GNUNET_TIME_absolute_get_duration (start).rel_value_us / 1000LL |
121 | "ms/item"); | 128 | / found, |
122 | GNUNET_DATACACHE_destroy(h); | 129 | "ms/item"); |
123 | ASSERT(ok == 0); | 130 | GNUNET_DATACACHE_destroy (h); |
131 | ASSERT (ok == 0); | ||
124 | return; | 132 | return; |
125 | FAILURE: | 133 | FAILURE: |
126 | if (h != NULL) | 134 | if (h != NULL) |
127 | GNUNET_DATACACHE_destroy(h); | 135 | GNUNET_DATACACHE_destroy (h); |
128 | ok = GNUNET_SYSERR; | 136 | ok = GNUNET_SYSERR; |
129 | } | 137 | } |
130 | 138 | ||
131 | 139 | ||
132 | int | 140 | int |
133 | main(int argc, char *argv[]) | 141 | main (int argc, char *argv[]) |
134 | { | 142 | { |
135 | char cfg_name[PATH_MAX]; | 143 | char cfg_name[PATH_MAX]; |
136 | char *const xargv[] = { | 144 | char *const xargv[] = { |
@@ -143,16 +151,16 @@ main(int argc, char *argv[]) | |||
143 | GNUNET_GETOPT_OPTION_END | 151 | GNUNET_GETOPT_OPTION_END |
144 | }; | 152 | }; |
145 | 153 | ||
146 | GNUNET_log_setup("perf-datacache", | 154 | GNUNET_log_setup ("perf-datacache", |
147 | "WARNING", | 155 | "WARNING", |
148 | NULL); | 156 | NULL); |
149 | plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); | 157 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); |
150 | GNUNET_snprintf(cfg_name, sizeof(cfg_name), "perf_datacache_data_%s.conf", | 158 | GNUNET_snprintf (cfg_name, sizeof(cfg_name), "perf_datacache_data_%s.conf", |
151 | plugin_name); | 159 | plugin_name); |
152 | GNUNET_PROGRAM_run((sizeof(xargv) / sizeof(char *)) - 1, xargv, | 160 | GNUNET_PROGRAM_run ((sizeof(xargv) / sizeof(char *)) - 1, xargv, |
153 | "perf-datacache", "nohelp", options, &run, NULL); | 161 | "perf-datacache", "nohelp", options, &run, NULL); |
154 | if ((0 != ok) && (77 != ok)) | 162 | if ((0 != ok) && (77 != ok)) |
155 | fprintf(stderr, "Missed some perfcases: %d\n", ok); | 163 | fprintf (stderr, "Missed some perfcases: %d\n", ok); |
156 | return ok; | 164 | return ok; |
157 | } | 165 | } |
158 | 166 | ||