Merge master branch
[lttng-tools.git] / benchmark / bench-sessions.c
CommitLineData
3c6bae61
DG
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 */
38int opt_quiet = 1;
39int opt_verbose = 0;
40
41static const char alphanum[] =
42 "0123456789"
43 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
44 "abcdefghijklmnopqrstuvwxyz";
45
46/*
47 * Return random string of 10 characters.
48 */
49static 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
63int main(int argc, char **argv)
64{
65 int ret, i, nb_iter;
66 char **names;
67 double value, total = 0;
8f11f9f6 68 struct ltt_session *session;
3c6bae61
DG
69
70 if (getuid() != 0) {
71 printf("Aborting test. Must be uid 0 to drop_caches\n");
72 return 1;
73 }
74
75 if (argc < 2) {
76 printf("Missing arguments\n");
77 return 1;
78 }
79
80 nb_iter = atoi(argv[1]);
81
82 names = malloc(sizeof(char*) * nb_iter);
83
84 srand(time(NULL));
85 bench_init();
86
87 fprintf(fp, "--- Create tracing session ---\n");
88 for (i = 0; i < nb_iter; i++) {
89 names[i] = get_random_string();
90 ret = system("echo 3 >/proc/sys/vm/drop_caches");
91 tracepoint(create_session_start);
8915fb60 92 ret = session_create(names[i], PATH1);
3c6bae61
DG
93 tracepoint(create_session_end);
94 if (ret < 0) {
95 printf("Create session went wrong. Aborting\n");
96 goto error;
97 }
98 value = bench_get_create_session();
99 fprintf(fp, "%.20f\n", value);
100 total += value;
101 }
102
103 fprintf(fp, "--> Average: %.20f\n\n", total/nb_iter);
104 total = 0;
105
106 fprintf(fp, "--- Destroy tracing session ---\n");
107 for (i = 0; i < nb_iter; i++) {
8f11f9f6 108 session = session_find_by_name(names[i]);
3c6bae61
DG
109 ret = system("echo 3 >/proc/sys/vm/drop_caches");
110 tracepoint(destroy_session_start);
8f11f9f6 111 ret = session_destroy(session);
3c6bae61
DG
112 tracepoint(destroy_session_end);
113 if (ret < 0) {
114 printf("Destroy session went wrong. Aborting\n");
115 goto error;
116 }
117 value = bench_get_destroy_session();
118 fprintf(fp, "%.20f\n", value);
119 total += value;
120 free(names[i]);
121 }
122 fprintf(fp, "--> Average: %.20f\n\n", total/nb_iter);
123
124 /* Success */
125 bench_close();
126 return 0;
127
128error:
129 bench_close();
130 free(names);
131
132 return 1;
133}
This page took 0.031651 seconds and 4 git commands to generate.