refactored test

This commit is contained in:
Hane 2024-01-17 20:07:53 +01:00
commit 6136207436
4 changed files with 69 additions and 20 deletions

View file

@ -1 +1 @@
clang++ -dynamic src\test\test.cpp -o build\test.exe -Wall -Wextra -Wpedantic -std=c++11 -L C:\capybara\libclang\x86_64-w64-mingw32\bin -L D:\Contenido\Capybara\Cositas\tmr\build -Wl,-Bstatic -l c++ -l unwind -Wl,-Bdynamic -l tmrtsc --verbose clang++ -dynamic src\test\test.cpp -o build\test.exe -Wall -Wextra -Wpedantic -std=c++11 -L C:\capybara\libclang\x86_64-w64-mingw32\bin -L D:\Contenido\Capybara\Cositas\tmr\build -Wl,-Bstatic -l c++ -l unwind -Wl,-Bdynamic -l tmrtsc --verbose

View file

@ -5,7 +5,8 @@
#define _MT #define _MT
#define _DLL #define _DLL
#include <Windows.h> #include <Windows.h>
#include <libloaderapi.h> #include <fileapi.h>
//#include <libloaderapi.h>
#endif #endif
#include "../debug.h" #include "../debug.h"
@ -14,11 +15,31 @@
using namespace tmr; using namespace tmr;
#ifdef _WIN64 #ifdef _WIN64
static inline int64_t getQPCTicks() {
LARGE_INTEGER ticks;
if (!QueryPerformanceCounter(&ticks))
{
return 0;
}
return ticks.QuadPart;
}
static inline int64_t getQPCFrequency() {
LARGE_INTEGER ticks;
if (!QueryPerformanceFrequency(&ticks))
{
return 0;
}
return ticks.QuadPart;
}
int main(int argc, char** argv){ int main(int argc, char** argv){
HMODULE dell; //HMODULE dell;
DWORD fracaso; //DWORD fracaso;
//DllImport TSCTimer* timer; //DllImport TSCTimer* timer;
int sleep = 1000; uint64_t sleep = 1;
uint64_t checks = 0;
/* /*
* dell = LoadLibraryExW(TEXT("libtmrtsc.dll"), NULL, NULL); * dell = LoadLibraryExW(TEXT("libtmrtsc.dll"), NULL, NULL);
@ -31,13 +52,42 @@ int main(int argc, char** argv){
timer = TSCTimer::getTimer(); timer = TSCTimer::getTimer();
if(timer == nullptr) if(timer == nullptr)
return -2; return -2;
uint64_t t1 = timer->getTimeStamp(); uint64_t wfr = getQPCFrequency();
Sleep(sleep); int64_t fr = timer->getBaseFrequency();
uint64_t t2 = timer->getTimeStamp();
uint64_t fr = timer->getBaseFrequency();
std::cout << "Siestecita de: " << sleep << " ms" << std::endl; uint64_t wt1 = getQPCTicks();
std::cout << "Windows Momento: \nt1: " << t1 << " t2: " << t2 << " fr: " << fr << std::endl; int64_t t1 = timer->getTimeStamp();
std::cout << "restita: " << t2-t1 << std::endl; int64_t t2 = timer->getTimeStamp();
while ((t2 - t1) < (sleep * fr)) {
t2 = timer->getTimeStamp();
checks++;
}
//uint64_t fr = timer->getBaseFrequency();
uint64_t wt2 = getQPCTicks();
std::cout << "Sleep: " << sleep << "s\n-----------------\nTest 1: TSCTimer within QPC\n" << std::endl;
std::cout << " QPC Momento: \nt1: " << wt1 << " t2: " << wt2 << " fr: " << wfr << std::endl;
std::cout << " restita: " << wt2-wt1 << std::endl;
std::cout << " TSCTimer Momento: \nt1: " << t1 << " t2: " << t2 << " fr: " << fr << std::endl;
std::cout << " restita: " << t2-t1 << std::endl;
std::cout << " checks: " << checks << "\n-----------------\nTest 2: QPC within TSCTimer\n"<< std::endl;
checks = 0;
t1 = timer->getTimeStamp();
wt1 = getQPCTicks();
wt2 = getQPCTicks();
while ((wt2 - wt1) < (sleep * wfr)) {
wt2 = getQPCTicks();
checks++;
}
//uint64_t fr = timer->getBaseFrequency();
t2 = timer->getTimeStamp();
std::cout << "QPC Momento: \n t1: " << wt1 << " t2: " << wt2 << " fr: " << wfr << std::endl;
std::cout << "restita: " << wt2-wt1 << std::endl;
std::cout << "TSCTimer Momento: \n t1: " << t1 << " t2: " << t2 << " fr: " << fr << std::endl;
std::cout << " restita: " << t2-t1 << std::endl;
std::cout << " checks: " << checks << std::endl;
return 0; return 0;
} }

View file

@ -47,7 +47,6 @@ namespace tmr {
int64_t TSCTimer::intelRetrieveART(){ int64_t TSCTimer::intelRetrieveART(){
//TODO: Find a valid Intel CPU to debug ART route //TODO: Find a valid Intel CPU to debug ART route
//if (freq == nullptr) return -
uint64_t raxde, rbxnum, rcxhz; uint64_t raxde, rbxnum, rcxhz;
asm volatile ( ".intel_syntax noprefix\t\n" \ asm volatile ( ".intel_syntax noprefix\t\n" \

View file

@ -32,18 +32,18 @@ namespace tmr {
#ifdef _WIN64 #ifdef _WIN64
enum winReturnValues{ enum winReturnValues{
CANT_OPEN_KEY = -1, CANT_OPEN_KEY = -1,
CANT_RETRIEVE_KEY_INFO = -2, CANT_RETRIEVE_KEY_INFO = -2,
CANT_READ_DATA_FROM_VALUE = -3, CANT_READ_DATA_FROM_VALUE = -3,
CANT_RETRIEVE_FREQUENCY = -4 CANT_RETRIEVE_FREQUENCY = -4
}; };
#endif #endif
enum ReturnValues { enum ReturnValues {
OPERATION_SUCCESSFUL = 0, OPERATION_SUCCESSFUL = 0,
INVARIANT_TSC_NOT_SUPPORTED = -1, INVARIANT_TSC_NOT_SUPPORTED = -1,
UNSUPPORTED_CPU = -2, UNSUPPORTED_CPU = -2,
CANT_READ_FREQUENCY_FROM_SYSTEM = -3, CANT_READ_FREQUENCY_FROM_SYSTEM = -3,
ART_NOT_REPORTED = -4 ART_NOT_REPORTED = -4
}; };
class LIB_EXPORT TSCTimer { class LIB_EXPORT TSCTimer {