Skip to content
Snippets Groups Projects
Commit 92e842a3 authored by Olivier Dion's avatar Olivier Dion Committed by Sébastien Blin
Browse files

client/ring_signal: Add tracepoints

Change-Id: I522edb40e114f03cdf6605f09cc40cdb0bd886b2
parent 475f04e1
No related branches found
No related tags found
No related merge requests found
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
#include "jami.h" #include "jami.h"
#include "logger.h" #include "logger.h"
#include "trace-tools.h"
#include "tracepoint.h"
#ifdef __APPLE__ #ifdef __APPLE__
#include <TargetConditionals.h> #include <TargetConditionals.h>
...@@ -56,19 +58,29 @@ extern SignalHandlerMap& getSignalHandlers(); ...@@ -56,19 +58,29 @@ extern SignalHandlerMap& getSignalHandlers();
* Find related user given callback and call it with given * Find related user given callback and call it with given
* arguments. * arguments.
*/ */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
template<typename Ts, typename... Args> template<typename Ts, typename... Args>
static void void emitSignal(Args... args)
emitSignal(Args... args)
{ {
jami_tracepoint_if_enabled(emit_signal, demangle<Ts>().c_str());
const auto& handlers = getSignalHandlers(); const auto& handlers = getSignalHandlers();
if (auto cb = *DRing::CallbackWrapper<typename Ts::cb_type>(handlers.at(Ts::name))) { if (auto wrap = DRing::CallbackWrapper<typename Ts::cb_type>(handlers.at(Ts::name))) {
try { try {
auto cb = *wrap;
jami_tracepoint(emit_signal_begin_callback,
wrap.file_, wrap.linum_);
cb(args...); cb(args...);
jami_tracepoint(emit_signal_end_callback);
} catch (std::exception& e) { } catch (std::exception& e) {
JAMI_ERR("Exception during emit signal %s:\n%s", Ts::name, e.what()); JAMI_ERR("Exception during emit signal %s:\n%s", Ts::name, e.what());
} }
} }
jami_tracepoint(emit_signal_end);
} }
#pragma GCC diagnostic pop
template<typename Ts> template<typename Ts>
std::pair<std::string, std::shared_ptr<DRing::CallbackWrapper<typename Ts::cb_type>>> std::pair<std::string, std::shared_ptr<DRing::CallbackWrapper<typename Ts::cb_type>>>
......
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#include <memory> #include <memory>
#include <type_traits> #include <type_traits>
#include "trace-tools.h"
namespace DRing { namespace DRing {
/* flags for initialization */ /* flags for initialization */
...@@ -114,13 +116,18 @@ private: ...@@ -114,13 +116,18 @@ private:
TFunc cb_; // The user-callback TFunc cb_; // The user-callback
public: public:
const char* file_;
uint32_t linum_;
// Empty wrapper: no callback associated. // Empty wrapper: no callback associated.
// Used to initialize internal callback arrays. // Used to initialize internal callback arrays.
CallbackWrapper() noexcept {} CallbackWrapper() noexcept {}
// Create and initialize a wrapper to given callback. // Create and initialize a wrapper to given callback.
CallbackWrapper(TFunc&& func) noexcept CallbackWrapper(TFunc&& func, const char* filename, uint32_t linum) noexcept
: cb_(std::forward<TFunc>(func)) : cb_(std::forward<TFunc>(func)),
file_(filename),
linum_(linum)
{} {}
// Create and initialize a wrapper from a generic CallbackWrapperBase // Create and initialize a wrapper from a generic CallbackWrapperBase
...@@ -128,8 +135,13 @@ public: ...@@ -128,8 +135,13 @@ public:
// Note: the given callback is copied into internal storage. // Note: the given callback is copied into internal storage.
CallbackWrapper(const std::shared_ptr<CallbackWrapperBase>& p) noexcept CallbackWrapper(const std::shared_ptr<CallbackWrapperBase>& p) noexcept
{ {
if (p) if (p) {
cb_ = ((CallbackWrapper<TProto>*) p.get())->cb_; auto other = (CallbackWrapper<TProto>*)p.get();
cb_ = other->cb_;
file_ = other->file_;
linum_ = other->linum_;
}
} }
// Return user-callback reference. // Return user-callback reference.
...@@ -149,11 +161,14 @@ public: ...@@ -149,11 +161,14 @@ public:
*/ */
template<typename Ts> template<typename Ts>
std::pair<std::string, std::shared_ptr<CallbackWrapperBase>> std::pair<std::string, std::shared_ptr<CallbackWrapperBase>>
exportable_callback(std::function<typename Ts::cb_type>&& func) exportable_callback(std::function<typename Ts::cb_type>&& func,
const char* file=CURRENT_FILENAME(),
uint32_t linum=CURRENT_LINE())
{ {
return std::make_pair((const std::string&) Ts::name, return std::make_pair((const std::string&) Ts::name,
std::make_shared<CallbackWrapper<typename Ts::cb_type>>( std::make_shared<CallbackWrapper<typename Ts::cb_type>>(
std::forward<std::function<typename Ts::cb_type>>(func))); std::forward<std::function<typename Ts::cb_type>>(func),
file, linum));
} }
DRING_PUBLIC void registerSignalHandlers( DRING_PUBLIC void registerSignalHandlers(
......
...@@ -112,6 +112,15 @@ LTTNG_UST_TRACEPOINT_EVENT( ...@@ -112,6 +112,15 @@ LTTNG_UST_TRACEPOINT_EVENT(
) )
) )
LTTNG_UST_TRACEPOINT_EVENT(
jami,
emit_signal_end,
LTTNG_UST_TP_ARGS(
),
LTTNG_UST_TP_FIELDS(
)
)
LTTNG_UST_TRACEPOINT_EVENT( LTTNG_UST_TRACEPOINT_EVENT(
jami, jami,
emit_signal_begin_callback, emit_signal_begin_callback,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment