diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index a6e4c9ddf1..9182b3dbe7 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -1950,6 +1950,7 @@ <event name='cpu_clock' enabled='no'/> <event name='task_clock' enabled='no'/> <event name='page_faults' enabled='no'/> + <event name='context_switches' enabled='no'/> </perf> ... @@ -2049,6 +2050,12 @@ types of page faults perf.page_faults + + context_switches + the count of context switches by applications running on + the platform + perf.context_switches +

Devices

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 856a2f731e..1a4b6cb631 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -436,6 +436,7 @@ cpu_clock task_clock page_faults + context_switches diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h index 1a6cb19b0a..f7e4cd2dce 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -2220,6 +2220,16 @@ void virDomainStatsRecordListFree(virDomainStatsRecordPtr *stats); */ # define VIR_PERF_PARAM_PAGE_FAULTS "page_faults" +/** + * VIR_PERF_PARAM_CONTEXT_SWITCHES: + * + * Macro for typed parameter name that represents context_switches + * perf event which can be used to measure the count of context + * switches by applications running on the platform. It corresponds + * to the "perf.context_switches" field in the *Stats APIs. + */ +# define VIR_PERF_PARAM_CONTEXT_SWITCHES "context_switches" + int virDomainGetPerfEvents(virDomainPtr dom, virTypedParameterPtr *params, diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index b3dfd1b3a5..4004350ba2 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -11256,6 +11256,9 @@ virConnectGetDomainCapabilities(virConnectPtr conn, * It is produced by the task_clock perf event. * "perf.page_faults" - The count of page faults as unsigned long long. * It is produced by the page_faults perf event + * "perf.context_switches" - The count of context switches as unsigned long + * long. It is produced by the context_switches + * perf event. * * Note that entire stats groups or individual stat fields may be missing from * the output in case they are not supported by the given hypervisor, are not diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 83e9377dce..30acb45f9b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9570,6 +9570,7 @@ qemuDomainSetPerfEvents(virDomainPtr dom, VIR_PERF_PARAM_CPU_CLOCK, VIR_TYPED_PARAM_BOOLEAN, VIR_PERF_PARAM_TASK_CLOCK, VIR_TYPED_PARAM_BOOLEAN, VIR_PERF_PARAM_PAGE_FAULTS, VIR_TYPED_PARAM_BOOLEAN, + VIR_PERF_PARAM_CONTEXT_SWITCHES, VIR_TYPED_PARAM_BOOLEAN, NULL) < 0) return -1; diff --git a/src/util/virperf.c b/src/util/virperf.c index 4ae13af19d..ba81e089d0 100644 --- a/src/util/virperf.c +++ b/src/util/virperf.c @@ -44,7 +44,8 @@ VIR_ENUM_IMPL(virPerfEvent, VIR_PERF_EVENT_LAST, "branch_instructions", "branch_misses", "bus_cycles", "stalled_cycles_frontend", "stalled_cycles_backend", "ref_cpu_cycles", - "cpu_clock", "task_clock", "page_faults"); + "cpu_clock", "task_clock", "page_faults", + "context_switches"); struct virPerfEvent { int type; @@ -122,6 +123,9 @@ static struct virPerfEventAttr attrs[] = { {.type = VIR_PERF_EVENT_PAGE_FAULTS, .attrType = PERF_TYPE_SOFTWARE, .attrConfig = PERF_COUNT_SW_PAGE_FAULTS}, + {.type = VIR_PERF_EVENT_CONTEXT_SWITCHES, + .attrType = PERF_TYPE_SOFTWARE, + .attrConfig = PERF_COUNT_SW_CONTEXT_SWITCHES}, }; typedef struct virPerfEventAttr *virPerfEventAttrPtr; diff --git a/src/util/virperf.h b/src/util/virperf.h index 182a9ec8b8..2adc549d90 100644 --- a/src/util/virperf.h +++ b/src/util/virperf.h @@ -50,6 +50,7 @@ typedef enum { VIR_PERF_EVENT_CPU_CLOCK, /* Count of cpu clock time*/ VIR_PERF_EVENT_TASK_CLOCK, /* Count of task clock time*/ VIR_PERF_EVENT_PAGE_FAULTS, /* Count of total page faults */ + VIR_PERF_EVENT_CONTEXT_SWITCHES, /* Count of context switches */ VIR_PERF_EVENT_LAST } virPerfEventType; diff --git a/tests/genericxml2xmlindata/generic-perf.xml b/tests/genericxml2xmlindata/generic-perf.xml index 3f27887212..29a227392d 100644 --- a/tests/genericxml2xmlindata/generic-perf.xml +++ b/tests/genericxml2xmlindata/generic-perf.xml @@ -29,6 +29,7 @@ + diff --git a/tools/virsh.pod b/tools/virsh.pod index 0f825c3d46..2347b53dfb 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -967,6 +967,7 @@ I<--perf> returns the statistics of all enabled perf events: "perf.cpu_clock" - the count of cpu clock time "perf.task_clock" - the count of task clock time "perf.page_faults" - the count of page faults + "perf.context_switches" - the count of context switches See the B command for more details about each event. @@ -2342,6 +2343,8 @@ B applications running on the platform. page_faults - Provides the count of page faults by applications running on the platform. + context_switches - Provides the count of context switches + by applications running on the platform. B: The statistics can be retrieved using the B command using the I<--perf> flag.