0

I am trying to profile an application inside an Azure VM (Ubuntu 18.04) using the perf. But the perf stats doesn't provide all the statistics.

Performance counter stats for 'ls':

          0.78 msec task-clock                #    0.760 CPUs utilized          
             1      context-switches          #    0.001 M/sec                  
             0      cpu-migrations            #    0.000 K/sec                  
           106      page-faults               #    0.135 M/sec                  
<not supported>      cycles                                                      
<not supported>      instructions                                                
<not supported>      branches                                                    
<not supported>      branch-misses                                               

   0.001031061 seconds time elapsed

   0.001016000 seconds user
   0.000000000 seconds sys

And, also the perf list doesn't list any hardware events.

List of pre-defined events (to be used in -e):

alignment-faults                                   [Software event]
bpf-output                                         [Software event]
context-switches OR cs                             [Software event]
cpu-clock                                          [Software event]
cpu-migrations OR migrations                       [Software event]
dummy                                              [Software event]
emulation-faults                                   [Software event]
major-faults                                       [Software event]
minor-faults                                       [Software event]
page-faults OR faults                              [Software event]
task-clock                                         [Software event]

duration_time                                      [Tool event]

msr/pperf/                                         [Kernel PMU event]
msr/smi/                                           [Kernel PMU event]
msr/tsc/                                           [Kernel PMU event]

rNNN                                               [Raw hardware event descriptor]
cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]

I read that the CPU performance counters are not enabled for the VMs source.

Is it possible to enable the hardware events in Azure VM? or is there any other way to find the instructions used while executing an application?

Naren
  • 2,171
  • 1
  • 25
  • 44
  • 1
    Most VMs don't virtualize and pass through the PMU HW performance counters. I think Linux KVM was working on it, but IDK if even that is done yet. – Peter Cordes Sep 29 '21 at 19:30
  • 1
    If you don't care about timing, just counting instructions, you could use dynamic instrumentation or emulation. e.g. Intel's SDE has an instruction-mix counter that can even break things down by mnemonic. See [How do I monitor the amount of SIMD instruction usage](https://stackoverflow.com/q/60104698) for example. – Peter Cordes Sep 29 '21 at 19:34
  • @PeterCordes Thanks for your input. I will try dynamic instrumentation. – Naren Oct 04 '21 at 09:33

1 Answers1

0

With VM, we cannot use hardware PMU events in perf from within a virtual machine guest on Linux.

Reference So Thread: Running perf within a VirtualBox guest

We can collect Windows and Linux performance data sources with Log Analytics agent

Refernce: https://docs.microsoft.com/en-us/azure/azure-monitor/agents/data-sources-performance-counters

Adding Linux performance counters

enter image description here

Follow this procedure to add a new Linux performance counter to collect.

  1. Click Add performance counter.
  2. Type the name of the counter in the text box in the format object(instance)\counter. When you start typing, you are presented with a matching list of common counters. You can either select a counter from the list or type in one of your own.
  3. All counters for an object use the same Sample Interval. The default is 10 seconds. You change this to a higher value of up to 1800 seconds (30 minutes) if you want to reduce the storage requirements of the collected performance data.
  4. When you're done adding counters, click the Apply button at the top of the screen to save the configuration.

Configure Linux performance counters in configuration file

Instead of configuring Linux performance counters using the Azure portal, you have the option of editing configuration files on the Linux agent. Performance metrics to collect are controlled by the configuration in /etc/opt/microsoft/omsagent//conf/omsagent.conf.

Each object, or category, of performance metrics to collect should be defined in the configuration file as a single element. The syntax follows the pattern below.