]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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) 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 | #include "common/EventTrace.h" | |
7c673cae | 19 | #include "common/TracepointProvider.h" |
7c673cae | 20 | #include "messages/MOSDOpReply.h" |
7c673cae FG |
21 | |
22 | #ifdef WITH_LTTNG | |
23 | #define TRACEPOINT_DEFINE | |
24 | #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE | |
25 | #include "tracing/eventtrace.h" | |
26 | #undef TRACEPOINT_PROBE_DYNAMIC_LINKAGE | |
27 | #undef TRACEPOINT_DEFINE | |
28 | #else | |
29 | #define tracepoint(...) | |
30 | #endif | |
31 | ||
32 | TracepointProvider::Traits event_tracepoint_traits("libeventtrace_tp.so", "event_tracing"); | |
33 | bool EventTrace::tpinit = false; | |
34 | ||
35 | void EventTrace::init_tp(CephContext *_ctx) | |
36 | { | |
37 | if (unlikely(!_ctx)) | |
38 | return; | |
39 | ||
40 | if (unlikely(!tpinit)) { | |
41 | TracepointProvider::initialize<event_tracepoint_traits>(_ctx); | |
42 | tpinit = true; | |
43 | } | |
44 | } | |
45 | ||
46 | void EventTrace::set_message_attrs(const Message *m, string& oid, string& context, bool incl_oid) | |
47 | { | |
48 | // arg1 = oid, arg2 = message type, arg3 = source!source_addr!tid!sequence | |
49 | if (m && (m->get_type() == CEPH_MSG_OSD_OP || m->get_type() == CEPH_MSG_OSD_OPREPLY)) { | |
50 | if (incl_oid) { | |
51 | if (m->get_type() == CEPH_MSG_OSD_OP) | |
52 | oid = ((MOSDOp *)m)->get_oid().name; | |
53 | else | |
54 | oid = ((MOSDOpReply *)m)->get_oid().name; | |
55 | } | |
56 | ||
57 | ostringstream buf; | |
58 | buf << m->get_source() << "!" << m->get_source_addr() << "!" | |
11fdf7f2 | 59 | << m->get_tid() << "!" << m->get_seq() << "!" << m->get_type(); |
7c673cae FG |
60 | context = buf.str(); |
61 | } | |
62 | } | |
63 | ||
64 | EventTrace::EventTrace(CephContext *_ctx, const char *_file, const char *_func, int _line) : | |
65 | ctx(_ctx), | |
66 | file(_file), | |
67 | func(_func), | |
68 | line(_line) | |
69 | { | |
70 | if (unlikely(!ctx)) | |
71 | return; | |
72 | last_ts = ceph_clock_now(); | |
73 | init_tp(ctx); | |
74 | ||
75 | lsubdout(ctx, eventtrace, LOG_LEVEL) << "ENTRY (" << func << ") " << file << ":" << line << dendl; | |
76 | tracepoint(eventtrace, func_enter, file.c_str(), func.c_str(), line); | |
77 | } | |
78 | ||
79 | EventTrace::~EventTrace() | |
80 | { | |
81 | if (unlikely(!ctx)) | |
82 | return; | |
83 | lsubdout(ctx, eventtrace, LOG_LEVEL) << "EXIT (" << func << ") " << file << dendl; | |
84 | tracepoint(eventtrace, func_exit, file.c_str(), func.c_str()); | |
85 | } | |
86 | ||
87 | void EventTrace::log_event_latency(const char *event) | |
88 | { | |
89 | utime_t now = ceph_clock_now(); | |
90 | double usecs = (now.to_nsec()-last_ts.to_nsec())/1000; | |
91 | OID_ELAPSED("", usecs, event); | |
92 | last_ts = now; | |
93 | } | |
94 | ||
95 | void EventTrace::trace_oid_event(const char *oid, const char *event, const char *context, | |
96 | const char *file, const char *func, int line) | |
97 | { | |
98 | if (unlikely(!g_ceph_context)) | |
99 | return; | |
100 | init_tp(g_ceph_context); | |
101 | tracepoint(eventtrace, oid_event, oid, event, context, file, func, line); | |
102 | } | |
103 | ||
104 | void EventTrace::trace_oid_event(const Message *m, const char *event, const char *file, | |
105 | const char *func, int line, bool incl_oid) | |
106 | { | |
107 | string oid, context; | |
108 | set_message_attrs(m, oid, context, incl_oid); | |
109 | trace_oid_event(oid.c_str(), event, context.c_str(), file, func, line); | |
110 | } | |
111 | ||
112 | void EventTrace::trace_oid_elapsed(const char *oid, const char *event, const char *context, | |
113 | double elapsed, const char *file, const char *func, int line) | |
114 | { | |
115 | if (unlikely(!g_ceph_context)) | |
116 | return; | |
117 | init_tp(g_ceph_context); | |
118 | tracepoint(eventtrace, oid_elapsed, oid, event, context, elapsed, file, func, line); | |
119 | } | |
120 | ||
121 | void EventTrace::trace_oid_elapsed(const Message *m, const char *event, double elapsed, | |
122 | const char *file, const char *func, int line, bool incl_oid) | |
123 | { | |
124 | string oid, context; | |
125 | set_message_attrs(m, oid, context, incl_oid); | |
126 | trace_oid_elapsed(oid.c_str(), event, context.c_str(), elapsed, file, func, line); | |
127 | } |