mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-07 22:02:12 +08:00
client/ring_signal: Add tracepoints
Change-Id: I522edb40e114f03cdf6605f09cc40cdb0bd886b2
This commit is contained in:

committed by
Sébastien Blin

parent
475f04e10f
commit
92e842a3e2
@ -36,6 +36,8 @@
|
||||
|
||||
#include "jami.h"
|
||||
#include "logger.h"
|
||||
#include "trace-tools.h"
|
||||
#include "tracepoint.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <TargetConditionals.h>
|
||||
@ -56,19 +58,29 @@ extern SignalHandlerMap& getSignalHandlers();
|
||||
* Find related user given callback and call it with given
|
||||
* arguments.
|
||||
*/
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
template<typename Ts, typename... Args>
|
||||
static void
|
||||
emitSignal(Args... args)
|
||||
void emitSignal(Args... args)
|
||||
{
|
||||
jami_tracepoint_if_enabled(emit_signal, demangle<Ts>().c_str());
|
||||
|
||||
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 {
|
||||
auto cb = *wrap;
|
||||
jami_tracepoint(emit_signal_begin_callback,
|
||||
wrap.file_, wrap.linum_);
|
||||
cb(args...);
|
||||
jami_tracepoint(emit_signal_end_callback);
|
||||
} catch (std::exception& e) {
|
||||
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>
|
||||
std::pair<std::string, std::shared_ptr<DRing::CallbackWrapper<typename Ts::cb_type>>>
|
||||
|
@ -30,6 +30,8 @@
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
#include "trace-tools.h"
|
||||
|
||||
namespace DRing {
|
||||
|
||||
/* flags for initialization */
|
||||
@ -114,13 +116,18 @@ private:
|
||||
TFunc cb_; // The user-callback
|
||||
|
||||
public:
|
||||
const char* file_;
|
||||
uint32_t linum_;
|
||||
|
||||
// Empty wrapper: no callback associated.
|
||||
// Used to initialize internal callback arrays.
|
||||
CallbackWrapper() noexcept {}
|
||||
|
||||
// Create and initialize a wrapper to given callback.
|
||||
CallbackWrapper(TFunc&& func) noexcept
|
||||
: cb_(std::forward<TFunc>(func))
|
||||
CallbackWrapper(TFunc&& func, const char* filename, uint32_t linum) noexcept
|
||||
: cb_(std::forward<TFunc>(func)),
|
||||
file_(filename),
|
||||
linum_(linum)
|
||||
{}
|
||||
|
||||
// Create and initialize a wrapper from a generic CallbackWrapperBase
|
||||
@ -128,8 +135,13 @@ public:
|
||||
// Note: the given callback is copied into internal storage.
|
||||
CallbackWrapper(const std::shared_ptr<CallbackWrapperBase>& p) noexcept
|
||||
{
|
||||
if (p)
|
||||
cb_ = ((CallbackWrapper<TProto>*) p.get())->cb_;
|
||||
if (p) {
|
||||
auto other = (CallbackWrapper<TProto>*)p.get();
|
||||
|
||||
cb_ = other->cb_;
|
||||
file_ = other->file_;
|
||||
linum_ = other->linum_;
|
||||
}
|
||||
}
|
||||
|
||||
// Return user-callback reference.
|
||||
@ -149,11 +161,14 @@ public:
|
||||
*/
|
||||
template<typename Ts>
|
||||
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,
|
||||
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(
|
||||
|
@ -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(
|
||||
jami,
|
||||
emit_signal_begin_callback,
|
||||
|
Reference in New Issue
Block a user