Skip to content

Commit 9290733

Browse files
author
Pavel Kosov
committed
[LNT] Added reading nm and objdump paths from env variables
- Added reading nm and objdump paths from env variables - Added binaryCacheRoot Reviewed By: thopre Differential Revision: https://reviews.llvm.org/D110839 OS Laboratory. Huawei Russian Research Institute. Saint-Petersburg
1 parent efe3935 commit 9290733

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

lnt/testing/profile/cPerf.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,18 @@ struct Symbol {
259259

260260
class NmOutput : public std::vector<Symbol> {
261261
public:
262-
std::string Nm;
262+
std::string Nm, BinaryCacheRoot;
263263

264-
NmOutput(std::string Nm) : Nm(Nm) {}
264+
NmOutput(std::string Nm, std::string BinaryCacheRoot)
265+
: Nm(Nm), BinaryCacheRoot(BinaryCacheRoot) {}
265266

266267
void fetchSymbols(Map *M, bool Dynamic) {
267268
std::string D = "-D";
268269
if (!Dynamic)
269270
// Don't fetch the dynamic symbols - instead fetch static ones.
270271
D = "";
271-
std::string Cmd = Nm + " " + D + " -S --defined-only " + std::string(M->Filename) +
272+
std::string Cmd = Nm + " " + D + " -S --defined-only " +
273+
BinaryCacheRoot + std::string(M->Filename) +
272274
" 2>/dev/null";
273275
auto Stream = ForkAndExec(Cmd);
274276

@@ -343,16 +345,17 @@ class NmOutput : public std::vector<Symbol> {
343345

344346
class ObjdumpOutput {
345347
public:
346-
std::string Objdump;
348+
std::string Objdump, BinaryCacheRoot;
347349
FILE *Stream;
348350
char *ThisText;
349351
uint64_t ThisAddress;
350352
uint64_t EndAddress;
351353
char *Line;
352354
size_t LineLen;
353355

354-
ObjdumpOutput(std::string Objdump)
355-
: Objdump(Objdump), Stream(nullptr), Line(NULL), LineLen(0) {}
356+
ObjdumpOutput(std::string Objdump, std::string BinaryCacheRoot)
357+
: Objdump(Objdump), BinaryCacheRoot(BinaryCacheRoot), Stream(nullptr),
358+
Line(NULL), LineLen(0) {}
356359
~ObjdumpOutput() {
357360
if (Stream) {
358361
fclose(Stream);
@@ -375,7 +378,8 @@ class ObjdumpOutput {
375378

376379
std::string Cmd = Objdump + " -d --no-show-raw-insn --start-address=" +
377380
std::string(buf1) + " --stop-address=" +
378-
std::string(buf2) + " " + std::string(M->Filename) +
381+
std::string(buf2) + " " +
382+
BinaryCacheRoot + std::string(M->Filename) +
379383
" 2>/dev/null";
380384
Stream = ForkAndExec(Cmd);
381385

@@ -420,7 +424,7 @@ class ObjdumpOutput {
420424
class PerfReader {
421425
public:
422426
PerfReader(const std::string &Filename, std::string Nm,
423-
std::string Objdump);
427+
std::string Objdump, std::string BinaryCacheRoot);
424428
~PerfReader();
425429

426430
void readHeader();
@@ -458,12 +462,13 @@ class PerfReader {
458462
PyObject *Functions, *TopLevelCounters;
459463
std::vector<PyObject*> Lines;
460464

461-
std::string Nm, Objdump;
465+
std::string Nm, Objdump, BinaryCacheRoot;
462466
};
463467

464468
PerfReader::PerfReader(const std::string &Filename,
465-
std::string Nm, std::string Objdump)
466-
: Nm(Nm), Objdump(Objdump) {
469+
std::string Nm, std::string Objdump,
470+
std::string BinaryCacheRoot)
471+
: Nm(Nm), Objdump(Objdump), BinaryCacheRoot(BinaryCacheRoot) {
467472
int fd = open(Filename.c_str(), O_RDONLY);
468473
assert(fd > 0);
469474

@@ -707,7 +712,7 @@ void PerfReader::emitMaps() {
707712
bool IsSO = IsSharedObject(Maps[MapID].Filename);
708713
uint64_t Adjust = IsSO ? Maps[MapID].Start : 0;
709714

710-
NmOutput Syms(Nm);
715+
NmOutput Syms(Nm, BinaryCacheRoot);
711716
Syms.reset(&Maps[MapID]);
712717

713718
// Accumulate the event totals for each symbol
@@ -753,7 +758,7 @@ void PerfReader::emitSymbol(
753758
std::map<uint64_t, std::map<const char *, uint64_t>>::iterator Event,
754759
std::map<const char *, uint64_t> &SymEvents,
755760
uint64_t Adjust) {
756-
ObjdumpOutput Dump(Objdump);
761+
ObjdumpOutput Dump(Objdump, BinaryCacheRoot);
757762
Dump.reset(&M, Sym.Start, Sym.End);
758763
Dump.next();
759764

@@ -784,11 +789,12 @@ static PyObject *cPerf_importPerf(PyObject *self, PyObject *args) {
784789
const char *Fname;
785790
const char *Nm = "nm";
786791
const char *Objdump = "objdump";
787-
if (!PyArg_ParseTuple(args, "s|ss", &Fname, &Nm, &Objdump))
792+
const char *BinaryCacheRoot = "";
793+
if (!PyArg_ParseTuple(args, "s|sss", &Fname, &Nm, &Objdump, &BinaryCacheRoot))
788794
return NULL;
789795

790796
try {
791-
PerfReader P(Fname, Nm, Objdump);
797+
PerfReader P(Fname, Nm, Objdump, BinaryCacheRoot);
792798
P.readHeader();
793799
P.readAttrs();
794800
P.readDataStream();

lnt/testing/profile/perf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def checkFile(fn):
2222
return f.read(8) == b'PERFILE2'
2323

2424
@staticmethod
25-
def deserialize(f, nm='nm', objdump='objdump', propagateExceptions=False):
25+
def deserialize(f, nm='nm', objdump='objdump', propagateExceptions=False,
26+
binaryCacheRoot=''):
2627
f = f.name
2728

2829
if os.path.getsize(f) == 0:

lnt/testing/profile/profile.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ def fromFile(f):
2727
"""
2828
for impl in lnt.testing.profile.IMPLEMENTATIONS.values():
2929
if impl.checkFile(f):
30-
ret = impl.deserialize(open(f, 'rb'))
30+
ret = None
31+
with open(f, 'rb') as fd:
32+
if impl is lnt.testing.profile.perf.LinuxPerfProfile:
33+
ret = impl.deserialize(fd,
34+
nm = os.getenv('CMAKE_NM', 'nm'),
35+
objdump = os.getenv('CMAKE_OBJDUMP', 'objdump'),
36+
binaryCacheRoot = os.getenv('LNT_BINARY_CACHE_ROOT', ''))
37+
else:
38+
ret = impl.deserialize(fd)
3139
if ret:
3240
return Profile(ret)
3341
else:

0 commit comments

Comments
 (0)