swr: [rasterizer archrast] don't generate empty files
authorTim Rowley <timothy.o.rowley@intel.com>
Mon, 31 Oct 2016 00:27:07 +0000 (19:27 -0500)
committerTim Rowley <timothy.o.rowley@intel.com>
Mon, 14 Nov 2016 15:02:25 +0000 (09:02 -0600)
Don't generate files when no events have been generated outside
the header events.

Reviewed-by: Bruce Cherniak <bruce.cherniak@intel.com>
src/gallium/drivers/swr/rasterizer/archrast/archrast.cpp
src/gallium/drivers/swr/rasterizer/archrast/archrast.h
src/gallium/drivers/swr/rasterizer/core/api.cpp
src/gallium/drivers/swr/rasterizer/scripts/templates/ar_eventhandlerfile_h.template

index 574098d80a8880e6a753cc518a93a74b167b52ae..16b6d3347ac399bedf908ca20f16893af09cb909 100644 (file)
@@ -53,19 +53,31 @@ namespace ArchRast
     }
 
     // Construct an event manager and associate a handler with it.
-    HANDLE CreateThreadContext()
+    HANDLE CreateThreadContext(AR_THREAD type)
     {
         // Can we assume single threaded here?
         static std::atomic<uint32_t> counter(0);
         uint32_t id = counter.fetch_add(1);
 
         EventManager* pManager = new EventManager();
-        EventHandler* pHandler = new EventHandlerStatsFile(id);
+        EventHandlerFile* pHandler = new EventHandlerStatsFile(id);
 
         if (pManager && pHandler)
         {
             pManager->Attach(pHandler);
 
+            if (type == AR_THREAD::API)
+            {
+                ThreadStartApiEvent e;
+                pManager->Dispatch(e);
+            }
+            else
+            {
+                ThreadStartWorkerEvent e;
+                pManager->Dispatch(e);
+            }
+            pHandler->MarkHeader();
+
             return pManager;
         }
 
index e6376f208fe8c259bba0b02d7238d86079149ca4..4783144fcb5702f60f42b30b6429295e8ee5bf47 100644 (file)
 
 namespace ArchRast
 {
-    HANDLE CreateThreadContext();
+    enum class AR_THREAD
+    {
+        API = 0,
+        WORKER = 1
+    };
+
+    HANDLE CreateThreadContext(AR_THREAD type);
     void DestroyThreadContext(HANDLE hThreadContext);
 
     // Dispatch event for this thread.
index 542eccda95e685b688b6b331e765f58a04683085..bf7a9f606f524552418e7a5fef029c846f342c18 100644 (file)
@@ -115,8 +115,7 @@ HANDLE SwrCreateContext(
 #if defined(KNOB_ENABLE_AR)
     // Setup ArchRast thread contexts which includes +1 for API thread.
     pContext->pArContext = new HANDLE[pContext->NumWorkerThreads+1];
-    pContext->pArContext[pContext->NumWorkerThreads] = ArchRast::CreateThreadContext();
-    _AR_EVENT(pContext->pArContext[pContext->NumWorkerThreads], ThreadStartApiEvent());
+    pContext->pArContext[pContext->NumWorkerThreads] = ArchRast::CreateThreadContext(ArchRast::AR_THREAD::API);
 #endif
 
     // Allocate scratch space for workers.
@@ -136,8 +135,7 @@ HANDLE SwrCreateContext(
 
 #if defined(KNOB_ENABLE_AR)
         // Initialize worker thread context for ArchRast.
-        pContext->pArContext[i] = ArchRast::CreateThreadContext();
-        _AR_EVENT(pContext->pArContext[i], ThreadStartWorkerEvent());
+        pContext->pArContext[i] = ArchRast::CreateThreadContext(ArchRast::AR_THREAD::WORKER);
 #endif
     }
 
index 97eca59f564318d7d1ea576f62f7ce9fa6d6eb2f..ada134d01c3ae6588338b0888a293963df0c1c40 100644 (file)
@@ -81,6 +81,12 @@ namespace ArchRast
         {
             if (mBufOffset > 0)
             {
+                if (mBufOffset == mHeaderBufOffset)
+                {
+                    // Nothing to flush. Only header has been generated.
+                    return false;
+                }
+
                 std::ofstream file;
                 file.open(mFilename, std::ios::out | std::ios::app | std::ios::binary);
 
@@ -94,6 +100,7 @@ namespace ArchRast
                 file.close();
 
                 mBufOffset = 0;
+                mHeaderBufOffset = 0; // Reset header offset so its no longer considered.
             }
             return true;
         }
@@ -121,7 +128,7 @@ namespace ArchRast
 % for name in protos['event_names']:
         //////////////////////////////////////////////////////////////////////////
         /// @brief Handle ${name} event
-        virtual void Handle(${name}& event)
+        virtual void Handle(${name}&& event)
         {
 % if protos['events'][name]['num_fields'] == 0:
             Write(${protos['events'][name]['event_id']}, (char*)&event.data, 0);
@@ -131,10 +138,18 @@ namespace ArchRast
         }
 % endfor
 
+        //////////////////////////////////////////////////////////////////////////
+        /// @brief Everything written to buffer this point is the header.
+        virtual void MarkHeader()
+        {
+            mHeaderBufOffset = mBufOffset;
+        }
+
         std::string mFilename;
 
         static const uint32_t mBufferSize = 1024;
         uint8_t mBuffer[mBufferSize];
         uint32_t mBufOffset{0};
+        uint32_t mHeaderBufOffset{0};
     };
 }