2 .\" Copyright (c) 2005, Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH CPC_ENABLE 3CPC "Jan 31, 2005"
8 cpc_enable, cpc_disable \- enable and disable performance counters
12 cc [ \fIflag\fR\&.\|.\|. ] \fIfile\fR\&.\|.\|. \fB-lcpc\fR [ \fIlibrary\fR\&.\|.\|. ]
15 \fBint\fR \fBcpc_enable\fR(\fBcpc_t *\fR\fIcpc\fR);
20 \fBint\fR \fBcpc_disable\fR(\fBcpc_t *\fR\fIcpc\fR);
26 In certain applications, it can be useful to explicitly enable and disable
27 performance counters at different times so that the performance of a critical
28 algorithm can be examined. The \fBcpc_enable()\fR and \fBcpc_disable()\fR
29 functions can be used to enable and disable the performance counters without
30 otherwise disturbing the invoking LWP's performance hardware configuration.
34 Upon successful completion, \fBcpc_enable()\fR and \fBcpc_disable()\fR return
35 0. Otherwise, they return -1 and set \fBerrno\fR to indicate the error.
39 These functions will fail if:
46 The associated performance counter context has been invalidated by another
56 No performance counter context has been created for the calling LWP.
61 \fBExample 1 \fRUse cpc_enable and cpc_disable to minimize code needed by
65 In the following example, the \fBcpc_enable()\fR and \fBcpc_disable()\fR
66 functions are used to minimize the amount of code that needs to be added to the
67 application. The \fBcputrack\fR(1) command can be used in conjunction with
68 these functions to provide event programming, sampling, and reporting
73 If the application is instrumented in this way and then started by
74 \fBcputrack\fR with the \fBnouser\fR flag set in the event specification,
75 counting of user events will only be enabled around the critical code section
76 of interest. If the program is run normally, no harm will ensue.
82 main(int argc, char *argv[])
84 cpc_t *cpc = cpc_open(CPC_VER_CURRENT);
85 /* ... application code ... */
88 (void) cpc_enable(cpc);
90 /* ==> Code to be measured goes here <== */
93 (void) cpc_disable(cpc);
95 /* ... other application code */
103 See \fBattributes\fR(5) for descriptions of the following attributes:
111 ATTRIBUTE TYPE ATTRIBUTE VALUE
113 Interface Stability Evolving
121 \fBcputrack\fR(1), \fBcpc\fR(3CPC), \fBcpc_open\fR(3CPC), \fBlibcpc\fR(3LIB),