|
57 | 57 | //
|
58 | 58 | //===----------------------------------------------------------------------===//
|
59 | 59 |
|
60 |
| -#ifndef STANDALONE |
61 | 60 | #include <Python.h>
|
62 |
| -#endif |
63 | 61 | #include <algorithm>
|
64 | 62 | #include <cassert>
|
65 | 63 | #include <cstring>
|
@@ -469,6 +467,8 @@ PerfReader::PerfReader(const std::string &Filename,
|
469 | 467 | std::string Nm, std::string Objdump,
|
470 | 468 | std::string BinaryCacheRoot)
|
471 | 469 | : Nm(Nm), Objdump(Objdump), BinaryCacheRoot(BinaryCacheRoot) {
|
| 470 | + TopLevelCounters = PyDict_New(); |
| 471 | + Functions = PyDict_New(); |
472 | 472 | int fd = open(Filename.c_str(), O_RDONLY);
|
473 | 473 | assert(fd > 0);
|
474 | 474 |
|
@@ -672,12 +672,9 @@ void PerfReader::emitLine(uint64_t PC,
|
672 | 672 | }
|
673 | 673 |
|
674 | 674 | void PerfReader::emitTopLevelCounters() {
|
675 |
| - TopLevelCounters = PyDict_New(); |
676 | 675 | for (auto &KV : TotalEvents)
|
677 | 676 | PyDict_SetItemString(TopLevelCounters, KV.first,
|
678 | 677 | PyLong_FromUnsignedLongLong((unsigned long long)KV.second));
|
679 |
| - |
680 |
| - Functions = PyDict_New(); |
681 | 678 | }
|
682 | 679 |
|
683 | 680 | void PerfReader::emitMaps() {
|
@@ -843,13 +840,17 @@ PyMODINIT_FUNC initcPerf(void) {
|
843 | 840 | #else // STANDALONE
|
844 | 841 |
|
845 | 842 | 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", ""); |
847 | 846 | P.readHeader();
|
848 | 847 | P.readAttrs();
|
849 | 848 | P.readDataStream();
|
850 | 849 | P.emitTopLevelCounters();
|
851 | 850 | P.emitMaps();
|
852 |
| - P.complete(); |
| 851 | + PyObject_Print(P.complete(), stdout, Py_PRINT_RAW); |
| 852 | + Py_FinalizeEx(); |
| 853 | + return 0; |
853 | 854 | }
|
854 | 855 |
|
855 | 856 | #endif
|
0 commit comments