Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

calltrace.reference

Klemens David Morgenstern edited this page Apr 4, 2018 · 1 revision

Summary

Members Descriptions
#define METAL_NO_INSTRUMENT The macro that removes call monitoring for a function.
int metal_calltrace_init(metal_calltrace * ct) This function initializes and registers a calltrace. Note that there is a limited amount of calltraces that can be added. The default value is 16, but can be changed by defining METAL_CALLTRACE_STACK_SIZE while compiling calltrace.
int metal_calltrace_complete(metal_calltrace * ct) This functions returns a value different from zero if the calltrace was completed. The behaviour depends on the repeat setting of the calltrace. If the calltrace is set to repeat n-times it has to be at least repeated once, while any other number will require the calltrace to be repeated exactly as set.
int metal_calltrace_success(metal_calltrace * ct) This functions returns a value different from zero if the calltrace was completed and did not err.
int metal_calltrace_deinit(metal_calltrace * ct) This function deinitializes the calltrace and removes it from the stack. This function must be called before the calltrace struct is removed from the stack, otherwise it might casue memory leaks.
namespace metal Namespace containing the calltrace

Members

int metal_calltrace_init(metal_calltrace * ct)

This function initializes and registers a calltrace. Note that there is a limited amount of calltraces that can be added. The default value is 16, but can be changed by defining METAL_CALLTRACE_STACK_SIZE while compiling calltrace.

Example

#include <cassert>
#include <metal/calltrace.h>

void func() {foo(); bar();}

int main(int argc, char *argv[])
{
   const void * ct_arr[] = {&foo, &bar};
   metal_calltrace ct = {&func, ct_arr, 2, 0, 0};

   assert(metal_calltrace_init(&ct));

   func();
   assert(metal_calltrace_success(&ct));
   assert(metal_calltrace_deinit(&ct));
   return 0;
}

Parameters

  • ct A pointer to the calltrace to be initialized.

Returns

A value differnt from zero if it succeeded.

int metal_calltrace_complete(metal_calltrace * ct)

This functions returns a value different from zero if the calltrace was completed. The behaviour depends on the repeat setting of the calltrace. If the calltrace is set to repeat n-times it has to be at least repeated once, while any other number will require the calltrace to be repeated exactly as set.

Parameters

  • ct A pointer to the calltrace that shall be examined.

Returns

Unequal zero if successful.

int metal_calltrace_success(metal_calltrace * ct)

This functions returns a value different from zero if the calltrace was completed and did not err.

Parameters

  • ct A pointer to the calltrace that shall be examined.

Returns

Unequal zero if completed without error.

int metal_calltrace_deinit(metal_calltrace * ct)

This function deinitializes the calltrace and removes it from the stack. This function must be called before the calltrace struct is removed from the stack, otherwise it might casue memory leaks.

Parameters

  • ct The calltrace to be deinitialized

Returns

A value unequal to zero if the calltrace was succesful removed from the stack.

namespace metal::test

Summary

Members Descriptions
public timestamp_t timestamp()
class metal::test::calltrace The actual calltrace implementation.
class metal::test::calltrace<0> Specialization for an empty calltrace.
struct metal::test::fn Convenience type to bind to any function with the given signature to pass to the calltrace. This does not take qualifier overloads in member function into account.

Members

timestamp_t timestamp()

class metal::test::calltrace

class metal::test::calltrace
  : private metal_calltrace_

The actual calltrace implementation.

Parameters

  • Size The number of the functions inside the trace body passed.

Example

void bar(std::vector<int> & v);
void foo()
{
    std::vector<int> vec;
    vec.push_back(42);

    bar(vec);
    vec.resize(2);
};

