j = download_get_result (&job->db,
job->easy_handle,
&response_code);
+#if ENABLE_BENCHMARK
+ {
+ char *url = NULL;
+ double total = 0;
+ struct UrlRequestData *urd;
+ CURLcode res;
+ res = curl_easy_getinfo (cmsg->easy_handle, CURLINFO_TOTAL_TIME, &total);
+ GNUNET_break (CURLE_OK == res);
+ curl_easy_getinfo (cmsg->easy_handle, CURLINFO_EFFECTIVE_URL, &url);
+ urd = get_url_benchmark_data (url);
+ urd->count++;
+ urd->time.rel_value_us += total * 1000 * 1000;
+ }
+#endif
job->jcc (job->jcc_cls,
response_code,
j);
GNUNET_assert (GNUNET_SYSERR != GNUNET_DISK_file_write_blocking (fh, s, strlen (s)));
GNUNET_free (s);
+ GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
+
+ GNUNET_asprintf (&s, "gnunet-benchmark-urls-%llu-%llu.txt",
+ (unsigned long long) pid,
+ (unsigned long long) tid);
+
+ fh = GNUNET_DISK_file_open (s,
+ (GNUNET_DISK_OPEN_WRITE |
+ GNUNET_DISK_OPEN_TRUNCATE |
+ GNUNET_DISK_OPEN_CREATE),
+ (GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE));
+ GNUNET_assert (NULL != fh);
+ GNUNET_free (s);
+
+ for (unsigned int i = 0; i < bd->urd_len; i++)
+ {
+ struct UrlRequestData *urd = &bd->urd[i];
+ GNUNET_asprintf (&s, "url %s count %lld time_us %lld\n",
+ urd->request_url,
+ (unsigned long long) urd->count,
+ (unsigned long long) urd->time.rel_value_us);
+ GNUNET_assert (GNUNET_SYSERR != GNUNET_DISK_file_write_blocking (fh, s, strlen (s)));
+ GNUNET_free (s);
+ }
+
+
GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
}
}
return bd;
}
+
+
+/**
+ * Get benchmark data for a URL. If the URL is too long, it's truncated
+ * before looking up the correspoding benchmark data.
+ *
+ * @param url url to get request data for
+ */
+struct UrlRequestData *
+get_url_benchmark_data (char *url)
+{
+ char trunc[MAX_BENCHMARK_URL_LEN];
+ struct BenchmarkData *bd;
+
+ memcpy (trunc, url, MAX_BENCHMARK_URL_LEN);
+ trunc[MAX_BENCHMARK_URL_LEN - 1] = 0;
+
+ bd = get_benchmark_data ();
+
+ for (unsigned int i = 0; i < bd->urd_len; i++)
+ {
+ if (0 == strcmp (trunc, bd->urd[i].request_url))
+ return &bd->urd[i];
+ }
+
+ {
+ struct UrlRequestData urd = { 0 };
+
+ memcpy (&urd.request_url, trunc, MAX_BENCHMARK_URL_LEN);
+
+ if (bd->urd_len == bd->urd_capacity)
+ {
+ bd->urd_capacity = 2 * (bd->urd_capacity + 1);
+ bd->urd = GNUNET_realloc (bd->urd, bd->urd_capacity * sizeof (struct UrlRequestData));
+ }
+
+ bd->urd[bd->urd_len++] = urd;
+ return &bd->urd[bd->urd_len - 1];
+ }
+}
#include "gnunet_time_lib.h"
+/**
+ * Maximum length of URLs considered for benchmarking.
+ * Shorter URLs are simply truncated.
+ */
+#define MAX_BENCHMARK_URL_LEN 128
+
+
+/**
+ * Struct for benchmark data for one URL.
+ */
+struct UrlRequestData
+{
+ /**
+ * Request URL, truncated (but 0-terminated).
+ */
+ char request_url[MAX_BENCHMARK_URL_LEN];
+
+ /**
+ * How often was the URL requested?
+ */
+ uint64_t count;
+
+ /**
+ * Total time spent requesting this URL.
+ */
+ struct GNUNET_TIME_Relative time;
+
+ /**
+ * Slowest time to response.
+ */
+ struct GNUNET_TIME_Relative time_max;
+
+ /**
+ * Fastest time to response.
+ */
+ struct GNUNET_TIME_Relative time_min;
+};
+
/**
* Thread-local struct for benchmarking data.
*/
-struct BenchmarkData {
+struct BenchmarkData
+{
/**
* Number of eddsa_sign operations.
*/
* Time spent in eddsa_sign.
*/
struct GNUNET_TIME_Relative eddsa_sign_time;
+
+ struct UrlRequestData *urd;
+
+ unsigned int urd_len;
+
+ unsigned int urd_capacity;
};
struct BenchmarkData *
get_benchmark_data (void);
+/**
+ * Get benchmark data for a URL. If the URL is too long, it's truncated
+ * before looking up the correspoding benchmark data.
+ *
+ * @param url url to get request data for
+ */
+struct UrlRequestData *
+get_url_benchmark_data (char *url);
+
#endif /* BENCHMARK_H_ */