Skip to content

Implement perf JIT reporting APIs#533

Merged
asherkin merged 4 commits intomasterfrom
perf-jit
Jun 29, 2021
Merged

Implement perf JIT reporting APIs#533
asherkin merged 4 commits intomasterfrom
perf-jit

Conversation

@asherkin
Copy link
Member

@asherkin asherkin commented Dec 23, 2020

Implemented here is the original perf JIT format which is widely supported but only supports simple name mapping, and the newer "jitdump" format which additionally supports embedding the machine code and source mapping information (along with a bunch of other things we don't currently have in the JIT).

Example usage:

# perf record -F 999 -g ./vm/spshell/linux-x86/spshell ./fib.smx
fib(42) = 267914296
[ perf record: Woken up 9 times to write data ]
[ perf record: Captured and wrote 2.124 MB perf.data (6339 samples) ]

# perf inject --jit -i perf.data -o perf.jit.data

# perf report -i perf.jit.data --stdio -q | head -n 15
    99.97%     0.00%  spshell  libc-2.29.so                [.] __libc_start_main
            |
            ---__libc_start_main
               main
               Execute
               sp::ScriptedInvoker::Invoke
               sp::PluginContext::Invoke
               sp::Environment::Invoke
               <jit invoke stub>
               fib.smx::main
               |
                --99.95%--fib.smx::fib
                          fib.smx::fib
                          fib.smx::fib
                          fib.smx::fib

Using the jitdump source mapping will probably require compiling perf from source, due to this bug, but it works very well.

@asherkin asherkin marked this pull request as ready for review December 27, 2020 13:27
@asherkin asherkin requested a review from dvander January 27, 2021 16:48
vm/linking.cpp Outdated
#if defined(KE_LINUX)
// These have to be shared among all environments, as the filenames are only distinguished by PID.
// Once we support multiple environments per process we'll need some internal locking.
static std::unique_ptr<PerfJitFile> perf_jit_file = {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be better to find a globally visible place to put these, but for now this is fine. You shouldn't need the initializer though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find a good spot elsewhere for these - any suggestions? I don't think we have any naturally global objects (Environments are the top-level instance), so they'd need to be global vars or static members of something (probably Environment?)

@peace-maker peace-maker added enhancement vm Concerning the virtual machine. labels Mar 12, 2021
vm/linking.cpp Outdated
// These have to be shared among all environments, as the filenames are only distinguished by PID.
// Once we support multiple environments per process we'll need some internal locking.
static std::unique_ptr<PerfJitFile> perf_jit_file;
static std::unique_ptr<PerfJitdumpFile> perf_jitdump_file;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine here. My thinking re: moving toward Environment was, that's all code we know has to be audited for a multi-threaded refactoring. But squirreled away here, no one is going to find it.

So if we keep it here, can we put a static std::mutex in and hold the lock while writing the perf data? Then we know it's at least future-proofed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the implementation out of linking and moved ownership of the files to Environment, I think that is looking a lot cleaner now indeed.

Copy link
Member

@dvander dvander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is indeed much nicer.

}
}

if (!pRuntime->Name())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This thing bugs me still, they're very different checks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old one was broken by previous refactoring elsewhere, the new one is the intended behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement vm Concerning the virtual machine.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants