summaryrefslogtreecommitdiffstats
path: root/Whisper/Utils/Trace/tracing.cpp
diff options
context:
space:
mode:
authorKonstantin <const@const.me>2023-01-16 14:52:43 +0100
committerKonstantin <const@const.me>2023-01-16 14:52:43 +0100
commit8c4603c73675958efc960fbd4bb599a2909d106a (patch)
tree714dc6fc9a1672d5fd7f89676b97e10959662abc /Whisper/Utils/Trace/tracing.cpp
parent990a8d0dbaefc996244097397259e92758b15cce (diff)
Source codes
Diffstat (limited to 'Whisper/Utils/Trace/tracing.cpp')
-rw-r--r--Whisper/Utils/Trace/tracing.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/Whisper/Utils/Trace/tracing.cpp b/Whisper/Utils/Trace/tracing.cpp
new file mode 100644
index 0000000..976f517
--- /dev/null
+++ b/Whisper/Utils/Trace/tracing.cpp
@@ -0,0 +1,60 @@
+#include "stdafx.h"
+#include "tracing.h"
+#include "../../source/ggml.h"
+
+#if SAVE_DEBUG_TRACE
+namespace Tracing
+{
+ std::unique_ptr<iTraceWriter> s_writer;
+
+ static BOOL __stdcall consoleHandler( DWORD dwCtrlType )
+ {
+ if( dwCtrlType == CTRL_C_EVENT )
+ s_writer = nullptr;
+
+ // Return TRUE if handled this message, further handler functions won't be called.
+ // Return FALSE to pass this message to further handlers until default handler calls ExitProcess().
+ return FALSE;
+ }
+
+ void traceCreate( LPCTSTR path )
+ {
+ s_writer = iTraceWriter::create( path );
+ SetConsoleCtrlHandler( &consoleHandler, TRUE );
+ }
+
+ void traceClose()
+ {
+ s_writer = nullptr;
+ }
+
+ iTraceWriter* getWriter()
+ {
+ return s_writer.get();
+ }
+
+ using Pair = std::pair<ItemName, ggml_tensor>;
+ static std::vector<Pair> delayed;
+
+ void delayTensor( const ItemName& name, const ggml_tensor* tensor )
+ {
+ delayed.emplace_back( name, *tensor );
+ }
+
+ HRESULT writeDelayedTensors()
+ {
+ if( delayed.empty() )
+ return S_FALSE;
+ iTraceWriter* w = getWriter();
+ if( nullptr == w )
+ {
+ delayed.clear();
+ return S_FALSE;
+ }
+ for( const Pair& p : delayed )
+ w->tensor( p.first, p.second );
+ delayed.clear();
+ return S_OK;
+ }
+}
+#endif \ No newline at end of file