1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

[llvm-exegesis][NFC] Let the pfm::Counter own the PerfHelper.

A perf helper is always only ever cretaed to be checked for validity
then passed as Counter ctor argument, never to be touched again.
Its lifetime should outlive that of the counter, and there is never any
reason to have two different counters of top of the perf helper.
Make sure these assumptions always hold by making the Counter consume the
PerfHelper.
This commit is contained in:
Clement Courbet 2020-04-08 14:37:38 +02:00
parent bd356ab8f2
commit 1f97534ae0
4 changed files with 6 additions and 5 deletions

View File

@ -55,7 +55,7 @@ private:
if (!PerfEvent.valid())
return make_error<Failure>(
Twine("invalid perf event '").concat(CounterName).concat("'"));
pfm::Counter Counter(PerfEvent);
pfm::Counter Counter(std::move(PerfEvent));
Scratch->clear();
{
CrashRecoveryContext CRC;

View File

@ -88,7 +88,7 @@ StringRef PerfEvent::getPfmEventString() const {
}
#ifdef HAVE_LIBPFM
Counter::Counter(const PerfEvent &Event) {
Counter::Counter(PerfEvent &&E) : Event(std::move(E)){
assert(Event.valid());
const pid_t Pid = 0; // measure current process/thread.
const int Cpu = -1; // measure any processor.

View File

@ -65,7 +65,7 @@ private:
// underlying event.
struct Counter {
// event: the PerfEvent to measure.
explicit Counter(const PerfEvent &event);
explicit Counter(PerfEvent &&event);
Counter(const Counter &) = delete;
Counter(Counter &&other) = default;
@ -77,6 +77,7 @@ struct Counter {
int64_t read() const; // Return the current value of the counter.
private:
PerfEvent Event;
#ifdef HAVE_LIBPFM
int FileDescriptor = -1;
#endif

View File

@ -22,11 +22,11 @@ using ::testing::Not;
TEST(PerfHelperTest, FunctionalTest) {
#ifdef HAVE_LIBPFM
ASSERT_FALSE(pfmInitialize());
const PerfEvent Event("CYCLES:u");
PerfEvent Event("CYCLES:u");
ASSERT_TRUE(Event.valid());
EXPECT_EQ(Event.name(), "CYCLES:u");
EXPECT_THAT(Event.getPfmEventString(), Not(IsEmpty()));
Counter Cnt(Event);
Counter Cnt(std::move(Event));
Cnt.start();
Cnt.stop();
Cnt.read();