Motr  M0
trace.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2011-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #include "lib/misc.h" /* M0_SET0 */
24 #include "lib/ub.h"
25 #include "ut/ut.h"
26 #include "lib/thread.h"
27 #include "lib/assert.h"
28 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_UT
29 #include "lib/trace.h"
30 
31 enum {
32  NR = 16,
33  NR_INNER = 100000
34 };
35 
36 static struct m0_thread t[NR];
37 
38 void trace_thread_func(int d)
39 {
40  int j;
41 
42  for (j = 0; j < NR_INNER; ++j)
43  M0_LOG(M0_DEBUG, "d: %i, d*j: %i", d, d * j);
44 }
45 
46 void test_trace(void)
47 {
48  int i;
49  int result;
50  uint64_t u64;
51 
52  M0_LOG(M0_DEBUG, "forty two: %i", 42);
53  M0_LOG(M0_DEBUG, "forty three and tree: %i %llu", 43,
54  (unsigned long long)(u64 = 3));
55  for (i = 0; i < NR_INNER; ++i)
56  M0_LOG(M0_DEBUG, "c: %i, d: %i", i, i*i);
57 
58  M0_SET_ARR0(t);
59  for (i = 0; i < NR; ++i) {
60  result = M0_THREAD_INIT(&t[i], int, NULL, &trace_thread_func,
61  i, "test_trace_%i", i);
62  M0_ASSERT(result == 0);
63  }
64  for (i = 0; i < NR; ++i) {
65  m0_thread_join(&t[i]);
66  m0_thread_fini(&t[i]);
67  }
68  M0_LOG(M0_DEBUG, "X: %i and Y: %i", 43, result + 1);
69  M0_LOG(M0_DEBUG, "%llx char: %c %llx string: %s",
70  0x1234567887654321ULL,
71  'c',
72  0xfefefefefefefefeULL,
73  (char *)"foobar");
74 }
75 
76 enum {
77  UB_ITER = 5000000
78 };
79 
80 static void ub_empty(int i)
81 {
82  M0_LOG(M0_DEBUG, "msg");
83 }
84 
85 static void ub_8(int i)
86 {
87  M0_LOG(M0_DEBUG, "%i", i);
88 }
89 
90 static void ub_64(int i)
91 {
92  M0_LOG(M0_DEBUG, "%i %i %i %i %i %i %i %i",
93  i, i + 1, i + 2, i + 3, i + 4, i + 5,
94  i + 6, i + 7);
95 }
96 
98  .us_name = "trace-ub",
99  .us_run = {
100  { .ub_name = "empty",
101  .ub_iter = UB_ITER,
102  .ub_round = ub_empty },
103 
104  { .ub_name = "8",
105  .ub_iter = UB_ITER,
106  .ub_round = ub_8 },
107 
108  { .ub_name = "64",
109  .ub_iter = UB_ITER,
110  .ub_round = ub_64 },
111 
112  { .ub_name = NULL }
113  }
114 };
115 
116 /*
117  * Local variables:
118  * c-indentation-style: "K&R"
119  * c-basic-offset: 8
120  * tab-width: 8
121  * fill-column: 80
122  * scroll-step: 1
123  * End:
124  */
#define NULL
Definition: misc.h:38
static void ub_empty(int i)
Definition: trace.c:80
int m0_thread_join(struct m0_thread *q)
Definition: kthread.c:169
#define M0_LOG(level,...)
Definition: trace.h:167
static void ub_8(int i)
Definition: trace.c:85
#define M0_THREAD_INIT(thread, TYPE, init, func, arg, namefmt,...)
Definition: thread.h:139
Definition: trace.c:32
int i
Definition: dir.c:1033
#define M0_SET_ARR0(arr)
Definition: misc.h:72
#define M0_ASSERT(cond)
struct m0_ub_set m0_trace_ub
Definition: trace.c:97
static struct m0_thread t[NR]
Definition: trace.c:36
const char * us_name
Definition: ub.h:76
void m0_thread_fini(struct m0_thread *q)
Definition: thread.c:92
Definition: trace.c:33
void trace_thread_func(int d)
Definition: trace.c:38
void test_trace(void)
Definition: trace.c:46
Definition: trace.c:77
Definition: ub.h:74
static void ub_64(int i)
Definition: trace.c:90