[PATCH 14/19] src: add constants for domain stats 'perf.' parameters

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Contrary to most APIs returning typed parameters, there are no constants
defined for the domain stats data keys. This is was because many of the
keys needs to be dynamically constructed using one or more array index
values.

It is possible to define constants while still supporting dynamic
array indexes by simply defining the prefixes and suffixes as constants.
The consuming code can then combine the constants with array index
value.

With this approach, it is practical to add constants for the domain stats
API keys.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 include/libvirt/libvirt-domain.h | 224 +++++++++++++++++++++++++++++++
 src/libvirt-domain.c             |  68 +---------
 src/qemu/qemu_driver.c           |  35 ++++-
 3 files changed, 260 insertions(+), 67 deletions(-)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 0360e163ca..abdefe6aec 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -3463,6 +3463,230 @@ struct _virDomainStatsRecord {
  */
 #define VIR_DOMAIN_STATS_BLOCK_SUFFIX_THRESHOLD ".threshold"
 
+
+/**
+ * VIR_DOMAIN_STATS_PERF_CMT:
+ *
+ * The usage of l3 cache (bytes) by applications running on the platform as
+ * unsigned long long. It is produced by the cmt perf event.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_PERF_CMT "perf.cmt"
+
+/**
+ * VIR_DOMAIN_STATS_PERF_MBMT:
+ *
+ * The total system bandwidth (bytes/s) from one level of cache to another as
+ * unsigned long long. It is produced by the mbmt perf event.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_PERF_MBMT "perf.mbmt"
+
+/**
+ * VIR_DOMAIN_STATS_PERF_MBML:
+ *
+ * The amount of data (bytes/s) sent through the memory controller on the
+ * socket as unsigned long long. It is produced by the mbml perf event.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_PERF_MBML "perf.mbml"
+
+/**
+ * VIR_DOMAIN_STATS_PERF_CACHE_MISSES:
+ *
+ * The count of cache misses as unsigned long long. It is produced by the
+ * cache_misses perf event.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_PERF_CACHE_MISSES "perf.cache_misses"
+
+/**
+ * VIR_DOMAIN_STATS_PERF_CACHE_REFERENCES:
+ *
+ * The count of cache hits as unsigned long long. It is produced by the
+ * cache_references perf event.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_PERF_CACHE_REFERENCES "perf.cache_references"
+
+/**
+ * VIR_DOMAIN_STATS_PERF_INSTRUCTIONS:
+ *
+ * The count of instructions as unsigned long long. It is produced by the
+ * instructions perf event.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_PERF_INSTRUCTIONS "perf.instructions"
+
+/**
+ * VIR_DOMAIN_STATS_PERF_CPU_CYCLES:
+ *
+ * The count of cpu cycles (total/elapsed) as an unsigned long long. It is
+ * produced by the cpu_cycles perf event.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_PERF_CPU_CYCLES "perf.cpu_cycles"
+
+/**
+ * VIR_DOMAIN_STATS_PERF_BRANCH_INSTRUCTIONS:
+ *
+ * The count of branch instructions as unsigned long long. It is produced by
+ * the branch_instructions perf event.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_PERF_BRANCH_INSTRUCTIONS "perf.branch_instructions"
+
+/**
+ * VIR_DOMAIN_STATS_PERF_BRANCH_MISSES:
+ *
+ * The count of branch misses as unsigned long long. It is produced by the
+ * branch_misses perf event.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_PERF_BRANCH_MISSES "perf.branch_misses"
+
+/**
+ * VIR_DOMAIN_STATS_PERF_BUS_CYCLES:
+ *
+ * The count of bus cycles as unsigned long long. It is produced by the
+ * bus_cycles perf event.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_PERF_BUS_CYCLES "perf.bus_cycles"
+
+/**
+ * VIR_DOMAIN_STATS_PERF_STALLED_CYCLES_FRONTEND:
+ *
+ * The count of stalled cpu cycles in the frontend of the instruction processor
+ * pipeline as unsigned long long. It is produced by the
+ * stalled_cycles_frontend perf event.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_PERF_STALLED_CYCLES_FRONTEND "perf.stalled_cycles_frontend"
+
+/**
+ * VIR_DOMAIN_STATS_PERF_STALLED_CYCLES_BACKEND:
+ *
+ * The count of stalled cpu cycles in the backend of the instruction processor
+ * pipeline as unsigned long long. It is produced by the stalled_cycles_backend
+ * perf event.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_PERF_STALLED_CYCLES_BACKEND "perf.stalled_cycles_backend"
+
+/**
+ * VIR_DOMAIN_STATS_PERF_REF_CPU_CYCLES:
+ *
+ * The count of total cpu cycles not affected by CPU frequency scaling by
+ * applications running as unsigned long long. It is produced by the
+ * ref_cpu_cycles perf event.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_PERF_REF_CPU_CYCLES "perf.ref_cpu_cycles"
+
+/**
+ * VIR_DOMAIN_STATS_PERF_CPU_CLOCK:
+ *
+ * The count of cpu clock time as unsigned long long. It is produced by the
+ * cpu_clock perf event.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_PERF_CPU_CLOCK "perf.cpu_clock"
+
+/**
+ * VIR_DOMAIN_STATS_PERF_TASK_CLOCK:
+ *
+ * The count of task clock time as unsigned long long. It is produced by the
+ * task_clock perf event.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_PERF_TASK_CLOCK "perf.task_clock"
+
+/**
+ * VIR_DOMAIN_STATS_PERF_PAGE_FAULTS:
+ *
+ * The count of page faults as unsigned long long. It is produced by the
+ * page_faults perf event
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_PERF_PAGE_FAULTS "perf.page_faults"
+
+/**
+ * VIR_DOMAIN_STATS_PERF_CONTEXT_SWITCHES:
+ *
+ * The count of context switches as unsigned long long. It is produced by the
+ * context_switches perf event.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_PERF_CONTEXT_SWITCHES "perf.context_switches"
+
+/**
+ * VIR_DOMAIN_STATS_PERF_CPU_MIGRATIONS:
+ *
+ * The count of cpu migrations, from one logical processor to another, as
+ * unsigned long long. It is produced by the cpu_migrations perf event.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_PERF_CPU_MIGRATIONS "perf.cpu_migrations"
+
+/**
+ * VIR_DOMAIN_STATS_PERF_PAGE_FAULTS_MIN:
+ *
+ * The count of minor page faults as unsigned long long. It is produced by the
+ * page_faults_min perf event.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_PERF_PAGE_FAULTS_MIN "perf.page_faults_min"
+
+/**
+ * VIR_DOMAIN_STATS_PERF_PAGE_FAULTS_MAJ:
+ *
+ * The count of major page faults as unsigned long long. It is produced by the
+ * page_faults_maj perf event.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_PERF_PAGE_FAULTS_MAJ "perf.page_faults_maj"
+
+/**
+ * VIR_DOMAIN_STATS_PERF_ALIGNMENT_FAULTS:
+ *
+ * The count of alignment faults as unsigned long long. It is produced by the
+ * alignment_faults perf event
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_PERF_ALIGNMENT_FAULTS "perf.alignment_faults"
+
+/**
+ * VIR_DOMAIN_STATS_PERF_EMULATION_FAULTS:
+ *
+ * The count of emulation faults as unsigned long long. It is produced by the
+ * emulation_faults perf event
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_PERF_EMULATION_FAULTS "perf.emulation_faults"
+
 /**
  * virDomainStatsTypes:
  *
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 90eecea641..516957a106 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -12288,72 +12288,8 @@ virConnectGetDomainCapabilities(virConnectPtr conn,
  *
  * VIR_DOMAIN_STATS_PERF:
  *     Return perf event statistics.
- *     The typed parameter keys are in this format:
- *
- *     "perf.cmt" - the usage of l3 cache (bytes) by applications running on
- *                  the platform as unsigned long long. It is produced by cmt
- *                  perf event.
- *     "perf.mbmt" - the total system bandwidth (bytes/s) from one level of
- *                   cache to another as unsigned long long. It is produced
- *                   by mbmt perf event.
- *     "perf.mbml" - the amount of data (bytes/s) sent through the memory
- *                   controller on the socket as unsigned long long. It is
- *                   produced by mbml perf event.
- *     "perf.cache_misses" - the count of cache misses as unsigned long long.
- *                           It is produced by cache_misses perf event.
- *     "perf.cache_references" - the count of cache hits as unsigned long long.
- *                               It is produced by cache_references perf event.
- *     "perf.instructions" - The count of instructions as unsigned long long.
- *                           It is produced by instructions perf event.
- *     "perf.cpu_cycles" - The count of cpu cycles (total/elapsed) as an
- *                         unsigned long long. It is produced by cpu_cycles
- *                         perf event.
- *     "perf.branch_instructions" - The count of branch instructions as
- *                                  unsigned long long. It is produced by
- *                                  branch_instructions perf event.
- *     "perf.branch_misses" - The count of branch misses as unsigned long
- *                            long. It is produced by branch_misses perf event.
- *     "perf.bus_cycles" - The count of bus cycles as unsigned long
- *                         long. It is produced by bus_cycles perf event.
- *     "perf.stalled_cycles_frontend" - The count of stalled cpu cycles in the
- *                                      frontend of the instruction processor
- *                                      pipeline as unsigned long long. It is
- *                                      produced by stalled_cycles_frontend
- *                                      perf event.
- *     "perf.stalled_cycles_backend"  - The count of stalled cpu cycles in the
- *                                      backend of the instruction processor
- *                                      pipeline as unsigned long long. It is
- *                                      produced by stalled_cycles_backend
- *                                      perf event.
- *     "perf.ref_cpu_cycles" - The count of total cpu cycles not affected by
- *                             CPU frequency scaling by applications running
- *                             as unsigned long long. It is produced by the
- *                             ref_cpu_cycles perf event.
- *     "perf.cpu_clock" - The count of cpu clock time as unsigned long long.
- *                        It is produced by the cpu_clock perf event.
- *     "perf.task_clock" - The count of task clock time as unsigned long long.
- *                         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.
- *     "perf.cpu_migrations" - The count of cpu migrations, from one logical
- *                             processor to another, as unsigned long
- *                             long. It is produced by the cpu_migrations
- *                             perf event.
- *     "perf.page_faults_min" - The count of minor page faults as unsigned
- *                              long long. It is produced by the
- *                              page_faults_min perf event.
- *     "perf.page_faults_maj" - The count of major page faults as unsigned
- *                              long long. It is produced by the
- *                              page_faults_maj perf event.
- *     "perf.alignment_faults" - The count of alignment faults as unsigned
- *                               long long. It is produced by the
- *                               alignment_faults perf event
- *     "perf.emulation_faults" - The count of emulation faults as unsigned
- *                               long long. It is produced by the
- *                               emulation_faults perf event
+ *     The VIR_DOMAIN_STATS_PERF_* constants define the known typed
+ *     parameter keys.
  *
  * VIR_DOMAIN_STATS_IOTHREAD:
  *     Return IOThread statistics if available. IOThread polling is a
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 6f9e0270dc..d964a67574 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -17644,11 +17644,44 @@ qemuDomainGetStatsPerfOneEvent(virPerf *perf,
                                virTypedParamList *params)
 {
     uint64_t value = 0;
+#define MAP(NAME) \
+    [VIR_PERF_EVENT_ ## NAME] = VIR_DOMAIN_STATS_PERF_ ## NAME
+
+    static const char *keys[] = {
+        MAP(CMT),
+        MAP(MBMT),
+        MAP(MBML),
+        MAP(CPU_CYCLES),
+        MAP(INSTRUCTIONS),
+
+        MAP(CACHE_REFERENCES),
+        MAP(CACHE_MISSES),
+        MAP(BRANCH_INSTRUCTIONS),
+        MAP(BRANCH_MISSES),
+        MAP(BUS_CYCLES),
+
+        MAP(STALLED_CYCLES_FRONTEND),
+        MAP(STALLED_CYCLES_BACKEND),
+        MAP(REF_CPU_CYCLES),
+        MAP(CPU_CLOCK),
+        MAP(TASK_CLOCK),
+
+        MAP(PAGE_FAULTS),
+        MAP(CONTEXT_SWITCHES),
+        MAP(CPU_MIGRATIONS),
+        MAP(PAGE_FAULTS_MIN),
+        MAP(PAGE_FAULTS_MAJ),
+
+        MAP(ALIGNMENT_FAULTS),
+        MAP(EMULATION_FAULTS),
+    };
+#undef MAP
+    G_STATIC_ASSERT(G_N_ELEMENTS(keys) == VIR_PERF_EVENT_LAST);
 
     if (virPerfReadEvent(perf, type, &value) < 0)
         return;
 
-    virTypedParamListAddULLong(params, value, "perf.%s", virPerfEventTypeToString(type));
+    virTypedParamListAddULLong(params, value, "%s", keys[type]);
 }
 
 static void
-- 
2.48.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux