@@ -259,16 +259,18 @@ struct Symbol {
259
259
260
260
class NmOutput : public std ::vector<Symbol> {
261
261
public:
262
- std::string Nm;
262
+ std::string Nm, BinaryCacheRoot ;
263
263
264
- NmOutput (std::string Nm) : Nm(Nm) {}
264
+ NmOutput (std::string Nm, std::string BinaryCacheRoot)
265
+ : Nm(Nm), BinaryCacheRoot(BinaryCacheRoot) {}
265
266
266
267
void fetchSymbols (Map *M, bool Dynamic) {
267
268
std::string D = " -D" ;
268
269
if (!Dynamic)
269
270
// Don't fetch the dynamic symbols - instead fetch static ones.
270
271
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 ) +
272
274
" 2>/dev/null" ;
273
275
auto Stream = ForkAndExec (Cmd);
274
276
@@ -343,16 +345,17 @@ class NmOutput : public std::vector<Symbol> {
343
345
344
346
class ObjdumpOutput {
345
347
public:
346
- std::string Objdump;
348
+ std::string Objdump, BinaryCacheRoot ;
347
349
FILE *Stream;
348
350
char *ThisText;
349
351
uint64_t ThisAddress;
350
352
uint64_t EndAddress;
351
353
char *Line;
352
354
size_t LineLen;
353
355
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 ) {}
356
359
~ObjdumpOutput () {
357
360
if (Stream) {
358
361
fclose (Stream);
@@ -375,7 +378,8 @@ class ObjdumpOutput {
375
378
376
379
std::string Cmd = Objdump + " -d --no-show-raw-insn --start-address=" +
377
380
std::string (buf1) + " --stop-address=" +
378
- std::string (buf2) + " " + std::string (M->Filename ) +
381
+ std::string (buf2) + " " +
382
+ BinaryCacheRoot + std::string (M->Filename ) +
379
383
" 2>/dev/null" ;
380
384
Stream = ForkAndExec (Cmd);
381
385
@@ -420,7 +424,7 @@ class ObjdumpOutput {
420
424
class PerfReader {
421
425
public:
422
426
PerfReader (const std::string &Filename, std::string Nm,
423
- std::string Objdump);
427
+ std::string Objdump, std::string BinaryCacheRoot );
424
428
~PerfReader ();
425
429
426
430
void readHeader ();
@@ -458,12 +462,13 @@ class PerfReader {
458
462
PyObject *Functions, *TopLevelCounters;
459
463
std::vector<PyObject*> Lines;
460
464
461
- std::string Nm, Objdump;
465
+ std::string Nm, Objdump, BinaryCacheRoot ;
462
466
};
463
467
464
468
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) {
467
472
int fd = open (Filename.c_str (), O_RDONLY);
468
473
assert (fd > 0 );
469
474
@@ -707,7 +712,7 @@ void PerfReader::emitMaps() {
707
712
bool IsSO = IsSharedObject (Maps[MapID].Filename );
708
713
uint64_t Adjust = IsSO ? Maps[MapID].Start : 0 ;
709
714
710
- NmOutput Syms (Nm);
715
+ NmOutput Syms (Nm, BinaryCacheRoot );
711
716
Syms.reset (&Maps[MapID]);
712
717
713
718
// Accumulate the event totals for each symbol
@@ -753,7 +758,7 @@ void PerfReader::emitSymbol(
753
758
std::map<uint64_t , std::map<const char *, uint64_t >>::iterator Event,
754
759
std::map<const char *, uint64_t > &SymEvents,
755
760
uint64_t Adjust) {
756
- ObjdumpOutput Dump (Objdump);
761
+ ObjdumpOutput Dump (Objdump, BinaryCacheRoot );
757
762
Dump.reset (&M, Sym.Start , Sym.End );
758
763
Dump.next ();
759
764
@@ -784,11 +789,12 @@ static PyObject *cPerf_importPerf(PyObject *self, PyObject *args) {
784
789
const char *Fname;
785
790
const char *Nm = " nm" ;
786
791
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))
788
794
return NULL ;
789
795
790
796
try {
791
- PerfReader P (Fname, Nm, Objdump);
797
+ PerfReader P (Fname, Nm, Objdump, BinaryCacheRoot );
792
798
P.readHeader ();
793
799
P.readAttrs ();
794
800
P.readDataStream ();
0 commit comments