[llvm] r332330 - [llvm-exegesis] Check perf event validity.
Clement Courbet via llvm-commits
llvm-commits at lists.llvm.org
Tue May 15 00:35:21 PDT 2018
Author: courbet
Date: Tue May 15 00:35:21 2018
New Revision: 332330
URL: http://llvm.org/viewvc/llvm-project?rev=332330&view=rev
Log:
[llvm-exegesis] Check perf event validity.
This was part of https://reviews.llvm.org/D46821.
Authored by Guillaume Chatelet
Modified:
llvm/trunk/tools/llvm-exegesis/lib/PerfHelper.cpp
Modified: llvm/trunk/tools/llvm-exegesis/lib/PerfHelper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/PerfHelper.cpp?rev=332330&r1=332329&r2=332330&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/PerfHelper.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/PerfHelper.cpp Tue May 15 00:35:21 2018
@@ -15,6 +15,7 @@
#include "perfmon/pfmlib.h"
#include "perfmon/pfmlib_perf_event.h"
#endif
+#include <cassert>
namespace exegesis {
namespace pfm {
@@ -88,6 +89,7 @@ llvm::StringRef PerfEvent::getPfmEventSt
#ifdef HAVE_LIBPFM
Counter::Counter(const PerfEvent &Event) {
+ assert(Event.valid());
const pid_t Pid = 0; // measure current process/thread.
const int Cpu = -1; // measure any processor.
const int GroupFd = -1; // no grouping of counters.
@@ -108,8 +110,10 @@ void Counter::stop() { ioctl(FileDescrip
int64_t Counter::read() const {
int64_t Count = 0;
ssize_t ReadSize = ::read(FileDescriptor, &Count, sizeof(Count));
- if (ReadSize != sizeof(Count))
+ if (ReadSize != sizeof(Count)) {
+ Count = -1;
llvm::errs() << "Failed to read event counter\n";
+ }
return Count;
}
More information about the llvm-commits
mailing list