I'd like to do some profiling and code coverage analysis on some C code. From webpages like here and here I see that I probably need tools like llvm-cov and llvm-profdata. But my Mac doesn't seem to have them. Anybody know how to install them?

[P.S. I can see from the tag description on [xcode] that "Almost all questions about development or app distribution are off topic here". I apologize in advance if mine is such a question. If someone can point me to a better place to ask, or even to the FAQs which the tag description cites, I'll be grateful.]

  • Do you want to use the GNU/Clang tools (as explained in the links you provided) or do you want to use Xcode? In the second case, did you already look at the developer documentation on apple.com?
    – nohillside
    Jan 28, 2022 at 13:05
  • @nohillside Well, what I want to do is profile some code I've been compiling with cc. I know that cc is really llvm/clang underneath, so I did a web search, and those links are what I came up with. And, no, I didn't look at the developer documentation on apple.com — frankly I wouldn't know where to start! Jan 28, 2022 at 13:29

1 Answer 1


Profiling can be done in Instruments, just build the release binary and run it via Instruments.app.

For code coverage, Use Xcode's code coverage in Edit scheme -> Test -> Gather coverage for ...

Xcode also contains llvm-profdata and llvm-cov in /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin. Put that in PATH and it should work normally.

If you have to use the llvm tools, either directly download from https://releases.llvm.org or use something like brew.

Here's how to make it work https://stackoverflow.com/a/63690216 with Xcode. If you just want to use terminal, simply changing SDKROOT and PATH is enough.

  • Thanks. I should perhaps have said that I'm doing everything on the command line. (I've never even heard of Instruments.) Jan 28, 2022 at 13:08
  • @SteveSummit: Instruments is a powerful tool, so you should check it out. If you have a lot of overlapping/concurrent things to analyze, look into signposts which Instruments can visualize.
    – DarkDust
    Jan 28, 2022 at 14:02
  • @anki This almost worked. It took a while (the package is big, and my home bandwidth is low, so it took several tries) but I got the llvm tools downloaded, and... they can't read the profile data files my instrumented code is generating, due to a version number mismatch in the profile data files. Dang. So now I'm downloading an older version... Jan 30, 2022 at 2:09
  • Version 9 worked, and I've found a hotspot already. Thanks again. Jan 30, 2022 at 4:57
  • @SteveSummit see the update apple.stackexchange.com/posts/436032/revisions
    – anki
    Jan 30, 2022 at 8:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .