aboutsummaryrefslogtreecommitdiff
path: root/crypto.c
diff options
context:
space:
mode:
authorFranklin Wei <me@fwei.tk>2018-08-03 18:51:27 +0000
committerFranklin Wei <me@fwei.tk>2018-08-03 18:51:27 +0000
commit15c809cc72125c149a56eaaa67b6fd546e2302ae (patch)
treea80852bff9d77c0b40ae949fd6c8b7012486def9 /crypto.c
parente33211c2bd96994e6da361239ed8714b8cea32c0 (diff)
downloadcsaa-15c809cc72125c149a56eaaa67b6fd546e2302ae.zip
csaa-15c809cc72125c149a56eaaa67b6fd546e2302ae.tar.gz
csaa-15c809cc72125c149a56eaaa67b6fd546e2302ae.tar.bz2
csaa-15c809cc72125c149a56eaaa67b6fd546e2302ae.tar.xz
Adapt dummy service and client for new profiling method
This moves the profiling code to crypto.c (which should probably be renamed util.c at some point). Test scripts and data processing scripts have been updated as well to deal with the new data.
Diffstat (limited to 'crypto.c')
-rw-r--r--crypto.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/crypto.c b/crypto.c
index 21ca87a..eae8fb8 100644
--- a/crypto.c
+++ b/crypto.c
@@ -524,6 +524,56 @@ void write_file(const char *path, const void *contents, size_t len)
}
}
+/* Profiling */
+void prof_reset(struct server_profile *prof)
+{
+ memset(prof, 0, sizeof(*prof));
+}
+
+void prof_add(struct server_profile *prof, const char *label)
+{
+ if(prof->n_times < MAX_TIMES)
+ {
+ prof->times[prof->n_times] = clock();
+ strcpy(prof->labels[prof->n_times], label);
+
+ prof->n_times++;
+ }
+}
+
+/* The test scripts depend on the output of this function with -p set
+ * (labels = false, labels_only = false). Do not change! */
+void prof_dump(struct server_profile *profile, bool labels, bool labels_only)
+{
+ //for(int i = 0; i < profile->n_times; ++i)
+ //fprintf(stderr, "%s ", profile->labels[i]);
+ //fprintf(stderr, "\n");
+
+ clock_t sum = 0;
+
+ /* TODO: use partial sums? */
+ for(int i = 1; i < profile->n_times; ++i)
+ {
+ if(labels || labels_only)
+ fprintf(stderr, "%s%s", profile->labels[i], !labels_only ? " " : "\n");
+
+ if(!labels_only)
+ fprintf(stderr, "%ld%c", profile->times[i] - profile->times[i - 1],
+ (!labels && !labels_only) ? ' ' : '\n');
+
+ sum += profile->times[i] - profile->times[i - 1];
+ }
+
+ if(!labels && !labels_only)
+ fprintf(stderr, "\n");
+}
+
+void prof_read(int fd, struct server_profile *profile_out)
+{
+ if(profile_out)
+ recv(fd, profile_out, sizeof(*profile_out), MSG_WAITALL);
+}
+
void crypto_test(void)
{
#if 0