Not logged in. Login

Running Perf

You may need to run Perf to measure behaviour of code. It is restricted for security reasons, but there are a couple of options.

Note that Valdrind can be run on any machine (including any CSIL workstation or a VM). It doesn't need special permissions.

In A Virtual Machine: no

Perf won't give meaningful results in a virtual machine (including WSL2, Amazon EC2 instances, etc). The hardware counters that it uses are not passed through to VMs.

Your Computer, with admin access

If you have a non-VM Linux installation on your computer, then you should be able to run Perf.

User access to the performance counters isn't enabled by default: there are security implications, but if you broadly-trust everyone using your computer, you can temporarily enable (until reboot) with this command:

echo 0 | sudo tee /proc/sys/kernel/perf_event_paranoid

Or have it enabled on every restart with this command to create a config file to enable it:

echo "kernel.perf_event_paranoid = 0" | sudo tee /etc/sysctl.d/99-perf.conf

In CSIL

Perf has been enabled on a few CSIL workstations for use by this course. You can SSH to these computers and run Perf there. Your home directory should be there, so you can edit and compile on any CSIL machine, and just run code on these:

  • asb9838nu-b01.csil.sfu.ca
  • asb9838nu-d01.csil.sfu.ca
  • asb9838nu-e01.csil.sfu.ca

From Off-Campus

  1. Activate the SFU VPN.
  2. Edit your code on your computer, make sure it works, etc.
  3. Copy the source to CSIL: "scp -P24 code.c USERNAME@csil-cpu1.csil.sfu.ca:" or the equivalent in your favourite SCP/SFTP client.
  4. Connect to one of the perf-enabled CSIL workstations by SSH": "ssh -p24 USERNAME@COMPUTERNAME" or the equivalent in your favourite SSH client.
  5. In that remote SSH terminal, compile and run: "gcc … code.c" and "perf stat …".

From CSIL

  1. Edit your code on a CSIL workstation, make sure it works, etc.
  2. Compile it on the workstation.
  3. Connect to one of the perf-enabled CSIL workstations by SSH: "ssh -p24 USERNAME@COMPUTERNAME" in a terminal window.
  4. In that remote SSH terminal, run it: "perf stat …".

Demo Video

Demo of getting Perf running.

Updated Mon April 15 2024, 10:42 by ggbaker.