Generate Call Graphs

You can use the C/C++ SDK to instrument methods so that they are reported and displayed in the call graph. You can instrument methods in one of the following ways:

  • Use the APPD_AUTO_FRAME macro, C++ only
  • Use appd_frame_begin and appd_frame_end

Instrument Methods with theAPPD_AUTO_FRAMEMacro

You can use the APPD_AUTO_FRAME macro to instrument applications built on C++ frameworks. The macro is equivalent to calling the appd_frame_beginand appd_frame_end methods.

  1. Specify the business transaction that you want to instrument calls for, and configure the root of the call graph.

    appd::sdk::BT bt("mybt");
    APPD_AUTO_FRAME(bt);
    method1(bt);
    method2(bt);
  2. Instrument the methods as shown below.

    void method1(appd::sdk::BT& bt)
    {
    APPD_AUTO_FRAME(bt);
    // Code for method1...
    }
    void method2(appd::sdk::BT& bt)
    {
    APPD_AUTO_FRAME(bt);
    // Code for method2...
    }

    The methods must have access to the business transaction so the business transaction can be passed into the method as an argument.

Instrument Methods with theappd_frame_beginandappd_frame_endFunctions

You can instrument methods for applications that are built on non-C++ frameworks. To instrument a method, you call appd_frame_begin at the beginning of the method, and appd_frame_end at the end of the method. When you do this, the duration of the method call is automatically calculated and reported in the call graph.

If your method makes an exit call, you can instrument the exit call by wrapping the exit call code between appd_exitcall_begin and appd_exitcall_end.

The code samples below show three methods that are each instrumented using appd_frame_begin and appd_frame_end, and then called in a root method, main(). The second sample method, method2(), contains an exit call.

void method1( )
{
appd_frame_handle frameHandle = appd_frame_begin(btHandle, APPD_FRAME_TYPE_CPP, nullptr, APPD_FUNCTION_NAME, __FILE__, __LINE__);
// code for method1
appd_frame_end(btHandle, frameHandle);
}
void method2()
{
appd_frame_handle frameHandle = appd_frame_begin(btHandle, APPD_FRAME_TYPE_CPP, nullptr, APPD_FUNCTION_NAME, __FILE__, __LINE__);
// code for method2
appd_exitcall_handle exitCallHandle = appd_exitcall_begin(btHandle, BACKEND_NAME);
// code for exit call
appd_exitcall_end(exitCallHandle);
appd_frame_end(btHandle, frameHandle);
}
void method3()
{
// To illustrate instrumenting a method where this SDK cannot be used
// method3 is a wrapper for the call of the actual method which will show up in the call graph
appd_frame_handle frameHandle = appd_frame_begin(btHandle, APPD_FRAME_TYPE_CPP, "Test", "Compute", "C:\\modules\\source\\Test.cs", 143);
// call the wrapped method
appd_frame_end(btHandle, frameHandle);
}

The main() method below is the root of the call graph. It specifies the business transaction that invokes the three methods above by passing the transaction into appd_bt_begin and appd_bt_end.

int main(int argc, char **argv)
{
// initialize AppDynamics
btHandle = appd_bt_begin(TRANSACTION_NAME, "");
appd_frame_handle frameHandle = appd_frame_begin(btHandle, APPD_FRAME_TYPE_CPP, nullptr, APPD_FUNCTION_NAME, __FILE__, __LINE__);
// code for main
method1();
method2();
method3();
appd_frame_end(btHandle, frameHandle);
appd_bt_end(btHandle);
}

The sample methods above are represented by the call graph shown below:

Call Graph Methods