int main(int argc, char* argv[])
{
    using namespace [metal::test](#namespacemetal_1_1test);
    [calltrace](#classmetal_1_1test_1_1calltrace) ct
        {
            &foo, //starting point
            any_fn, //constructor, no way to get the address
            [fn<void(int&&)>](#structmetal_1_1test_1_1fn)(&std::vector<int>::push_back), //the move push back
            &bar, //function not overloaded
            &std::vector<int>::size,
            any_fn //destructor
        };

    foo();
    assert(ct);
    return 0;
};

Summary

Members Descriptions
template<> calltrace(Func func,int repeat,int skip) Construct an empty (i.e. asserting no calls) calltrace from the given function, including a repeat count and a skip.
template<> calltrace(Func func,int repeat) Construct an empty calltrace from the given function, including a repeat count, but no skip.
template<> calltrace(Func func) Construct an empty calltrace from the given function, without a repeat count and skip.
template<> calltrace(Func func,int repeat,int skip,Args... args) Construct a calltrace from the given function, including a repeat count and a skip
calltrace(const calltrace &) = delete Deleted copy-ctor.
template<> calltrace(Func func,int repeat,Args... args) Construct a calltrace from the given function, including a repeat count, but no skip.
template<> calltrace(Func func,Args ... args) Construct a calltrace from the given function, without a repeat count and skip.
bool inited() const Check if the calltrace was inited, i..e added to the calltrace list.
bool errored() const Check if the calltrace had an error occur.
bool complete() const Check if the calltrace is completed, without checking the error count. The behaviour depends on the repeat setting of the calltrace. If the calltrace is set to repeat n-times it has to be at least repeated once, while any other number will require the calltrace to be repeated exactly as set.
bool success() const Check if the calltrace was succesful, i.e. inited, completed and did not err.
operator bool() const Convenience overload for success.
~calltrace() Destructor, removes the calltrace from the list.

Members

template<> calltrace (Func func,int repeat,int skip)

Construct an empty (i.e. asserting no calls) calltrace from the given function, including a repeat count and a skip.

Parameters

  • func The function to trace

  • repeat The times the calltrace shall be repeated

  • skip The amount of calls that shall be ignore before activating the calltrace

template<> calltrace(Func func,int repeat)

Construct an empty calltrace from the given function, including a repeat count, but no skip.

Parameters

  • func The function to trace

  • repeat The times the calltrace shall be repeated

template<> calltrace(Func func)

Construct an empty calltrace from the given function, without a repeat count and skip.

Parameters

  • func The function to trace

template<> calltrace(Func func,int repeat,int skip,Args... args)

Construct a calltrace from the given function, including a repeat count and a skip.

Parameters

  • func The function to trace

  • repeat The times the calltrace shall be repeated

  • skip The amount of calls that shall be ignore before activating the calltrace

  • args The expected function calls.

template<> calltrace(Func func,int repeat,Args... args)

Construct a calltrace from the given function, including a repeat count, but no skip.

Parameters

  • func The function to trace

  • repeat The times the calltrace shall be repeated

  • args The expected function calls.

template<> calltrace(Func func,Args ... args)

Construct a calltrace from the given function, without a repeat count and skip.

Parameters

  • func The function to trace

  • args The expected function calls.

bool inited() const

Check if the calltrace was inited, i..e added to the calltrace list.

bool errored() const

Check if the calltrace had an error occur.

bool complete() const

Check if the calltrace is completed, without checking the error count. The behaviour depends on the repeat setting of the calltrace. If the calltrace is set to repeat n-times it has to be at least repeated once, while any other number will require the calltrace to be repeated exactly as set.

bool success() const

Check if the calltrace was succesful, i.e. inited, completed and did not err.

operator bool() const

Convenience overload for success.

~calltrace()

Destructor, removes the calltrace from the list.

class metal::test::calltrace< 0 >

class metal::test::calltrace< 0 >
  : private metal_calltrace_

Specialization for an empty calltrace.

Summary

Members Descriptions
template<> alltrace(Func func,int repeat,int skip) Construct an empty (i.e. asserting no calls) calltrace from the given function, including a repeat count and a skip.
template<> alltrace(Func func,int repeat) Construct an empty calltrace from the given function, including a repeat count, but no skip.
template<> alltrace(Func func) Construct an empty calltrace from the given function, without a repeat count and skip.
bool inited() const Check if the calltrace was inited, i..e added to the calltrace list.
bool errored() const Check if the calltrace had an error occur.
bool complete() const Check if the calltrace is completed, without checking the error count. The behaviour depends on the repeat setting of the calltrace. If the calltrace is set to repeat n-times it has to be at least repeated once, while any other number will require the calltrace to be repeated exactly as set.
bool success() const Check if the calltrace was succesful, i.e. inited, completed and did not err.
operator bool() const Convenience overload for success.
~calltrace() Destructor, removes the calltrace from the list.

Members

template<> calltrace(Func func,int repeat,int skip)

Construct an empty (i.e. asserting no calls) calltrace from the given function, including a repeat count and a skip.

Parameters

  • func The function to trace

  • repeat The times the calltrace shall be repeated

  • skip The amount of calls that shall be ignore before activating the calltrace

template<> calltrace(Func func,int repeat)

Construct an empty calltrace from the given function, including a repeat count, but no skip.

Parameters

  • func The function to trace

  • repeat The times the calltrace shall be repeated

template<> calltrace(Func func)

Construct an empty calltrace from the given function, without a repeat count and skip.

Parameters

  • func The function to trace

bool inited() const

Check if the calltrace was inited, i..e added to the calltrace list.

bool errored() const

Check if the calltrace had an error occur.

bool complete() const

Check if the calltrace is completed, without checking the error count. The behaviour depends on the repeat setting of the calltrace. If the calltrace is set to repeat n-times it has to be at least repeated once, while any other number will require the calltrace to be repeated exactly as set.

bool success() const

Check if the calltrace was succesful, i.e. inited, completed and did not err.

operator bool() const

Convenience overload for success.

~calltrace()

Destructor, removes the calltrace from the list.

struct metal::test::fn

Convenience type to bind to any function with the given signature to pass to the calltrace. This does not take qualifier overloads in member function into account.

Example

void foo(int);
void foo(double);

struct bar
{
   bar();
   void f(int);
   void f(double);
   ~bar();
};

bar b;

void func()
{
    foo(42);
    b.f(0.1);
}

calltrace ct{&func,
             fn<void(int)>(&foo), //binds to foo(int)
             fn<void(double)>(&bar::f) //binds to bar::f(double)
             };

struct metal::test::mem_fn

Helper type to bind to a member function, either any without const/volatile qualifier or with a specific signature.

Example

struct my_class
{
    void foo();
    void foo() const;

    void bar();
    void bar() const;
    void bar(int);
    void bar(int) const;
};

calltrace ct{&some_func,
             mem_fn<>(&my_class::foo), //binds to my_class::foo()
             mem_fn<void()>(&my_class::bar), //binds to my_class::bar()
             mem_fn<void(int)>(&my_class::bar) //binds to my_class::bar(int)
             };
Clone this wiki locally