1. 6
  1. 1

    Recently I was trying to profile some code on macOS and discovered that perf and friends when run in a container/VM don’t have access to hardware performance counters. As far as I’m aware, that leaves you with DTrace (and potentially Instruments, I don’t know, I’ve never used it). I found this while looking for learning resources.

    1. 1

      As far as I’m aware, that leaves you with DTrace (and potentially Instruments, I don’t know, I’ve never used it)

      Instruments is a (very nice) DTrace GUI, so it will work if DTrace works. Hardware performance counters are available in VMs if the hypervisor virtualises them. I’m pretty sure both Xen and Hyper-V do, I think bhyve does, what are you using?

      1. 1

        I’m just using Docker or VirtualBox on my laptop. That’s good news about Instruments!

        1. 1

          I don’t think VirtualBox virtualises performance counters. Docker uses xhyve (a port of FreeBSD’s bhyve) to run on top of Apple’s hypervisor.framework, but I don’t think it did last time I looked, unless it’s something that the framework does transparently. What are you actually trying to measure though? Instruments is Mac only, are you running macOS inside the VM or trying to measure something about the VM from outside?

          1. 1

            I think there’s a miscommunication. I have a macOS laptop and I was trying to run some Linux profiling tools (perf, Cachegrind) on a binary inside of a Docker container. If you know of an equivalent to Cachegrind that has support for recent versions of macOS I would love to hear about it.

            1. 1

              Ah, I see. I was confused by your references to macOS tools, because macOS is completely irrelevant to your use case. Docker for Mac uses xhyve to run a Linux VM for each container, so macOS is completely out of the loop except to reserve some memory and schedule the VCPUs. The question is about tools that run inside a Linux VM.

              You’ll need a hypervisor that virtualises performance counters to be able to use things like perf. It looks as if VMWare supports it, Parallels might (though given that their response a bug that causes reproducible kernel panics was to demand more money for the version with the bug fix, they’re never getting my money ever again). Valgrind’s cachegrind doesn’t need performance counters but its cache model is not fantastic. Anything that uses binary instrumentation (e.g. gprof, DTrace’s FBT) will work.