[PATCH] D31345: [XRay] [compiler-rt] Unwriting FDR mode buffers when functions are short.

Keith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 24 12:45:42 PDT 2017


kpw added a comment.

D'oh. Just realized that I need to do cycle math to convert from TSC ticks to us.

I've also got a program that I'm trying to see output from, and there may be some issues for me to iron out. I'm not seeing any records after the fdr_header.
I may be doing the setup incorrectly. I'm going to recompile compiler-rt without my change to see the difference in output.

#include <stdlib.h>
#include <xray/xray_fdr_logging.h>
#include <xray/xray_interface.h>
#include <cassert>
#include <chrono>
#include <cstdio>
#include <thread>

constexpr auto kBufferSize = 16384;
constexpr auto kBufferMax = 10;

[[clang::xray_always_instrument]] void __attribute__((noinline)) fC() {

  std::printf("In fC()\n");

}

[[clang::xray_always_instrument]] void __attribute__((noinline)) fB() {

  std::printf("In fB()\n");
  fC();

}

[[clang::xray_always_instrument]] void __attribute__((noinline)) fA() {

  std::printf("In fA()\n");
  fB();

}

[[clang::xray_always_instrument]] void __attribute__((noinline)) fD() {

  std::printf("In fD()\n");
  std::this_thread::sleep_for(std::chrono::milliseconds(100));

}

// Avoid infinite recursion in case the logging function is instrumented (so
// calls logging
//   function again).
[[clang::xray_never_instrument]] void simplyPrint(int32_t functionId,

                                                  XRayEntryType xret) {
  printf("XRay: functionId=%d type=%d.\n", int(functionId), int(xret));

}

int main(int argc, char* argv[]) {

  using namespace __xray;
  FDRLoggingOptions Options;
  Options.ReportErrors = true;
  char TmpFilename[] = "fdr-logging-test.XXXXXX";
  Options.Fd = mkstemp(TmpFilename);
  fdrLoggingInit(kBufferSize, kBufferMax, &Options, sizeof(FDRLoggingOptions));
  __xray_set_handler(fdrLoggingHandleArg0);
  printf("Patching...\n");
  __xray_patch();
  fA();
  fC();
  fC();
  fD();
  printf("Unpatching...\n");
  __xray_unpatch();
  fdrLoggingFinalize();
  fdrLoggingFlush();
  return 0;

}


https://reviews.llvm.org/D31345





More information about the llvm-commits mailing list