Skip to contentSkip to conversation

PATCH: pretty print for xenperf

PATCH Tristan Gingold 3 participants 3 messages Aug 11, 2006

lore
Share & tools
lore
#0 lore raw

Hi,

this is almost an ia64 specific patch to xenperf.
It makes xenperf output more understandable.
On x86, it now displays hypercalls name.

Tested on xen/ia64.

Tristan.

# HG changeset patch
# User gingold@virtu10
# Node ID 00f21b3c2c7df0251c56c4ffcb891e96f8df9a54 # Parent f5a4620c4ece5a6fd5607cc865b2d391f5ed2a73 Pretty print option added.

tools/misc/xenperf.c +280 -21
diff -r f5a4620c4ece -r 00f21b3c2c7d tools/misc/xenperf.c
@@ -17,15 +17,261 @@
 #include <sys/mman.h>
 #include <errno.h>
 #include <string.h>
+#include <xen/xen.h>
+
+static void disp_perfc (int full,
+						xc_perfc_desc_t *pcd,
+						xc_perfc_val_t *val)
+{
+	 unsigned int sum;
+	 int j;
+
+	 printf ("%-35s ", pcd->name);
+				 
+	 sum = 0;
+	 for ( j = 0; j < pcd->nr_vals; j++ )
+		  sum += val[j];
+	 printf ("T=%10u ", (unsigned int)sum);
+				 
+	 if ( full || (pcd->nr_vals <= 4) )
+		  for ( j = 0; j < pcd->nr_vals; j++ )
+			   printf(" %10u", (unsigned int)val[j]);
+				 
+	 printf("\n");
+}
+
+static const char * const ia64_hyperpriv[] = {
+	"panic", "rfi", "rsm.dt", "ssm.dt", "cover", "itc.d", "itc.i", "ssm.i",
+	"=ivr", "=tpr", "tpr=", "eoi", "itm=", "thash", "ptc.ga", "itr.d",
+	"=rr", "rr=", "kr=", "fc", "=cpuid", "=pmd", "=ar.eflg", "ar.eflg=",
+	"rsm.be", "=psr"
+};
+#define IA64_HYPERPRIV_NBR (sizeof(ia64_hyperpriv)/sizeof(char *))
+
+#define IA64_PRIVOP_MISC_NBR 64
+static const char * const ia64_privop_misc[IA64_PRIVOP_MISC_NBR] = {
+	"mov_to_rr", "mov_to_dbr", "mov_to_ibr", "mov_to_pkr",
+	"mov_to_pmc", "mov_to_pmd", "<0x06>", "<0x07>",
+	"<0x08>", "ptc_l", "ptc_g", "ptc_ga",
+	"ptr_d", "ptr_i", "itr_d", "itr_i",
+	"mov_from_rr", "mov_from_dbr", "mov_from_ibr", "mov_from_pkr",
+	"mov_from_pmc", "<0x15>", "<0x16>", "<0x17>",
+	"<0x18>", "<0x19>", "privified-thash", "privified-ttag",
+	"<0x1c>", "<0x1d>", "tpa", "tak",
+	"<0x20>", "<0x21>", "<0x22>", "<0x23>",
+	"mov_from_cr", "mov_from_psr", "<0x26>", "<0x27>",
+	"<0x28>", "<0x29>", "<0x2a>", "<0x2b>",
+	"mov_to_cr", "mov_to_psr", "itc_d", "itc_i",
+	"<0x30>", "<0x31>", "<0x32>", "<0x33>",
+	"ptc_e", "<0x35>", "<0x36>", "<0x37>",
+	"<0x38>", "<0x39>", "<0x3a>", "<0x3b>",
+	"<0x3c>", "<0x3d>", "<0x3e>", "<0x3f>"
+};
+
+#define RS "??"
+#define IA64_CR_NBR 128
+static const char * const ia64_cr[IA64_CR_NBR] = {
+	"dcr","itm","iva",RS,RS,RS,RS,RS,
+	"pta",RS,RS,RS,RS,RS,RS,RS,
+	"ipsr","isr",RS,"iip","ifa","itir","iipa","ifs",
+	"iim","iha",RS,RS,RS,RS,RS,RS,
+	RS,RS,RS,RS,RS,RS,RS,RS, RS,RS,RS,RS,RS,RS,RS,RS,
+	RS,RS,RS,RS,RS,RS,RS,RS, RS,RS,RS,RS,RS,RS,RS,RS,
+	"lid","ivr","tpr","eoi","irr0","irr1","irr2","irr3",
+	"itv","pmv","cmcv",RS,RS,RS,RS,RS,
+	"lrr0","lrr1",RS,RS,RS,RS,RS,RS,
+	RS,RS,RS,RS,RS,RS,RS,RS, RS,RS,RS,RS,RS,RS,RS,RS,
+	RS,RS,RS,RS,RS,RS,RS,RS, RS,RS,RS,RS,RS,RS,RS,RS,
+	RS,RS,RS,RS,RS,RS,RS,RS
+};
+
+static const char * const hypercalls_name[] = {
+	 [__HYPERVISOR_set_trap_table] = "set_trap_table",
+	 [__HYPERVISOR_mmu_update] = "mmu_update",
+	 [__HYPERVISOR_set_gdt] = "set_gdt",
+	 [__HYPERVISOR_stack_switch] = "stack_switch",
+	 [__HYPERVISOR_set_callbacks] = "set_callbacks",
+	 [__HYPERVISOR_fpu_taskswitch] = "fpu_taskswitch",
+	 [__HYPERVISOR_sched_op_compat] = "sched_op_compat",
+	 [__HYPERVISOR_dom0_op] = "dom0_op",
+	 [__HYPERVISOR_set_debugreg] = "set_debugreg",
+	 [__HYPERVISOR_get_debugreg] = "get_debugreg",
+	 [__HYPERVISOR_update_descriptor] = "update_descriptor",
+	 [__HYPERVISOR_memory_op] = "memory_op",
+	 [__HYPERVISOR_multicall] = "multicall",
+	 [__HYPERVISOR_update_va_mapping] = "update_va_mapping",
+	 [__HYPERVISOR_set_timer_op] = "set_timer_op",
+	 [__HYPERVISOR_event_channel_op_compat] = "event_channel_op_compat",
+	 [__HYPERVISOR_xen_version] = "xen_version",
+	 [__HYPERVISOR_console_io] = "console_io",
+	 [__HYPERVISOR_physdev_op_compat] = "physdev_op_compat",
+	 [__HYPERVISOR_grant_table_op] = "grant_table_op",
+	 [__HYPERVISOR_vm_assist] = "vm_assist",
+	 [__HYPERVISOR_update_va_mapping_otherdomain] = "update_va_mapping_otherdomain",
+	 [__HYPERVISOR_iret] = "iret",
+	 [__HYPERVISOR_vcpu_op] = "vcpu_op",
+	 [__HYPERVISOR_set_segment_base] = "set_segment_base",
+	 [__HYPERVISOR_mmuext_op] = "mmuext_op",
+	 [__HYPERVISOR_acm_op] = "acm_op",
+	 [__HYPERVISOR_nmi_op] = "nmi_op",
+	 [__HYPERVISOR_sched_op] = "sched_op",
+	 [__HYPERVISOR_callback_op] = "callback_op",
+	 [__HYPERVISOR_xenoprof_op] = "xenoprof_op",
+	 [__HYPERVISOR_event_channel_op] = "event_channel_op",
+	 [__HYPERVISOR_physdev_op] = "physdev_op",
+	 [__HYPERVISOR_hvm_op] = "hvm_op",
+#ifdef __ia64__
+	 [__HYPERVISOR_arch_0] = "dom0vp",
+#else
+	 [__HYPERVISOR_arch_0] = "arch_0",
+#endif
+	 [__HYPERVISOR_arch_1] = "arch_1",
+	 [__HYPERVISOR_arch_2] = "arch_2",
+	 [__HYPERVISOR_arch_3] = "arch_3",
+	 [__HYPERVISOR_arch_4] = "arch_4",
+	 [__HYPERVISOR_arch_5] = "arch_5",
+	 [__HYPERVISOR_arch_6] = "arch_6",
+	 [__HYPERVISOR_arch_7] = "arch_7"
+};
+#define HYPERCALLS_NAME_NR (sizeof(hypercalls_name)/sizeof(char*))
+
+static void pretty_print (xc_perfc_desc_t *desc, int num_desc,
+						  xc_perfc_val_t *val, int num_val,
+						  int full)
+{
+	int i, j;
+
+	for ( i = 0; i < num_desc; i++, desc++ )
+	{
+		 unsigned int sum = 0;
+
+		 for (j = 0; j < desc->nr_vals; j++)
+			  sum += val[j];
+
+		 if (!strcmp(desc->name, "slow hyperprivops")
+			 || !strcmp(desc->name, "fast hyperprivops"))
+		 {
+			  printf ("%s:\n", desc->name);
+			  for (j = 0; j < desc->nr_vals; j++)
+			  {
+				   if (*val != 0)
+						printf ("  %-10s: %10u\n",
+								j < IA64_HYPERPRIV_NBR ?
+								ia64_hyperpriv[j] : "??",
+								*val);
+				   val++;
+			  }
+		 }
+		 else if (!strcmp(desc->name, "slow reflection")
+			 || !strcmp(desc->name, "fast reflection"))
+		 {
+			  int cnt = 0;
+
+			  printf ("%s:\n", desc->name);
+			  for (j = 0; j < desc->nr_vals; j++)
+			  {
+				   if (*val != 0)
+				   {
+						printf ("  %04x: %-10u", j << 8, *val);
+						if ((cnt & 3) == 3)
+							printf ("\n");
+						cnt++;
+				   }
+				   val++;
+			  }
+			  if (cnt & 3)
+				   printf ("\n");
+		 }
+		 else if (!strcmp(desc->name, "privop misc"))
+		 {
+			  printf ("%s:\n", desc->name);
+			  for (j = 0; j < desc->nr_vals; j++)
+			  {
+				   if (*val != 0)
+						printf ("  %-16s: %u\n",
+								j < IA64_PRIVOP_MISC_NBR ?
+								ia64_privop_misc[j] : "??",
+								*val);
+				   val++;
+			  }
+		 }
+		 else if (!strcmp(desc->name, "privop mov to cr")
+			 || !strcmp(desc->name, "privop mov from cr"))
+		 {
+			  printf ("%s: %u\n", desc->name, sum);
+			  for (j = 0; j < desc->nr_vals; j++)
+			  {
+				   if (*val != 0)
+						printf ("  %-16s: %u (%d%%)\n",
+								j < IA64_CR_NBR ? ia64_cr[j] : "??",
+								*val,
+								(*val * 100) / sum);
+				   val++;
+			  }
+		 }
+		 else if (!memcmp (desc->name, "privop-addrs addr ", 18))
+		 {
+			  const char *name = desc->name + 18;
+			  int nb_addrs = desc->nr_vals;
+			  if (i + 2 >= num_desc
+				  || memcmp (desc[1].name, "privop-addrs count ", 19)
+				  || strcmp (desc[1].name + 19, name)
+				  || memcmp (desc[2].name, "privop-addrs overflow ", 22)
+				  || strcmp (desc[2].name + 22, name)
+				  || desc[1].nr_vals != nb_addrs
+				  || desc[2].nr_vals != 1)
+			  {
+				   disp_perfc (0, desc, val);
+				   val += desc->nr_vals;
+			  }
+			  else
+			  {
+				   printf ("privop addrs for %s\n", name);
+				   for (j = 0; j < nb_addrs; j++)
+				   {
+						if (val[j] == 0)
+							 break;
+						printf ("  %08x: %u\n",
+								val[j], val[nb_addrs + j]);
+				   }
+				   val += 2 * nb_addrs;
+				   printf ("    overflows: %u\n", *val);
+				   val++;
+				   /* Skip the next two entries.  */
+				   desc += 2;
+				   i += 2;
+			  }
+		 }
+		 else if (!strcmp(desc->name, "hypercalls"))
+		 {
+			  printf ("%s: T=%u\n", desc->name, sum);
+			  for (j = 0; j < desc->nr_vals; j++)
+			  {
+				   if (*val != 0)
+						printf ("  %-34s: %u\n",
+								j < HYPERCALLS_NAME_NR && hypercalls_name[j] ?
+								hypercalls_name[j] : "??",
+								*val);
+				   val++;
+			  }
+		 }
+		 else
+		 {
+			  disp_perfc (full, desc, val);
+			  val += desc->nr_vals;
+		 }
+	}
+}
 
 int main(int argc, char *argv[])
 {
-    int              i, j, xc_handle;
+    int              i, xc_handle;
     xc_perfc_desc_t *pcd;
 	xc_perfc_val_t  *pcv;
 	xc_perfc_val_t  *val;
 	int num_desc, num_val;
-    unsigned int    sum, reset = 0, full = 0;
+    unsigned int    reset = 0, full = 0;
+	enum { DISP_SHORT, DISP_LIST, DISP_PRETTY} act = DISP_PRETTY;
 
     if ( argc > 1 )
     {
@@ -35,7 +281,16 @@ int main(int argc, char *argv[])
             switch ( p[1] )
             {
             case 'f':
-                full = 1;
+				full = 1;
+                break;
+            case 'l':
+                act = DISP_LIST;
+                break;
+            case 'p':
+                act = DISP_PRETTY;
+                break;
+            case 's':
+                act = DISP_SHORT;
                 break;
             case 'r':
                 reset = 1;
@@ -47,10 +302,13 @@ int main(int argc, char *argv[])
         else
         {
         error:
-            printf("%s: [-r]\n", argv[0]);
+            printf("%s: [-r] [-f] [-l|-p]\n", argv[0]);
             printf("no args: print digested counters\n");
+            printf("    -r : reset counters\n");
             printf("    -f : print full arrays/histograms\n");
-            printf("    -r : reset counters\n");
+            printf("    -s : short print\n");
+            printf("    -l : list counters\n");
+            printf("    -p : pretty print (default)\n");
             return 0;
         }
     }   
@@ -108,22 +366,23 @@ int main(int argc, char *argv[])
     munlock(pcv, sizeof(*pcv) * num_val);
 
 	val = pcv;
-    for ( i = 0; i < num_desc; i++ )
-    {
-        printf ("%-35s ", pcd[i].name);
-        
-        sum = 0;
-        for ( j = 0; j < pcd[i].nr_vals; j++ )
-            sum += val[j];
-        printf ("T=%10u ", (unsigned int)sum);
-
-        if ( full || (pcd[i].nr_vals <= 4) )
-            for ( j = 0; j < pcd[i].nr_vals; j++ )
-                printf(" %10u", (unsigned int)val[j]);
-
-        printf("\n");
-		val += pcd[i].nr_vals;
-    }
+	switch (act)
+		{
+		case DISP_SHORT:
+			for ( i = 0; i < num_desc; i++ )
+			{
+				 disp_perfc (full, &pcd[i], val);
+				 val += pcd[i].nr_vals;
+			}
+			break;
+		case DISP_LIST:
+			for ( i = 0; i < num_desc; i++ )
+				printf ("%-35s : %u\n", pcd[i].name, pcd[i].nr_vals);
+			break;
+		case DISP_PRETTY:
+			pretty_print (pcd, num_desc, pcv, num_val, full);
+			break;
+		}
 
     return 0;
 }

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 4 lines · Tristan Gingold

this is almost an ia64 specific patch to xenperf.
It makes xenperf output more understandable.
On x86, it now displays hypercalls name.

I don't see how this approach will support other architectures cleanly.

Also, you need to double-check all your whitespace.

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
#2 lore raw
Quoted 5 lines · Hollis Blanchard
Quoted 3 lines

this is almost an ia64 specific patch to xenperf.
It makes xenperf output more understandable.
On x86, it now displays hypercalls name.

I don't see how this approach will support other architectures cleanly.

Agreed. We should arrange for the pretty-print strings to be supplied by Xen. If the perfctr protocol to userspace needs cleaning up or extending to do this then that's not a problem.

-- Keir