mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2024-11-28 08:14:15 +01:00
Add stopwatch to both threaded and unthreaded paths. Still need to actually write unix stopwatch implementation.
This commit is contained in:
parent
2ad2e94584
commit
720ad0ac6f
@ -7,8 +7,17 @@ SET( SOURCES
|
|||||||
SET( HEADERS
|
SET( HEADERS
|
||||||
"include/TexComp.h"
|
"include/TexComp.h"
|
||||||
"include/CompressedImage.h"
|
"include/CompressedImage.h"
|
||||||
|
"include/TexCompTypes.h"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Make sure to add the appropriate stopwatch files...
|
||||||
|
SET( HEADERS ${HEADERS} "src/StopWatch.h" )
|
||||||
|
IF( MSVC )
|
||||||
|
SET( SOURCES ${SOURCES} "src/StopWatchWin32.cpp" )
|
||||||
|
ELSE()
|
||||||
|
SET( SOURCES ${SOURCES} "src/StopWatchUnix.cpp" )
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
INCLUDE_DIRECTORIES( ${TexC_SOURCE_DIR}/BPTCEncoder/include )
|
INCLUDE_DIRECTORIES( ${TexC_SOURCE_DIR}/BPTCEncoder/include )
|
||||||
INCLUDE_DIRECTORIES( ${TexC_BINARY_DIR}/BPTCEncoder/include )
|
INCLUDE_DIRECTORIES( ${TexC_BINARY_DIR}/BPTCEncoder/include )
|
||||||
|
|
||||||
|
29
Core/src/StopWatchUnix.cpp
Normal file
29
Core/src/StopWatchUnix.cpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include "StopWatch.h"
|
||||||
|
|
||||||
|
StopWatch::StopWatch() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void StopWatch::Start() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void StopWatch::Stop() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void StopWatch::Reset() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
double StopWatch::TimeInSeconds() const {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
double StopWatch::TimeInMilliseconds() const {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
double StopWatch::TimeInMicroseconds() const {
|
||||||
|
|
||||||
|
}
|
@ -56,15 +56,27 @@ CompressedImage * CompressImage(
|
|||||||
|
|
||||||
CompressionFunc f = ChooseFuncFromSettings(settings);
|
CompressionFunc f = ChooseFuncFromSettings(settings);
|
||||||
if(f) {
|
if(f) {
|
||||||
|
|
||||||
|
StopWatch stopWatch = StopWatch();
|
||||||
|
|
||||||
if(settings.iNumThreads > 1) {
|
if(settings.iNumThreads > 1) {
|
||||||
|
|
||||||
ThreadGroup tgrp (settings.iNumThreads, img, f, cmpData);
|
ThreadGroup tgrp (settings.iNumThreads, img, f, cmpData);
|
||||||
|
|
||||||
tgrp.Start();
|
tgrp.Start();
|
||||||
tgrp.Join();
|
tgrp.Join();
|
||||||
|
|
||||||
|
stopWatch = tgrp.GetStopWatch();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
stopWatch.Start();
|
||||||
(*f)(img.GetPixels(), cmpData, img.GetWidth(), img.GetHeight());
|
(*f)(img.GetPixels(), cmpData, img.GetWidth(), img.GetHeight());
|
||||||
|
stopWatch.Stop();
|
||||||
outImg = new CompressedImage(img.GetWidth(), img.GetHeight(), settings.format, cmpData);
|
outImg = new CompressedImage(img.GetWidth(), img.GetHeight(), settings.format, cmpData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Report compression time
|
||||||
|
fprintf(stdout, "Compression time: %0.3f ms\n", stopWatch.TimeInMilliseconds());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ReportError("Could not find adequate compression function for specified settings");
|
ReportError("Could not find adequate compression function for specified settings");
|
||||||
|
@ -34,6 +34,11 @@ ThreadGroup::~ThreadGroup() {
|
|||||||
|
|
||||||
void ThreadGroup::Start() {
|
void ThreadGroup::Start() {
|
||||||
|
|
||||||
|
// Have we already activated the thread group?
|
||||||
|
if(m_ActiveThreads > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for(int i = 0; i < m_NumThreads; i++) {
|
for(int i = 0; i < m_NumThreads; i++) {
|
||||||
|
|
||||||
if(m_ActiveThreads >= kMaxNumThreads)
|
if(m_ActiveThreads >= kMaxNumThreads)
|
||||||
@ -45,6 +50,8 @@ void ThreadGroup::Start() {
|
|||||||
m_ActiveThreads++;
|
m_ActiveThreads++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_StopWatch.Reset();
|
||||||
|
m_StopWatch.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadGroup::Join() {
|
void ThreadGroup::Join() {
|
||||||
@ -54,5 +61,11 @@ void ThreadGroup::Join() {
|
|||||||
delete m_ThreadHandles[i];
|
delete m_ThreadHandles[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// !FIXME! This will also take the thread deletion into account. We
|
||||||
|
// should really be using better synchronization to actually only
|
||||||
|
// measure how long it takes for all threads to finish execution.
|
||||||
|
m_StopWatch.Stop();
|
||||||
|
|
||||||
|
// Reset active number of threads...
|
||||||
m_ActiveThreads = 0;
|
m_ActiveThreads = 0;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define _THREAD_GROUP_H_
|
#define _THREAD_GROUP_H_
|
||||||
|
|
||||||
#include "TexComp.h"
|
#include "TexComp.h"
|
||||||
|
#include "StopWatch.h"
|
||||||
|
|
||||||
// forward declare
|
// forward declare
|
||||||
namespace boost {
|
namespace boost {
|
||||||
@ -38,6 +39,8 @@ class ThreadGroup {
|
|||||||
void Start();
|
void Start();
|
||||||
void Join();
|
void Join();
|
||||||
|
|
||||||
|
const StopWatch &GetStopWatch() const { return m_StopWatch; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
boost::barrier *m_Barrier;
|
boost::barrier *m_Barrier;
|
||||||
|
|
||||||
@ -48,6 +51,8 @@ class ThreadGroup {
|
|||||||
|
|
||||||
CmpThread m_Threads[kMaxNumThreads];
|
CmpThread m_Threads[kMaxNumThreads];
|
||||||
boost::thread *m_ThreadHandles[kMaxNumThreads];
|
boost::thread *m_ThreadHandles[kMaxNumThreads];
|
||||||
|
|
||||||
|
StopWatch m_StopWatch;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _THREAD_GROUP_H_
|
#endif // _THREAD_GROUP_H_
|
||||||
|
Loading…
Reference in New Issue
Block a user