]> git.proxmox.com Git - ceph.git/blob - ceph/src/common/EventTrace.h
add subtree-ish sources for 12.0.3
[ceph.git] / 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 <string>
22 #include "msg/Message.h"
23 #include "common/ceph_context.h"
24
25 #if defined(WITH_LTTNG) && defined(WITH_EVENTTRACE)
26
27 #define OID_EVENT_TRACE(oid, event) \
28 EventTrace::trace_oid_event(oid, event, "", __FILE__, __func__, __LINE__)
29 #define OID_EVENT_TRACE_WITH_MSG(msg, event, incl_oid) \
30 EventTrace::trace_oid_event(msg, event, __FILE__, __func__, __LINE__, incl_oid)
31 #define OID_ELAPSED(oid, elapsed, event) \
32 EventTrace::trace_oid_elapsed(oid, event, "", elapsed, __FILE__, __func__, __LINE__)
33 #define OID_ELAPSED_WITH_MSG(m, elapsed, event, incl_oid) \
34 EventTrace::trace_oid_elapsed(m, event, elapsed, __FILE__, __func__, __LINE__, incl_oid)
35 #define FUNCTRACE() EventTrace _t1(g_ceph_context, __FILE__, __func__, __LINE__)
36 #define OID_ELAPSED_FUNC_EVENT(event) _t1.log_event_latency(event)
37
38 #else
39
40 #define OID_EVENT_TRACE(oid, event)
41 #define OID_EVENT_TRACE_WITH_MSG(msg, event, incl_oid)
42 #define OID_ELAPSED(oid, elapsed, event)
43 #define OID_ELAPSED_WITH_MSG(m, elapsed, event, incl_oid)
44 #define FUNCTRACE()
45 #define OID_ELAPSED_FUNC_EVENT(event)
46
47 #endif
48
49 #define LOG_LEVEL 1
50
51 class EventTrace {
52 private:
53 CephContext *ctx;
54 string file;
55 string func;
56 int line;
57 utime_t last_ts;
58
59 static bool tpinit;
60
61 static void init_tp(CephContext *_ctx);
62 static void set_message_attrs(const Message *m, string& oid, string& context, bool incl_oid);
63
64 public:
65
66 EventTrace(CephContext *_ctx, const char *_file, const char *_func, int line);
67 ~EventTrace();
68 void log_event_latency(const char *tag);
69
70 static void trace_oid_event(const char *oid, const char *event, const char *context,
71 const char *file, const char *func, int line);
72 static void trace_oid_event(const Message *m, const char *event, const char *file,
73 const char *func, int line, bool incl_oid);
74
75 static void trace_oid_elapsed(const char *oid, const char *event, const char *context,
76 double elapsed, const char *file, const char *func, int line);
77 static void trace_oid_elapsed(const Message *m, const char *event, double elapsed,
78 const char *file, const char *func, int line, bool incl_oid);
79
80 };
81 #endif