Retired Document
Important: The information in this document is deprecated in Xcode 6. For Xcode 6 and later, read Instruments User Guide.
Controlling Profiling Programmatically
You can add code to your application that allows it to interact with OpenGL Profiler during a profiling session. This chapter shows you how to perform these tasks programmatically:
Setting a Breakpoint
Your application can programmatically set breakpoints when it is attached to OpenGL Profiler.
To set a breakpoint:
Include the
CGLProfiler.h
andCGLProfilerFunctionEnum.h
header files in your application.Declare an array of three
GLint
values, set to the following:The function ID, as defined in the header file
CGLProfilerFunctionEnum.h
.The logical
OR
ofkCGLProfBreakBefore
orkCGLProfBreakAfter
, indicating how you want the breakpoint to stop—before entering the OpenGL function, on return from it, or both.A Boolean that turns the breakpoint on or off.
Call the function
CGLSetOption
, passing the array as a parameter.
Listing 4-1 shows code that sets a breakpoint before the CGLFlushDrawable
function.
Listing 4-1 Code that sets a breakpoint
#include "OpenGL/CGLProfiler.h" |
#include "OpenGL/CGLProfilerFunctionEnum.h" |
... |
GLint myBreakpoint[] = { kCGLFECGLFlushDrawable, kCGLProfBreakBefore, 1;} |
CGLSetOption( kCGLGOEnableBreakpoint, myBreakpoint ); |
... |
Writing Comments to the Trace Window
Your application can programmatically write comments to the Trace window during a profiling session. To write comments:
Include the
CGLProfiler.h
header file in your application.Call the function
CGLSetOption
with the constantkCGLGOComment
and your comment cast as a long.
Listing 4-2 shows code that writes a comment that looks like this in the Trace window:
21561: 0.00 µs /* ***** My Comment is here ***** */
Listing 4-2 Code that writes a comment to the Trace window
#include <OpenGL/CGLProfiler.h> |
... |
CGLSetOption(kCGLGOComment, (long) "***** My Comment is here *****"); |
... |
Controlling Trace Collection
Your application can programmatically control when to start and stop collecting a trace, which lets you control which traces to collect in a specific part of your application or during a particular period of time. You can also clear the Trace window.
To control trace collection:
Include the
CGLProfiler.h
header file in your application.Call the function
CGLSetOption
with the constantkCGLGOEnableFunctionTrace
and eitherGL_TRUE
(to turn on trace collection) orGL_FALSE
(to turn off trace collection).
Listing 4-3 shows code that enables trace collection.
Listing 4-3 Code that enables trace collection
#include <OpenGL/CGLProfiler.h> |
... |
CGLSetOption(kCGLGOEnableFunctionTrace, GL_TRUE); |
... |
To clear the Trace window:
Include the
CGLProfiler.h
header file in your application.Call the function
CGLSetOption
with the constantkCGLGOResetFunctionTrace
and the valueNULL
.
Listing 4-4 shows code that enables trace collection.
Listing 4-4 Code that clears the Trace window
#include <OpenGL/CGLProfiler.h> |
... |
CGLSetOption(kCGLGOResetFunctionTrace, NULL); |
... |
Controlling Statistics Collection
You application can programmatically control when to start and stop collecting statistics. You must make sure that the Statistics window in OpenGL Profiler is open when you profile your application.
To control statistics collection:
Include the
CGLProfiler.h
header file in your application.Call the function
CGLSetOption
with the constantkCGLGOResetFunctionStatistics
and the valueNULL
to first reset counters to 0. This step is optional.Call the function
CGLSetOption
with the constantkCGLGOResetFunctionStatistics
and the valueGL_TRUE
to start statistics collection.When you are done collecting statistics, call the function
CGLSetOption
with the constantkCGLGOResetFunctionStatistics
and the valueGL_FALSE
.
Listing 4-5 shows code that resets counters, starts statistics collection, and then stops it.
Listing 4-5 Code that starts and stops statistics collection
#include <OpenGL/CGLProfiler.h> |
... |
// Reset counters to 0 |
CGLSetOption(kCGLGOResetFunctionStatistics, NULL); |
// Start statistics collection |
CGLSetOption(kCGLGOEnableFunctionStatistics, GL_TRUE); |
... |
// Stop statistics collection |
CGLSetOption(kCGLGOEnableFunctionStatistics, GL_FALSE); |
... |
Copyright © 2015 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2015-03-09