Merge branch 'master' into benchmark
[lttng-tools.git] / benchmark / bench-sessions.c
1 /*
2 * Copyright (c) 2011 David Goulet <david.goulet@polymtl.ca>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * as published by the Free Software Foundation; only version 2
7 * of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #define _GNU_SOURCE
20 #include <assert.h>
21 #include <errno.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <time.h>
27
28 #include "ltt-sessiond/session.h"
29 #include "utils.h"
30 #include "benchmark.h"
31
32 #define SESSION1 "test1"
33
34 /* This path will NEVER be created in this test */
35 #define PATH1 "/tmp/.test-junk-lttng"
36
37 /* For lttngerr.h */
38 int opt_quiet = 1;
39 int opt_verbose = 0;
40
41 static const char alphanum[] =
42 "0123456789"
43 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
44 "abcdefghijklmnopqrstuvwxyz";
45
46 /*
47 * Return random string of 10 characters.
48 */
49 static char *get_random_string(void)
50 {
51 int i;
52 char *str = malloc(11);
53
54 for (i = 0; i < 10; i++) {
55 str[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
56 }
57
58 str[10] = '\0';
59
60 return str;
61 }
62
63 int main(int argc, char **argv)
64 {
65 int ret, i, nb_iter;
66 char **names;
67 double value, total = 0;
68
69 if (getuid() != 0) {
70 printf("Aborting test. Must be uid 0 to drop_caches\n");
71 return 1;
72 }
73
74 if (argc < 2) {
75 printf("Missing arguments\n");
76 return 1;
77 }
78
79 nb_iter = atoi(argv[1]);
80
81 names = malloc(sizeof(char*) * nb_iter);
82
83 srand(time(NULL));
84 bench_init();
85
86 fprintf(fp, "--- Create tracing session ---\n");
87 for (i = 0; i < nb_iter; i++) {
88 names[i] = get_random_string();
89 ret = system("echo 3 >/proc/sys/vm/drop_caches");
90 tracepoint(create_session_start);
91 ret = session_create(names[i], PATH1);
92 tracepoint(create_session_end);
93 if (ret < 0) {
94 printf("Create session went wrong. Aborting\n");
95 goto error;
96 }
97 value = bench_get_create_session();
98 fprintf(fp, "%.20f\n", value);
99 total += value;
100 }
101
102 fprintf(fp, "--> Average: %.20f\n\n", total/nb_iter);
103 total = 0;
104
105 fprintf(fp, "--- Destroy tracing session ---\n");
106 for (i = 0; i < nb_iter; i++) {
107 ret = system("echo 3 >/proc/sys/vm/drop_caches");
108 tracepoint(destroy_session_start);
109 ret = session_destroy(names[i]);
110 tracepoint(destroy_session_end);
111 if (ret < 0) {
112 printf("Destroy session went wrong. Aborting\n");
113 goto error;
114 }
115 value = bench_get_destroy_session();
116 fprintf(fp, "%.20f\n", value);
117 total += value;
118 free(names[i]);
119 }
120 fprintf(fp, "--> Average: %.20f\n\n", total/nb_iter);
121
122 /* Success */
123 bench_close();
124 return 0;
125
126 error:
127 bench_close();
128 free(names);
129
130 return 1;
131 }
This page took 0.051705 seconds and 4 git commands to generate.