# TSCClock.cc

Go to the documentation of this file.

    00001 #include "TSCClock.hh"
    00002 #include <stdio.h>
    00003 #include <stdlib.h>
    00004 #include <string.h>
    00005
    00006 namespace certi {
    00007
    00008 TSCClock::TSCClock() : Clock("TSCClock")
    00009 {
    00010     resolution = 1.0e3/getProcessorFrequency();
    00011 }
    00012
    00013 double
    00014 TSCClock::getResolution() {
    00015     return resolution;
    00016 }
    00017
    00018 uint64_t
    00019 TSCClock::getCurrentTicksValue() {
    00020     return readTSC();
    00021 }
    00022
    00023 double
    00024 TSCClock::tick2NanoSecond(const uint64_t ticks) {
    00025     return resolution*ticks;
    00026 }
    00027
    00028 TSCClock::~TSCClock()
    00029 {
    00030 }
    00031
    00032 double TSCClock::getProcessorFrequency() {
    00033       FILE* fdcpu;
    00034       char left[256], right[256];
    00035       double freq = -1.0;
    00036
    00037       fdcpu = fopen("/proc/cpuinfo","r");
    00038
    00039       while (EOF != fscanf(fdcpu,"%s : %s \n",left,right) ) {
    00040
    00041         if (strstr(left,"MHz")) {
    00042           freq=atof(right);
    00043           break;
    00044         }
    00045       }
    00046       fclose(fdcpu);
    00047       return freq;
    00048 }
    00049
    00050 }