Skip to content

Commit

Permalink
introduce the VM_STATS environment variable to collect/dump compiler …
Browse files Browse the repository at this point in the history
…stats
  • Loading branch information
Laurent Sansonetti committed May 14, 2011
1 parent acfe0a9 commit 5e28a91
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions HACKING.rdoc
Expand Up @@ -122,10 +122,13 @@ The following environment variables might help you debug easy bugs.
builtin interpreter (generally used on cold paths).

* VM_DUMP_IR: set it to any value to dump the LLVM IR on $stderr before the
interpreter quits.
program quits.

* VM_VERIFY_IR: set it to any value to force a LLVM module verification before
the interpreter quits.
the program quits.

* VM_STATS: set it to any value to collect then print compiler statistics
before the program quits.

* VM_OPT_LEVEL: set it either to 0, 1, 2 or 3 to change the optimization level
of the LLVM code generator.
Expand Down
12 changes: 12 additions & 0 deletions vm.cpp
Expand Up @@ -48,6 +48,7 @@
# include <llvm/Intrinsics.h>
# include <llvm/Bitcode/ReaderWriter.h>
# include <llvm/LLVMContext.h>
# include "llvm/ADT/Statistic.h"
using namespace llvm;
#endif // MACRUBY_STATIC

Expand Down Expand Up @@ -5188,6 +5189,8 @@ class_has_custom_resolver(Class klass)
# include ".objs/kernel_data.c"
#endif

static bool vm_enable_stats = false;

extern "C"
void
Init_PreVM(void)
Expand All @@ -5202,6 +5205,11 @@ Init_PreVM(void)
// To not corrupt stack pointer (essential for backtracing).
llvm::NoFramePointerElim = true;

if (getenv("VM_STATS") != NULL) {
vm_enable_stats = true;
llvm::EnableStatistics();
}

MemoryBuffer *mbuf = NULL;
const char *kernel_file = getenv("VM_KERNEL_PATH");
if (kernel_file != NULL) {
Expand Down Expand Up @@ -5560,6 +5568,10 @@ rb_vm_finalize(void)
rb_verify_module();
printf("IR verified!\n");
}

if (vm_enable_stats) {
llvm::PrintStatistics();
}
#endif

// XXX: deleting the core is not safe at this point because there might be
Expand Down

0 comments on commit 5e28a91

Please sign in to comment.