 #include <stdint.h>
 #include <stdio.h>
 #include <unistd.h>
+#include <dlfcn.h>
 #include "sassi_intrinsics.h"
 #include "sassi_lazyallocator.hpp"
 #include <sassi/sassi-core.hpp>

// this array to be __managed__ so that UVM would take care of copying data
// back and forth.  In this example, we will just declare this array to reside
// on the device, and we will explicitly copy the data back and forth.
__device__ unsigned long long dynamic_instr_counts[SASSI_NUM_OPCODES];

///////////////////////////////////////////////////////////////////////////////////
///

///  Write out the statistics we've gathered.
/// 
///////////////////////////////////////////////////////////////////////////////////
void sassi_finalize(sassi::lazy_allocator::device_reset_reason reason)
{
  FILE *resultFile = fopen("sassi-ophist.txt", "w");
  for (unsigned i = 0; i < SASSI_NUM_OPCODES; i++) {
    if (dynamic_instr_counts[i] > 0) {
      fprintf(resultFile, "%-10.10s: %llu\n", SASSIInstrOpcodeStrings[i], dynamic_instr_counts[i]);
    }
  }
  fclose(resultFile);
