Add template for generating code to save events to a file.
Signed-off-by: Tim Rowley <timothy.o.rowley@intel.com>
rasterizer/jitter/builder_x86.cpp \
rasterizer/archrast/gen_ar_event.h \
rasterizer/archrast/gen_ar_event.cpp \
- rasterizer/archrast/gen_ar_eventhandler.h
+ rasterizer/archrast/gen_ar_eventhandler.h \
+ rasterizer/archrast/gen_ar_eventhandlerfile.h
MKDIR_GEN = $(AM_V_at)$(MKDIR_P) $(@D)
PYTHON_GEN = $(AM_V_GEN)$(PYTHON2) $(PYTHON_FLAGS)
--output rasterizer/archrast/gen_ar_eventhandler.h \
--gen_eventhandler_h
+rasterizer/archrast/gen_ar_eventhandlerfile.h: rasterizer/scripts/gen_archrast.py rasterizer/scripts/templates/ar_eventhandlerfile_h.template rasterizer/archrast/events.proto
+ $(MKDIR_GEN)
+ $(PYTHON_GEN) \
+ $(srcdir)/rasterizer/scripts/gen_archrast.py \
+ --proto $(srcdir)/rasterizer/archrast/events.proto \
+ --output rasterizer/archrast/gen_ar_eventhandlerfile.h \
+ --gen_eventhandlerfile_h
+
COMMON_LIBADD = \
$(top_builddir)/src/gallium/auxiliary/libgallium.la \
$(top_builddir)/src/mesa/libmesagallium.la \
* @brief Definitions for archrast.
*
******************************************************************************/
+#include <atomic>
+
#include "common/os.h"
#include "archrast/archrast.h"
#include "archrast/eventmanager.h"
+#include "gen_ar_eventhandlerfile.h"
namespace ArchRast
{
// Construct an event manager and associate a handler with it.
HANDLE CreateThreadContext()
{
+ // 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 EventHandler();
+ EventHandler* pHandler = new EventHandlerFile(id);
if (pManager && pHandler)
{
protos['enums'] = {}
protos['enum_names'] = []
+ eventId = 0
raw_text = []
while idx < len(lines):
line = lines[idx].rstrip()
match = re.match(r"(\s*)event(\s*)(\w+)", line)
if match:
+ eventId += 1
event_name = match.group(3)
protos['event_names'].append(event_name)
protos['events'][event_name] = {}
+ protos['events'][event_name]['event_id'] = eventId
idx = parse_event_fields(lines, idx, protos['events'][event_name])
# search for enums.
parser.add_argument("--gen_event_h", "-geh", help="Generate event header", action="store_true", default=False)
parser.add_argument("--gen_event_cpp", "-gec", help="Generate event cpp", action="store_true", default=False)
parser.add_argument("--gen_eventhandler_h", "-gehh", help="Generate eventhandler header", action="store_true", default=False)
+ parser.add_argument("--gen_eventhandlerfile_h", "-gehf", help="Generate eventhandler header for writing to files", action="store_true", default=False)
args = parser.parse_args()
proto_filename = args.proto
event_header="gen_ar_event.h", # todo: fix this!
protos=protos)
+ # Generate event handler header
+ if args.gen_eventhandlerfile_h:
+ curdir = os.path.dirname(os.path.abspath(__file__))
+ template_file = os.sep.join([curdir, 'templates', 'ar_eventhandlerfile_h.template'])
+ output_fullpath = os.sep.join([output_dir, output_filename])
+
+ write_template_to_file(template_file, output_fullpath,
+ filename=output_filename,
+ event_header="gen_ar_eventhandler.h", # todo: fix this!
+ protos=protos)
+
return 0
if __name__ == '__main__':
--- /dev/null
+/****************************************************************************
+* Copyright (C) 2016 Intel Corporation. All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice (including the next
+* paragraph) shall be included in all copies or substantial portions of the
+* Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+* IN THE SOFTWARE.
+*
+* @file ${filename}
+*
+* @brief Event handler interface. auto-generated file
+*
+* DO NOT EDIT
+*
+******************************************************************************/
+#pragma once
+
+#include "common/os.h"
+#include "${event_header}"
+#include <fstream>
+
+namespace ArchRast
+{
+ //////////////////////////////////////////////////////////////////////////
+ /// EventHandlerFile - interface for handling events.
+ //////////////////////////////////////////////////////////////////////////
+ class EventHandlerFile : public EventHandler
+ {
+ public:
+ EventHandlerFile(uint32_t id)
+ {
+#if defined(_WIN32)
+ char buf[255];
+ // There could be multiple threads creating thread pools. We
+ // want to make sure they are uniquly identified by adding in
+ // the creator's thread id into the filename.
+ sprintf(buf, "\\ar_event%d_%d.bin", GetCurrentThreadId(), id);
+ mFilename = std::string(buf);
+#else
+ SWR_ASSERT(0);
+#endif
+ }
+
+ ~EventHandlerFile()
+ {
+ if (mFile.is_open()) mFile.close();
+ }
+
+ void write(uint32_t eventId, const char* pBlock, uint32_t size)
+ {
+ if (!mFile.is_open())
+ {
+ mFile.open(mFilename, std::ios::out | std::ios::app | std::ios::binary);
+ }
+
+ mFile.write((char*)&eventId, sizeof(eventId));
+ mFile.write(pBlock, size);
+ }
+
+% for name in protos['event_names']:
+ virtual void handle(${name}& event)
+ {
+ write(${protos['events'][name]['event_id']}, (char*)&event, sizeof(event));
+ }
+% endfor
+
+ std::ofstream mFile;
+ std::string mFilename;
+ };
+}