Skip to content

Commit d08e890

Browse files
author
Pavel Kosov
committed
[LNT] NFC. Improvements to cPerf
This patch contains few improvements to cPerf: - Fixed the warning about llx printf format on LP64 systems - Used environment variables in the standalone version for a debug purpose - Added the comment with the command line to build the standalone version OS Laboratory. Huawei Russian Research Institute. Saint-Petersburg Reviewed By: thopre Differential Revision: https://reviews.llvm.org/D117007
1 parent 016a4a7 commit d08e890

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

lnt/testing/profile/cPerf.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ class ObjdumpOutput {
500500
public:
501501
std::string Objdump, BinaryCacheRoot;
502502
FILE *Stream;
503-
char *ThisText;
503+
const char *ThisText;
504504
uint64_t ThisAddress;
505505
uint64_t EndAddress;
506506
char *Line;
@@ -535,8 +535,8 @@ class ObjdumpOutput {
535535
}
536536

537537
char buf1[32], buf2[32];
538-
sprintf(buf1, "%#llx", Start);
539-
sprintf(buf2, "%#llx", Stop + 4);
538+
sprintf(buf1, "%#" PRIx64, Start);
539+
sprintf(buf2, "%#" PRIx64, Stop + 4);
540540

541541
std::string Cmd = Objdump + " -d --no-show-raw-insn --start-address=" +
542542
std::string(buf1) + " --stop-address=" +
@@ -1083,16 +1083,33 @@ PyMODINIT_FUNC initcPerf(void) {
10831083

10841084
#else // STANDALONE
10851085

1086+
// You can build the standalone version for a debug purpose using
1087+
// clang++ cPerf.cpp -o /tmp/cPerf -DSTANDALONE $(pkg-config --cflags --libs python3-embed)
1088+
1089+
// getenv() is permitted to overwrite its return value on subsequent calls,
1090+
// so copy it to std::string early.
1091+
static std::string getEnvVar(const char *VarName, const char *DefaultValue) {
1092+
const char *Value = getenv(VarName);
1093+
if (!Value)
1094+
Value = DefaultValue;
1095+
return Value;
1096+
}
1097+
10861098
int main(int argc, char **argv) {
10871099
Py_Initialize();
10881100
if (argc < 2) return -1;
1089-
PerfReader P(argv[1], "objdump", "");
1101+
1102+
std::string BinaryCacheRoot = getEnvVar("LNT_BINARY_CACHE_ROOT", "");
1103+
std::string Objdump = getEnvVar("CMAKE_OBJDUMP", "objdump");
1104+
1105+
PerfReader P(argv[1], Objdump, BinaryCacheRoot);
10901106
P.readHeader();
10911107
P.readAttrs();
10921108
P.readDataStream();
10931109
P.emitTopLevelCounters();
10941110
P.emitMaps();
10951111
PyObject_Print(P.complete(), stdout, Py_PRINT_RAW);
1112+
fputs("\n", stdout); // Usually expected by UNIX shells
10961113
Py_FinalizeEx();
10971114
return 0;
10981115
}

0 commit comments

Comments
 (0)