本文說明如何變更在虛擬機器 (VM) 例項中啟用的效能監控單元 (PMU) 類型,或停用該類型。如要進一步瞭解 PMU,請參閱「PMU 總覽」。
在 VM 中啟用 PMU 並在 VM 上執行效能監控軟體後,您可以執行下列操作:
變更在 VM 中啟用的 PMU 類型。如要追蹤不同類型的低階 CPU 事件,這項變更就很實用。
停用 VM 中的 PMU。如果您不再需要存取 PMU 中的效能計數器,這項操作就很實用。
事前準備
-
如果尚未設定,請先設定驗證機制。「驗證」是指驗證身分,以便存取 Trusted Cloud by S3NS 服務和 API 的程序。如要從本機開發環境執行程式碼或範例,請選取下列任一選項,以便對 Compute Engine 進行驗證:
Select the tab for how you plan to use the samples on this page:
gcloud
-
After installing the Google Cloud CLI, sign in to the gcloud CLI with your federated identity and then initialize it by running the following command:
gcloud init
- Set a default region and zone.
-
如要更新 VM:
compute.instances.update
在 VM 上 如要確認 VM 中啟用的 PMU 類型,請檢查
performanceMonitoringUnit
欄位的值。如果缺少該欄位,則 PMU 會停用。如要啟用 Enhanced PMU 類型,請檢查
machineType
欄位的值,確認 VM 是否使用具有 96 或 192 個 vCPU 的 C4 機器類型。如果不是,請變更 VM 的機器類型。建立空的 YAML 檔案。
如要將 VM 的屬性匯出至您剛建立的 YAML 檔案,請使用
gcloud compute instances export
指令:gcloud compute instances export VM_NAME \ --destination=YAML_FILE \ --zone=ZONE
更改下列內容:
VM_NAME
:VM 名稱。YAML_FILE
:您在上一個步驟中建立的 YAML 檔案路徑。ZONE
:VM 所在區域。
在 YAML 設定檔中,找出
performanceMonitoringUnit
欄位,然後變更其值,指定不同的 PMU 類型:advancedMachineFeatures: performanceMonitoringUnit: PMU_TYPE
將
PMU_TYPE
替換為下列任一值:架構 PMU 類型:
ARCHITECTURAL
標準 PMU 類型:
STANDARD
強化型 PMU 類型:
ENHANCED
如要更新 VM 並重新啟動,請使用
gcloud compute instances update-from-file
指令,並將--most-disruptive-allowed-action
旗標設為RESTART
:gcloud compute instances update-from-file VM_NAME \ --most-disruptive-allowed-action=RESTART \ --source=YAML_FILE \ --zone=ZONE
更改下列內容:
VM_NAME
:VM 名稱。YAML_FILE
:YAML 檔案的路徑,其中包含您在上一個步驟中修改的設定資料。ZONE
:VM 所在區域。
建立空白 JSON 檔案。
如要查看現有 VM 的屬性,請向
instances.get
方法提出GET
要求:GET https://compute.s3nsapis.fr/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME
更改下列內容:
PROJECT_ID
:VM 所在專案的 ID。ZONE
:VM 所在區域。VM_NAME
:現有 VM 的名稱。
在先前步驟中建立的空 JSON 檔案中,執行下列操作:
輸入
GET
要求輸出的 VM 屬性。找出
performanceMonitoringUnit
欄位,然後變更其值,指定不同的 PMU 類型:"advancedMachineFeatures": { "performanceMonitoringUnit": "PMU_TYPE" }
請將
PMU_TYPE
替換為下列任一值:架構 PMU 類型:
ARCHITECTURAL
標準 PMU 類型:
STANDARD
強化型 PMU 類型:
ENHANCED
如要更新 VM 並重新啟動,請對
instances.update
方法提出PUT
要求。在要求中執行以下操作:在要求網址中,將
mostDisruptiveAllowedAction
查詢參數設為RESTART
。針對要求主體,請使用您在先前步驟中建立及更新的 JSON 檔案中的 VM 屬性。
要求的內容會類似以下:
PUT https://compute.s3nsapis.fr/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME?mostDisruptiveAllowedAction=RESTART { "advancedMachineFeatures": { "performanceMonitoringUnit": "PMU_TYPE" }, ... }
建立空的 YAML 檔案。
如要將 VM 的屬性匯出至您剛建立的 YAML 檔案,請使用
gcloud compute instances export
指令:gcloud compute instances export VM_NAME \ --destination=YAML_FILE \ --zone=ZONE
更改下列內容:
VM_NAME
:VM 名稱。YAML_FILE
:您在上一個步驟中建立的 YAML 檔案路徑。ZONE
:VM 所在區域。
在 YAML 設定檔中,找出
performanceMonitoringUnit
欄位,然後將其值設為NONE
:advancedMachineFeatures: performanceMonitoringUnit: NONE
如要更新 VM 並重新啟動,請使用
gcloud compute instances update-from-file
指令,並將--most-disruptive-allowed-action
旗標設為RESTART
:gcloud compute instances update-from-file VM_NAME \ --most-disruptive-allowed-action=RESTART \ --source=YAML_FILE \ --zone=ZONE
更改下列內容:
VM_NAME
:VM 名稱。YAML_FILE
:YAML 檔案的路徑,其中包含您在上一個步驟中修改的設定資料。ZONE
:VM 所在區域。
建立空白 JSON 檔案。
如要查看現有 VM 的屬性,請向
instances.get
方法提出GET
要求:GET https://compute.s3nsapis.fr/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME
更改下列內容:
PROJECT_ID
:VM 所在專案的 ID。ZONE
:VM 所在區域。VM_NAME
:現有 VM 的名稱。
在先前步驟中建立的空 JSON 檔案中,執行下列操作:
輸入
GET
要求輸出的 VM 屬性。找出
performanceMonitoringUnit
欄位,然後將其值變更為NONE
:"advancedMachineFeatures": { "performanceMonitoringUnit": "NONE" }
如要更新 VM 並重新啟動,請對
instances.update
方法提出PUT
要求。在要求中執行以下操作:在要求網址中,將
mostDisruptiveAllowedAction
查詢參數設為RESTART
。針對要求主體,請使用您在先前步驟中建立及更新的 JSON 檔案中的 VM 屬性。
要求類似以下內容:
PUT https://compute.s3nsapis.fr/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME?mostDisruptiveAllowedAction=RESTART { "advancedMachineFeatures": { "performanceMonitoringUnit": "NONE" }, ... }
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
After installing the Google Cloud CLI, sign in to the gcloud CLI with your federated identity and then initialize it by running the following command:
gcloud init
詳情請參閱 Trusted Cloud 驗證說明文件中的「驗證以使用 REST」。
必要的角色
如要取得變更或停用 VM 中啟用的 PMU 類型所需的權限,請要求管理員為您授予專案的 Compute 執行個體管理員 (v1) (
roles/compute.instanceAdmin.v1
) 身分與存取權管理角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。這個預先定義的角色包含變更 VM 中啟用或停用的 PMU 類型所需的權限。如要查看確切的必要權限,請展開「必要權限」部分:
所需權限
如要變更或停用 VM 中啟用的 PMU 類型,您必須具備下列權限:
變更 VM 中的 PMU 類型
變更現有 C4A 或 C4 VM 中啟用的 PMU 類型前,請使用 Google Cloud CLI 或 REST API 查看 VM 詳細資料。在指令或 API 要求的輸出內容中,確認以下項目:
您不必停止 VM,即可變更其中啟用的 PMU 類型。不過,您必須按照本節所述重新啟動 VM,變更才會生效。
如要變更現有 VM 中啟用的 PMU 類型,請選取下列任一選項:
gcloud
REST
如要進一步瞭解如何更新 VM 的屬性,請參閱「更新 VM 屬性」。
在 VM 中停用 PMU
您不必停止 VM 即可停用 PMU。不過,您必須按照本節所述重新啟動 VM,變更才能生效。
如要在現有 VM 中停用 PMU,請選取下列任一選項:
gcloud
REST
如要進一步瞭解如何更新 VM 的屬性,請參閱「更新 VM 屬性」。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-06-16 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-06-16 (世界標準時間)。"],[[["This guide provides instructions on how to change the Performance Monitoring Unit (PMU) type enabled in a virtual machine (VM) instance, or to disable it altogether."],["Changing the PMU type allows you to track different low-level CPU events, while disabling it stops access to the performance counters in the PMU."],["You can use either the Google Cloud CLI or REST API to change the PMU type to Architectural, Standard, or Enhanced, depending on the desired level of detail."],["Disabling the PMU in a VM is accomplished by setting the `performanceMonitoringUnit` field to `NONE` within the VM's configuration, and then restarting the VM."],["Updating the PMU settings of the VM will require a restart of the VM for the new settings to take effect."]]],[]] -