Revert "l4p/tcp: introduce tle_tcp_stream_establish() API"
[tldk.git] / lib / libtle_l4p / debug.h
1 /*
2  * Copyright (c) 2016  Intel Corporation.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef _DEBUG_H_
17 #define _DEBUG_H_
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 #define FUNC_SEQ_VERIFY(v) do { \
24         static uint64_t nb_call; \
25         static typeof(v) x; \
26         if (nb_call++ != 0) \
27                 RTE_VERIFY(tcp_seq_leq(x, v)); \
28         x = (v); \
29 } while (0)
30
31 #define FUNC_VERIFY(e, c) do { \
32         static uint64_t nb_call; \
33         if ((e) == 0) \
34                 nb_call++; \
35         else \
36                 nb_call = 0; \
37         RTE_VERIFY(nb_call != (c)); \
38 } while (0)
39
40 #define FUNC_STAT(v, c) do { \
41         static uint64_t nb_call, nb_data; \
42         nb_call++; \
43         nb_data += (v); \
44         if ((nb_call & ((c) - 1)) == 0) { \
45                 printf("%s#%d@%u: nb_call=%lu, avg(" #v ")=%#Lf\n", \
46                         __func__, __LINE__, rte_lcore_id(), nb_call, \
47                         (long double)nb_data / nb_call); \
48                 nb_call = 0; \
49                 nb_data = 0; \
50         } \
51 } while (0)
52
53 #define FUNC_TM_STAT(v, c) do { \
54         static uint64_t nb_call, nb_data; \
55         static uint64_t cts, pts, sts; \
56         cts = rte_rdtsc(); \
57         if (pts != 0) \
58                 sts += cts - pts; \
59         pts = cts; \
60         nb_call++; \
61         nb_data += (v); \
62         if ((nb_call & ((c) - 1)) == 0) { \
63                 printf("%s#%d@%u: nb_call=%lu, " \
64                         "avg(" #v ")=%#Lf, " \
65                         "avg(cycles)=%#Lf, " \
66                         "avg(cycles/" #v ")=%#Lf\n", \
67                         __func__, __LINE__, rte_lcore_id(), nb_call, \
68                         (long double)nb_data / nb_call, \
69                         (long double)sts / nb_call, \
70                         (long double)sts / nb_data); \
71                 nb_call = 0; \
72                 nb_data = 0; \
73                 sts = 0; \
74         } \
75 } while (0)
76
77 #ifdef __cplusplus
78 }
79 #endif
80
81 #endif /* _DEBUG_H_ */