1
0
mirror of https://github.com/Yours3lf/rpi-vk-driver.git synced 2025-02-19 16:54:18 +01:00

fixed profiler

This commit is contained in:
yours3lf 2020-05-18 23:22:56 +01:00
parent 86a7834753
commit ae1fbc2698
4 changed files with 37 additions and 24 deletions

View File

@ -37,7 +37,7 @@
#include "vkCaps.h"
#define PROFILESTART(x)// startMeasure((&\x), (#x))
#define PROFILESTART(x) startMeasure((x), (#x))
#define PROFILEEND(x) endMeasure((x))
/**

View File

@ -4,10 +4,6 @@ extern "C" {
#include "profiler.h"
/**
#define _POSIX_C_SOURCE 199309L
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
@ -28,6 +24,7 @@ void initProfiler()
globalProfiler = (profiler*)malloc(sizeof(profiler));
globalProfiler->funcDatabase = createMap(malloc(sizeof(mapElem) * MAX_FUNCTIONS), MAX_FUNCTIONS);
globalProfiler->frameCounter = 0;
globalProfilerGuard = 0;
}
@ -67,11 +64,8 @@ void startMeasure(void* func, const char* funcName)
}
}
/**/
void endMeasure(unsigned func)
void endMeasure(void* func)
{
/**
struct timespec end;
clock_gettime(CLOCK_REALTIME, &end);
@ -87,15 +81,31 @@ void endMeasure(unsigned func)
assert(data->inProgress);
data->inProgress = 0;
data->timeSpent = (end.tv_nsec - data->start.tv_nsec) / MILLION;
if((end.tv_nsec - data->start.tv_nsec) < 0)
{
data->timeSpent += (end.tv_sec - data->start.tv_sec - 1) * 0.001 + (1000000000 + end.tv_nsec - data->start.tv_nsec) / MILLION;
}
else
{
data->timeSpent += (end.tv_sec - data->start.tv_sec) * 0.001 + (end.tv_nsec - data->start.tv_nsec) / MILLION;
}
globalProfilerGuard = 0;
}
/**/
}
void endFrame()
{
while(globalProfilerGuard);
{
globalProfilerGuard = 1;
globalProfiler->frameCounter++;
globalProfilerGuard = 0;
}
}
/**
double getTimeSpent(void* func)
{
assert(globalProfiler);
@ -107,7 +117,7 @@ double getTimeSpent(void* func)
return 0;
}
return data->timeSpent;
return data->timeSpent / (double)globalProfiler->frameCounter;
}
void profilePrintResults()
@ -167,14 +177,13 @@ void profilePrintResults()
uint32_t counter = 0;
for(int32_t c = numFunctions - 1; c >= 0; --c)
{
fprintf(stderr, "#%u %-30s: %lf ms\n", ++counter, profileResults[c].funcName, profileResults[c].timeSpent);
fprintf(stderr, "#%u %-30s: %lf ms\n", ++counter, profileResults[c].funcName, profileResults[c].timeSpent / (double)globalProfiler->frameCounter);
if(counter >= 10)
{
//break;
}
}
}
/**/
#if defined (__cplusplus)
}

View File

@ -2,9 +2,12 @@
extern "C" {
#endif
/**
#define _POSIX_C_SOURCE 199309L
#include "map.h"
#include <time.h>
#define MILLION 1000000.0
#define MAX_FUNCTIONS 8192
@ -12,26 +15,24 @@ extern "C" {
typedef struct
{
map funcDatabase;
uint32_t frameCounter;
} profiler;
typedef struct
{
char* funcName; //stores function name
double timeSpent; //stores time spent in function in milliseconds
//struct timespec start; //for timekeeping
struct timespec start; //for timekeeping
uint32_t inProgress;
} funcData;
void initProfiler();
void startMeasure(void* func, const char* funcName);
/**/
void endMeasure(unsigned func);
/**
void endMeasure(void* func);
void endFrame();
double getTimeSpent(void* func);
void profilePrintResults();
/**/
#if defined (__cplusplus)
}
#endif

View File

@ -635,6 +635,9 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkQueuePresentKHR)(
}
PROFILEEND(RPIFUNC(vkQueuePresentKHR));
endFrame();
return VK_SUCCESS;
}
@ -669,7 +672,7 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkDestroySwapchainKHR)(
PROFILEEND(RPIFUNC(vkDestroySwapchainKHR));
//profilePrintResults();
profilePrintResults();
}
/*