-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[ctxprof] ProfileWriter abstraction #129590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,7 @@ | |
#include <iostream> | ||
|
||
using namespace llvm::ctx_profile; | ||
extern "C" bool __llvm_ctx_profile_fetch(void *Data, | ||
bool (*Writer)(void *, | ||
const ContextNode &)); | ||
extern "C" bool __llvm_ctx_profile_fetch(ProfileWriter &); | ||
|
||
// avoid name mangling | ||
extern "C" { | ||
|
@@ -46,22 +44,29 @@ __attribute__((noinline)) void theRoot() { | |
// CHECK-NEXT: check even | ||
// CHECK-NEXT: check odd | ||
|
||
void printProfile(const ContextNode &Node, const std::string &Indent, | ||
const std::string &Increment) { | ||
std::cout << Indent << "Guid: " << Node.guid() << std::endl; | ||
std::cout << Indent << "Entries: " << Node.entrycount() << std::endl; | ||
std::cout << Indent << Node.counters_size() << " counters and " | ||
<< Node.callsites_size() << " callsites" << std::endl; | ||
std::cout << Indent << "Counter values: "; | ||
for (uint32_t I = 0U; I < Node.counters_size(); ++I) | ||
std::cout << Node.counters()[I] << " "; | ||
std::cout << std::endl; | ||
for (uint32_t I = 0U; I < Node.callsites_size(); ++I) | ||
for (const auto *N = Node.subContexts()[I]; N; N = N->next()) { | ||
std::cout << Indent << "At Index " << I << ":" << std::endl; | ||
printProfile(*N, Indent + Increment, Increment); | ||
} | ||
} | ||
class TestProfileWriter : public ProfileWriter { | ||
void printProfile(const ContextNode &Node, const std::string &Indent, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it might be usefult to pass in a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a .cpp file that gets compiled (and run) as part of the test, so we basically have access to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To make things clear, here's an example of the usage I'm thinking of: https://github.com/llvm/llvm-project/blob/main/llvm/unittests/IR/MetadataTest.cpp#L164-L172 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to make sure we're talking about the same thing: this here is a lit test. Note the RUN lines at the top of the file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discussed offline and since this in compiler-rt its not useful to use ostream. |
||
const std::string &Increment) { | ||
std::cout << Indent << "Guid: " << Node.guid() << std::endl; | ||
std::cout << Indent << "Entries: " << Node.entrycount() << std::endl; | ||
std::cout << Indent << Node.counters_size() << " counters and " | ||
<< Node.callsites_size() << " callsites" << std::endl; | ||
std::cout << Indent << "Counter values: "; | ||
for (uint32_t I = 0U; I < Node.counters_size(); ++I) | ||
std::cout << Node.counters()[I] << " "; | ||
std::cout << std::endl; | ||
for (uint32_t I = 0U; I < Node.callsites_size(); ++I) | ||
for (const auto *N = Node.subContexts()[I]; N; N = N->next()) { | ||
std::cout << Indent << "At Index " << I << ":" << std::endl; | ||
printProfile(*N, Indent + Increment, Increment); | ||
} | ||
} | ||
|
||
public: | ||
void writeContextual(const ContextNode &RootNode) override { | ||
printProfile(RootNode, "", ""); | ||
} | ||
}; | ||
|
||
// 8657661246551306189 is theRoot. We expect 2 callsites and 2 counters - one | ||
// for the entry basic block and one for the loop. | ||
|
@@ -88,11 +93,8 @@ void printProfile(const ContextNode &Node, const std::string &Indent, | |
// CHECK-NEXT: Counter values: 2 1 | ||
|
||
bool profileWriter() { | ||
return __llvm_ctx_profile_fetch( | ||
nullptr, +[](void *, const ContextNode &Node) { | ||
printProfile(Node, "", " "); | ||
return true; | ||
}); | ||
TestProfileWriter W; | ||
return __llvm_ctx_profile_fetch(W); | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment to describe the interface and expected usage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done - briefly. Updated further up the change stack, where more members appear.