OpenKODE Core extension: KD_KHR_perfcounter


NameKHR_perfcounter
Name stringsKD_KHR_perfcounter
ContributorsAvi Shapira, Yaki Tebeka
ContactsOpenKODE working group, Khronos Group
StatusApproved by OpenKODE working group February 2008
VersionVersion 5, 2008-06-20
Number2
Dependencies Requires OpenKODE Core 1.0. This extension is written based on the wording of the OpenKODE Core 1.0 specification.

1. Overview

This extension provides a unified API through which different performance counter suppliers expose performance counters.

Performance counters suppliers may be:

  • CPU vendors - CPU utilization counters.

  • Operating systems: Counters related to memory, I/O, threads, etc.

  • Graphic system: Graphic driver utilization counters, graphic memory usage counters, GPU utilization counters, FPS, etc.

  • Any other program, system or service that would like to expose performance counters.

2. Header file

When this extension is present, its facilities are accessed by including its header file:

#include <KD/KHR_perfcounter.h>

3. Recommended counter names

Although not mandatory, it is recommended that vendors use the following counter names, in order to promote interoperability.

3.1. CPU

  • "CPU X utilization"

  • "CPU X user mode utilization"

  • "CPU X kernel mode utilization"

where X is a decimal integer giving the CPU number.

3.2. Memory

  • "Physical memory usage"

  • "Virtual memory usage"

  • "Cache pages fault / sec"

3.3. I/O

  • "File read bytes / sec"

  • "File write bytes / sec"

  • "I/O read bytes / sec"

  • "I/O write bytes / sec"

3.4. Operating system

  • "Processes amount"

  • "Threads amount"

  • "Context switched / sec"

3.5. Graphic system

  • "Graphic driver utilization"

  • "GPU X utilization"

  • "GPU X vertex processors utilization"

  • "GPU X fragment processors utilization"

  • "GPU memory usage"

  • "Primitive count"

  • "Culled primitive count"

where X is a decimal integer giving the GPU number.

4. New constants

KD_INFINITE_COUNTER_VAL_KHR (KDINT64_MAX)

Defines an infinite counter value.

KD_UNKNOWN_COUNTER_VAL_KHR (-1)

Represents an unknown value.

5. New types

5.1. KDCounterInfoKHR

Information on a single performance counter.

Synopsis

typedef struct KDCounterInfoKHR {
    const KDchar *vendorName;
    const KDchar *name;
    const KDchar *description;
    KDint64 minValue;
    KDint64 maxValue;
    KDfloat32 defaultScale;
} KDCounterInfoKHR;

Description

vendorName

Counter vendor name.

name

Counter name (should be short).

description

Counter description (as detailed as possible).

minValue

Counter minimal value.

maxValue

Counter maximal value (can get KD_INFINITE_COUNTER_VAL_KHR).

defaultScale

Scale factor that transforms the counter value to the [0,100] range.

Use KD_UNKNOWN_COUNTER_VAL_KHR for counters to which there is no predefined default scale.

6. New functions

6.1. kdGetNumberOfCountersKHR

Return the number of performance counters.

Synopsis

KDint kdGetNumberOfCountersKHR(void); 

Description

This function retrieves the number of performance counters supported by the implementation.

Return value

On success, the function returns the number of counters, or 0 if none. On failure, the function returns -1 and stores one of the error codes below into the error indicator returned by kdGetError.

Error codes

KD_EACCES

Permission denied.

6.2. kdGetCounterInformationKHR

Retrieve information on a performance counter.

Synopsis

const KDCounterInfoKHR *kdGetCounterInformationKHR(KDint  index);

Description

This function retrieves information on counter number index. The index is 0-based.

Return value

On success, the function returns a pointer to a KDCounterInfoKHR structure giving information on the requested counter. On failure, the function returns KD_NULL and stores one of the error codes below into the error indicator returned by kdGetError.

Error codes

KD_EACCES

Permission denied.

KD_EINVAL

Unrecognized counter index.

6.3. kdActivateCountersKHR

Make counters active.

Synopsis

KDint kdActivateCountersKHR(const KDint * indexes,
 KDint  numindexes);

Description

This function activates the counters whose indexes appear in the first numindexes elements of the array indexes. Note that activating a lot of counters may reduce system performance.

If numindexes is negative, or if indexes is not a readable array of at least numindexes KDint values, then undefined behavior results.

Return value

On success, the function returns 0. On failure, it returns -1 and stores one of the error codes below into the error indicator returned by kdGetError.

Error codes

KD_EACCES

Permission denied.

KD_EINVAL

Unrecognized counter index.

6.4. kdDeactivateCountersKHR

Makes counters inactive.

Synopsis

KDint kdDeactivateCountersKHR(const KDint * indexes,
 KDint  numindexes);

Description

This function deactivates the counters whose indexes appear in the first numindexes elements of the array indexes.

If numindexes is negative, or if indexes is not a readable array of at least numindexes KDint values, then undefined behavior results.

Return value

On success, the function returns 0. On failure, it returns -1 and stores one of the error codes below into the error indicator returned by kdGetError.

Error codes

KD_EACCES

Permission denied.

KD_EINVAL

Unrecognized counter index.

6.5. kdStartSamplingKHR

Start the performance counters sampling.

Synopsis

KDint kdStartSamplingKHR(void); 

Description

This function initializes all performance counter values to 0 and starts the active ones sampling.

Return value

On success, the function returns 0. On failure, it returns -1 and stores one of the error codes below into the error indicator returned by kdGetError.

Error codes

KD_EACCES

Permission denied.

6.6. kdStopSamplingKHR

Stop the performance counters sampling.

Synopsis

KDint kdStopSamplingKHR(void); 

Description

This function stops the active performance counters sampling.

Return value

On success, the function returns 0. On failure, it returns -1 and stores one of the error codes below into the error indicator returned by kdGetError.

Error codes

KD_EACCES

Permission denied.

6.7. kdGetCounterValuesKHR

Retrieves list of counter values.

Synopsis

KDint kdGetCounterValuesKHR(const KDint * indexes,
 KDint  numindexes,
 KDint64 * values);

Description

This function stores counter values into the array value. For each integer from 0 to numindexes-1 inclusive, a counter index is read out of that position in the indexes array, and the current value of the counter of that index is stored in the corresponding position in the values array.

If numindexes is negative, or if indexes is not a readable array of at least numindexes KDint values, or if values is not a writable array of at least numindexes KDint64 elements, then undefined behavior results.

Return value

On success, the function returns 0. On failure, it returns -1 and stores one of the error codes below into the error indicator returned by kdGetError.

Error codes

KD_EACCES

Permission denied.

KD_EINVAL

Unrecognized counter index.

7. Revision history

7.1. Version 5, 2008-06-20

Changed back to being based on OpenKODE Core 1.0 specification.

7.2. Version 4, 2008-03-31

Now based on OpenKODE Core 1.0.1 specification.

7.3. Version 3, 2008-01-17

Functions are no longer declared as function pointer types. Used KDINT64_MAX for infinite counter value, since a counter value is a KDint64. Changed struct member names to match style of OpenKODE Core. Added definition of error codes.

7.4. Version 2, 2007-03-23

Added contributor list and revision history. Added list of recommended counter names.

7.5. Version 1, 2007-01-31

Initial version.