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