Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Instrumenting C/C++ Application Performance Monitoring

DZone's Guide to

Instrumenting C/C++ Application Performance Monitoring

It's always nice to have a measure of certainty when it comes to our complex systems' performance.

· Performance Zone
Free Resource

With the AppDynamics Winter ’16 Release, AppDynamics now supports monitoring of C/C++ applications via a monitoring SDK that enables the same real-time, end-to-end, user-to-database performance visibility as other supported languages, for rapid root-cause analysis and issue resolution.

C/C++ has been around a while, and it’s regarded as the language for high-performance applications primarily because it compiles to machine code and directly interfaces with the operating system without an intermediate layer.

While the application complexity has exploded over the years and modern languages have evolved and become more popular due to various reasons, C/C++ based applications are still a core part of business critical application environment for many enterprises. As these applications become increasingly critical to the business, it’s more important than ever to have a simple, yet fast way to monitor, diagnose, and resolve application problems before they affect revenue.

Introducing AppDynamics C/C++ Application Performance Management Module

AppDynamics C/C++ Application Performance Management (APM) module provides end-to-end business transaction-centric management of C/C++ applications in the most complex and distributed environments to deliver exceptional user experience by proactively identifying and resolving performance issues.

As a key module of AppDynamics Application Intelligence Platform, C/C++ APM module monitors the C/C++ applications via a monitoring SDK that enables the same real-time, end-to-end, user-to-database performance visibility as other supported languages, for rapid root-cause analysis and issue resolution.

cpp-application-performance-monitoring-Fig1.png

Fig 1: C/C++ Application Performance Monitoring

You can instrument your C/C++ application code using the SDK, recompile the code and deploy in production to get real-time visibility of performance and find the root cause of code bottlenecks in seconds, all with minimal overhead. AppDynamics C/C++ application monitoring SDK enables automatic discovery and mapping of all tiers that service and interact with the C/C++ applications, automatic dynamic baselining, data collectors, and health rules, as well as managing key metrics including application load and response times, and system resources including CPU, memory, and disk I/O.

Instrumenting C/C++ Application for Monitoring

It’s pretty straightforward to instrument a C/C++ application code for defining and monitoring business transactions, capturing snapshots, distributed transaction correlation, backend monitoring, error Monitoring and collecting data from methods.

For example, in order to define and monitor a business transaction like what you see in Fig 1, you just need to enclose the code that constitutes the request that you want to monitor between appd_bt_begin() and appd_bt_end()calls. Please see code sample before and after instrumentation below where you will notice just two line of code required to get the code monitored as a business transaction.

Example of code before instrumentation:

AccountOpResult AccountMgr::CreateAccount(const std::string& username, const std::string& password)
{
    AccountOpResult result = AOR_OK;
    if (utf8length(username) > MAX_ACCOUNT_STR)
    {
        result = AOR_NAME_TOO_LONG;
    }
    else if (GetId(username))
    {
        result = AOR_NAME_ALREADY_EXISTS;
    }
    else if (!loginDB.PExecute("INSERT INTO account(username,pass_hash) VALUES('%s','%s')", username, CalculatePassHash(password)))
    {
        result = AOR_DB_INTERNAL_ERROR;
    }
    return result;
} 

Example of code after instrumentation:

AccountOpResult AccountMgr::CreateAccount(const std::string& username, const std::string& password)
{
    AccountOpResult result = AOR_OK;

 appd_bt_handle bt = appd_bt_begin(__func__, NULL);

    if (utf8length(username) > MAX_ACCOUNT_STR)
    {
        result = AOR_NAME_TOO_LONG;
    }
    else if (GetId(username))
    {
        result = AOR_NAME_ALREADY_EXISTS;
    }
    else if (!loginDB.PExecute("INSERT INTO account(username,pass_hash) VALUES('%s','%s')", username, CalculatePassHash(password)))
    {
        result = AOR_DB_INTERNAL_ERROR;
    }
 appd_bt_end(bt);
    return result;
} 

appd_bt_begin() returns a handle to use in subsequent routines that affect that business transaction. If you are creating a business transaction that correlates with an upstream business transaction, pass the correlation header of the upstream transaction so the new transaction that you are creating can correlate with it.

By inserting similar code, you can do distributed transaction correlation, backend monitoring, error monitoring and collect data (key/value) from methods

Hopefully this gives you an overview of C++ monitoring solution and gets you started. Learn more about the configuration, instrumentation and additional details of the C/C++ monitoring SDK in the AppDynamics documentation.

Topics:
c & c++ ,performance and monitoring ,sdks ,instrumentation

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}