diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt index 99e2d63..ef1fd1a 100644 --- a/Core/CMakeLists.txt +++ b/Core/CMakeLists.txt @@ -7,8 +7,17 @@ SET( SOURCES SET( HEADERS "include/TexComp.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_BINARY_DIR}/BPTCEncoder/include ) diff --git a/Core/src/StopWatchUnix.cpp b/Core/src/StopWatchUnix.cpp new file mode 100644 index 0000000..ad1800f --- /dev/null +++ b/Core/src/StopWatchUnix.cpp @@ -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 { + +} diff --git a/Core/src/StopWatch.cpp b/Core/src/StopWatchWin32.cpp similarity index 100% rename from Core/src/StopWatch.cpp rename to Core/src/StopWatchWin32.cpp diff --git a/Core/src/TexComp.cpp b/Core/src/TexComp.cpp index b0d8c09..a395957 100644 --- a/Core/src/TexComp.cpp +++ b/Core/src/TexComp.cpp @@ -56,15 +56,27 @@ CompressedImage * CompressImage( CompressionFunc f = ChooseFuncFromSettings(settings); if(f) { + + StopWatch stopWatch = StopWatch(); + if(settings.iNumThreads > 1) { + ThreadGroup tgrp (settings.iNumThreads, img, f, cmpData); + tgrp.Start(); tgrp.Join(); + + stopWatch = tgrp.GetStopWatch(); } else { + stopWatch.Start(); (*f)(img.GetPixels(), cmpData, img.GetWidth(), img.GetHeight()); + stopWatch.Stop(); outImg = new CompressedImage(img.GetWidth(), img.GetHeight(), settings.format, cmpData); } + + // Report compression time + fprintf(stdout, "Compression time: %0.3f ms\n", stopWatch.TimeInMilliseconds()); } else { ReportError("Could not find adequate compression function for specified settings"); diff --git a/Core/src/ThreadGroup.cpp b/Core/src/ThreadGroup.cpp index af43cbf..b44c80c 100644 --- a/Core/src/ThreadGroup.cpp +++ b/Core/src/ThreadGroup.cpp @@ -34,6 +34,11 @@ ThreadGroup::~ThreadGroup() { void ThreadGroup::Start() { + // Have we already activated the thread group? + if(m_ActiveThreads > 0) { + return; + } + for(int i = 0; i < m_NumThreads; i++) { if(m_ActiveThreads >= kMaxNumThreads) @@ -45,6 +50,8 @@ void ThreadGroup::Start() { m_ActiveThreads++; } + m_StopWatch.Reset(); + m_StopWatch.Start(); } void ThreadGroup::Join() { @@ -54,5 +61,11 @@ void ThreadGroup::Join() { 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; } diff --git a/Core/src/ThreadGroup.h b/Core/src/ThreadGroup.h index 8a08d05..a0605bc 100644 --- a/Core/src/ThreadGroup.h +++ b/Core/src/ThreadGroup.h @@ -2,6 +2,7 @@ #define _THREAD_GROUP_H_ #include "TexComp.h" +#include "StopWatch.h" // forward declare namespace boost { @@ -38,6 +39,8 @@ class ThreadGroup { void Start(); void Join(); + const StopWatch &GetStopWatch() const { return m_StopWatch; } + private: boost::barrier *m_Barrier; @@ -48,6 +51,8 @@ class ThreadGroup { CmpThread m_Threads[kMaxNumThreads]; boost::thread *m_ThreadHandles[kMaxNumThreads]; + + StopWatch m_StopWatch; }; #endif // _THREAD_GROUP_H_