Skip to content

Commit a00494c

Browse files
author
Pavel Kosov
committed
[LNT] Fixed the standalone mode of cPerf for the debug purpose
It also initializes dict objects in the constructor to make the object PerfReader consistent. Reviewed By: thopre Differential Revision: https://reviews.llvm.org/D112203 OS Laboratory, Huawei Russian Research Institute, Saint-Petersburg
1 parent 8bd6625 commit a00494c

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lnt/testing/profile/cPerf.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@
5757
//
5858
//===----------------------------------------------------------------------===//
5959

60-
#ifndef STANDALONE
6160
#include <Python.h>
62-
#endif
6361
#include <algorithm>
6462
#include <cassert>
6563
#include <cstring>
@@ -469,6 +467,8 @@ PerfReader::PerfReader(const std::string &Filename,
469467
std::string Nm, std::string Objdump,
470468
std::string BinaryCacheRoot)
471469
: Nm(Nm), Objdump(Objdump), BinaryCacheRoot(BinaryCacheRoot) {
470+
TopLevelCounters = PyDict_New();
471+
Functions = PyDict_New();
472472
int fd = open(Filename.c_str(), O_RDONLY);
473473
assert(fd > 0);
474474

@@ -672,12 +672,9 @@ void PerfReader::emitLine(uint64_t PC,
672672
}
673673

674674
void PerfReader::emitTopLevelCounters() {
675-
TopLevelCounters = PyDict_New();
676675
for (auto &KV : TotalEvents)
677676
PyDict_SetItemString(TopLevelCounters, KV.first,
678677
PyLong_FromUnsignedLongLong((unsigned long long)KV.second));
679-
680-
Functions = PyDict_New();
681678
}
682679

683680
void PerfReader::emitMaps() {
@@ -843,13 +840,17 @@ PyMODINIT_FUNC initcPerf(void) {
843840
#else // STANDALONE
844841

845842
int main(int argc, char **argv) {
846-
PerfReader P(argv[1], std::cout);
843+
Py_Initialize();
844+
if (argc < 2) return -1;
845+
PerfReader P(argv[1], "nm", "objdump", "");
847846
P.readHeader();
848847
P.readAttrs();
849848
P.readDataStream();
850849
P.emitTopLevelCounters();
851850
P.emitMaps();
852-
P.complete();
851+
PyObject_Print(P.complete(), stdout, Py_PRINT_RAW);
852+
Py_FinalizeEx();
853+
return 0;
853854
}
854855

855856
#endif

0 commit comments

Comments
 (0)