How can I use OPNET profiling utility to profile my C++ external files and C++ process models?

Categories:
Solution Number:
S20792
Last Modified:
2013-08-20
Issue

How can I use OPNET profiling utility to profile my C++ external files and C++ process models?

Solution

In order to profile C++ code, you will need to wrap C++ code in C wrappers.Narrow down on C++ suspects using C wrappers. If you identify an expensive C function whose C descendants are inexpensive, but which also has a C++ descendant, you've effectively identified an expansive C++ function. If that function is sufficiently low-level, you've got a good answer to your inquiry.To profile C++ functions:If the function you wish to profile is capable of having a C interface (e.g., it is not a class method), then you only need one wrapper. Otherwise, you need two wrappers: 1) C++ wrapper that is extern C, and 2) C wrapper that calls the C++ wrapperFor example, say you wish to profile sample_class::sample_cpp_func.=========================================/* In a .c file or C process model */voidsample_c_wrapper_func (int a) { /* Wrapper c function that just calls the extern C function. */ /* Because this is a C function, profile works here. */ /* This is a simple wrapper function, so the time spent */ /* in this function is almost exactly equal to the time */ /* spent in the one function that we call here. */ FIN (...); sample_cpp_func_that_is_extern_c (a); FOUT; }==================================================================================/* In a .cpp file or C++ process model */extern C voidsample_cpp_func_that_is_extern_c (int a) { // This is a C++ function that has a C interface. // It can include whatever c++ code, such as: sample_class->sample_cpp_func (a); }voidsample_class::sample_cpp_func (int a = 0) { // C++ code of interest }=========================================If instead you wish to profile a C++ process model, you would create a C process model that simply invokes the C++ process model. The profiling will work in the C process model.

Environment

DES Kernel->Process Modeling/Coding,DES Kernel->Statistics and Reports

Attachments
NOTICE: Riverbed® product names have changed. Please refer to the Product List for a complete list of product names.
Can't find an answer? Create a case