After you've enabled the PMU in a compute instance and run performance-monitoring software on the compute instance, you can do the following:
-
Change the PMU type enabled in the compute instance. This change is useful when you want to track different types of low-level CPU events.
-
Disable the PMU in the compute instance. This action is useful when you no longer need to access the performance counters in the PMU.
This document explains how to change the performance monitoring unit (PMU) type that is enabled in a Compute Engine instance, or disable it. To learn more about the PMU, see PMU overview .
Before you begin
- If you haven't already, set up authentication
.
Authentication verifies your identity for access to Google Cloud services and APIs. To run
code or samples from a local development environment, you can authenticate to
Compute Engine by selecting one of the following options:
Select the tab for how you plan to use the samples on this page:
gcloud
-
Install the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity .
- Set a default region and zone .
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity .
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
-
Required roles
To get the permissions that
you need to change the PMU type enabled in a compute instance or disable it,
ask your administrator to grant you the Compute Instance Admin (v1)
( roles/compute.instanceAdmin.v1
)
IAM role
on your project.
For more information about granting roles, see Manage access to projects, folders, and organizations
.
This predefined role contains the permissions required to change the PMU type enabled in a compute instance or disable it. To see the exact permissions that are required, expand the Required permissionssection:
Required permissions
The following permissions are required to change the PMU type enabled in a compute instance or disable it:
- To update a compute instance:
compute.instances.updateon the compute instance
You might also be able to get these permissions with custom roles or other predefined roles .
Change the PMU type in a compute instance
Before you change the PMU type for an existing A4X, C4A, C4, or M4 instance, view the details of the compute instance by using the Google Cloud CLI or REST API. In the output from the command or API request, verify the following:
-
To verify that the PMU type is enabled in the compute instance, check the value of the
performanceMonitoringUnitfield. If the field is missing, then the PMU is disabled. -
If you want to enable the enhanced PMU type, then you must verify that the compute instance uses one of the following machine types by checking the value of the
machineTypefield:-
A C4 machine type with 144 or 288 vCPUs
-
One of the following M4 machine types:
-
m4-megamem-112 -
m4-megamem-224 -
m4-ultramem-56 -
m4-ultramem-112 -
m4-ultramem-224
-
If your compute instance uses a different machine type, then you must change the machine type that the compute instance uses before you can monitor enhanced PMU types.
-
You don't have to stop the compute instance to change the PMU type. However, to make the change effective, you must restart the compute instance as described in this section.
To change the PMU type enabled in an existing compute instance, select one of the following options:
gcloud
-
Create an empty YAML file.
-
To export the properties of a compute instance into the YAML file that you've just created, use the
gcloud compute instances exportcommand :gcloud compute instances export INSTANCE_NAME \ --destination= YAML_FILE \ --zone= ZONEReplace the following:
-
INSTANCE_NAME: the name of the compute instance. -
YAML_FILE: the path to the YAML file that you created in the previous step. -
ZONE: the zone where the compute instance exists.
-
-
In the YAML configuration file, locate the
performanceMonitoringUnitfield and change its value to specify a different PMU type:advancedMachineFeatures: performanceMonitoringUnit: PMU_TYPEReplace
PMU_TYPEwith one of the following values:-
Architectural PMU type:
ARCHITECTURAL -
Standard PMU type:
STANDARD -
Enhanced PMU type:
ENHANCED
-
-
To update the compute instance and restart it, use the
gcloud compute instances update-from-filecommand with the--most-disruptive-allowed-actionflag set toRESTART:gcloud compute instances update-from-file INSTANCE_NAME \ --most-disruptive-allowed-action=RESTART \ --source= YAML_FILE \ --zone= ZONEReplace the following:
-
INSTANCE_NAME: the name of the compute instance. -
YAML_FILE: the path to the YAML file with the configuration data that you modified in the previous step. -
ZONE: the zone where the compute instance exists.
-
REST
-
To view the properties of an existing compute instance, make a
GETrequest to theinstances.getmethod :GET https://compute.googleapis.com/compute/v1/projects/ PROJECT_ID /zones/ ZONE /instances/ INSTANCE_NAMEReplace the following:
-
PROJECT_ID: the ID of the project where the compute instance is located. -
ZONE: the zone where the compute instance exists. -
INSTANCE_NAME: the name of an existing compute instance.
-
-
To update the compute instance and restart it, make a
PUTrequest to theinstances.updatemethod as follows:-
In the request URL, include the
mostDisruptiveAllowedActionquery parameter set toRESTART. -
For the request body, use the
GETrequest output from the previous step. However, in theadvancedMachineFeaturesfield, you must change the value of theperformanceMonitoringUnitfield to your chosen PMU type.
The
PUTrequest is similar to the following:PUT https://compute.googleapis.com/compute/v1/projects/ PROJECT_ID /zones/ ZONE /instances/ INSTANCE_NAME ?mostDisruptiveAllowedAction=RESTART { "advancedMachineFeatures": { "performanceMonitoringUnit": " PMU_TYPE " }, ... }Replace
PMU_TYPEwith one of the following values:-
Architectural PMU type:
ARCHITECTURAL -
Standard PMU type:
STANDARD -
Enhanced PMU type:
ENHANCED
-
For more information about updating the properties of a compute instance, see Update instance properties .
Disable the PMU in a compute instance
You can disable the PMU in a compute instance without stopping the compute instance. However, to make the change effective, you must restart the compute instance as described in this section.
To disable the PMU in an existing compute instance, select one of the following options:
gcloud
-
Create an empty YAML file.
-
To export the properties of a compute instance into the YAML file that you've just created, use the
gcloud compute instances exportcommand :gcloud compute instances export INSTANCE_NAME \ --destination= YAML_FILE \ --zone= ZONEReplace the following:
-
INSTANCE_NAME: the name of the compute instance. -
YAML_FILE: the path to the YAML file that you created in the previous step. -
ZONE: the zone where the compute instance exists.
-
-
In the YAML configuration file, remove the
performanceMonitoringUnitfield. If theadvancedMachineFeaturesfield is empty, then remove it as well.advancedMachineFeatures: performanceMonitoringUnit: PMU_TYPE -
To update the compute instance and restart it, use the
gcloud compute instances update-from-filecommand with the--most-disruptive-allowed-actionflag set toRESTART:gcloud compute instances update-from-file INSTANCE_NAME \ --most-disruptive-allowed-action=RESTART \ --source= YAML_FILE \ --zone= ZONEReplace the following:
-
INSTANCE_NAME: the name of the compute instance. -
YAML_FILE: the path to the YAML file with the configuration data that you modified in the previous step. -
ZONE: the zone where the compute instance exists.
-
REST
-
To view the properties of an existing compute instance, make a
GETrequest to theinstances.getmethod :GET https://compute.googleapis.com/compute/v1/projects/ PROJECT_ID /zones/ ZONE /instances/ INSTANCE_NAMEReplace the following:
-
PROJECT_ID: the ID of the project where the compute instance exists. -
ZONE: the zone where the compute instance exists. -
INSTANCE_NAME: the name of an existing compute instance.
-
-
To update the compute instance and restart it, make a
PUTrequest to theinstances.updatemethod . In the request, do the following:-
In the request URL, include the
mostDisruptiveAllowedActionquery parameter set toRESTART. -
For the request body, use the
GETrequest output from the previous step. However, you must remove theperformanceMonitoringUnitfield and, if there aren't other fields in theadvancedMachineFeaturesfield, theadvancedMachineFeaturesfield too.
The
PUTrequest is similar to the following:PUT https://compute.googleapis.com/compute/v1/projects/ PROJECT_ID /zones/ ZONE /instances/ INSTANCE_NAME ?mostDisruptiveAllowedAction=RESTART { ~"advancedMachineFeatures": { ... }~, ... } -
For more information about updating the properties of a compute instance, see Update instance properties .

