Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / common / EventTrace.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2016 Intel Corporation.
7  * All rights reserved.
8  *
9  * Author: Anjaneya Chagam <anjaneya.chagam@intel.com>
10  *
11  * This is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License version 2.1, as published by the Free Software
14  * Foundation.  See file COPYING.
15  *
16  */
17
18 #ifndef _EventTrace_h_
19 #define _EventTrace_h_
20
21 #include "msg/Message.h"
22
23 #if defined(WITH_LTTNG) && defined(WITH_EVENTTRACE)
24
25 #define OID_EVENT_TRACE(oid, event) \
26   EventTrace::trace_oid_event(oid, event, "", __FILE__, __func__, __LINE__)
27 #define OID_EVENT_TRACE_WITH_MSG(msg, event, incl_oid) \
28   EventTrace::trace_oid_event(msg, event, __FILE__, __func__, __LINE__, incl_oid)
29 #define OID_ELAPSED(oid, elapsed, event) \
30   EventTrace::trace_oid_elapsed(oid, event, "", elapsed, __FILE__, __func__, __LINE__)
31 #define OID_ELAPSED_WITH_MSG(m, elapsed, event, incl_oid) \
32   EventTrace::trace_oid_elapsed(m, event, elapsed, __FILE__, __func__, __LINE__, incl_oid)
33 #define FUNCTRACE() EventTrace _t1(g_ceph_context, __FILE__, __func__, __LINE__)
34 #define OID_ELAPSED_FUNC_EVENT(event) _t1.log_event_latency(event)
35
36 #else
37
38 #define OID_EVENT_TRACE(oid, event)
39 #define OID_EVENT_TRACE_WITH_MSG(msg, event, incl_oid)
40 #define OID_ELAPSED(oid, elapsed, event)
41 #define OID_ELAPSED_WITH_MSG(m, elapsed, event, incl_oid)
42 #define FUNCTRACE()
43 #define OID_ELAPSED_FUNC_EVENT(event)
44
45 #endif
46
47 #define LOG_LEVEL 1
48
49 class EventTrace {
50 private:
51   CephContext *ctx;
52   string file;
53   string func;
54   int line;
55   utime_t last_ts;
56
57   static bool tpinit;
58
59   static void init_tp(CephContext *_ctx);
60   static void set_message_attrs(const Message *m, string& oid, string& context, bool incl_oid);
61
62 public:
63
64   EventTrace(CephContext *_ctx, const char *_file, const char *_func, int line);
65   ~EventTrace();
66   void log_event_latency(const char *tag);
67
68   static void trace_oid_event(const char *oid, const char *event, const char *context,
69     const char *file, const char *func, int line);
70   static void trace_oid_event(const Message *m, const char *event, const char *file,
71     const char *func, int line, bool incl_oid);
72
73   static void trace_oid_elapsed(const char *oid, const char *event, const char *context,
74     double elapsed, const char *file, const char *func, int line);
75   static void trace_oid_elapsed(const Message *m, const char *event, double elapsed,
76     const char *file, const char *func, int line, bool incl_oid);
77   
78 };
79 #endif