1 /****************************************************************************
2 * Copyright (C) 2016 Intel Corporation. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * @brief Event handler interface. auto-generated file
29 ******************************************************************************/
32 #include "common/os.h"
33 #include "${event_header}"
39 //////////////////////////////////////////////////////////////////////////
40 /// EventHandlerFile - interface for handling events.
41 //////////////////////////////////////////////////////////////////////////
42 class EventHandlerFile : public EventHandler
45 EventHandlerFile(uint32_t id)
48 DWORD pid = GetCurrentProcessId();
49 TCHAR procname[MAX_PATH];
50 GetModuleFileName(NULL, procname, MAX_PATH);
51 const char* pBaseName = strrchr(procname, '\\');
52 std::stringstream outDir;
53 outDir << KNOB_DEBUG_OUTPUT_DIR << pBaseName << "_" << pid << std::ends;
54 CreateDirectory(outDir.str().c_str(), NULL);
57 // There could be multiple threads creating thread pools. We
58 // want to make sure they are uniquly identified by adding in
59 // the creator's thread id into the filename.
60 sprintf(buf, "%s\\ar_event%d_%d.bin", outDir.str().c_str(), GetCurrentThreadId(), id);
61 mFilename = std::string(buf);
64 // There could be multiple threads creating thread pools. We
65 // want to make sure they are uniquly identified by adding in
66 // the creator's thread id into the filename.
67 sprintf(buf, "%s/ar_event%d_%d.bin", "/tmp", GetCurrentThreadId(), id);
68 mFilename = std::string(buf);
74 if (mFile.is_open()) mFile.close();
77 void write(uint32_t eventId, const char* pBlock, uint32_t size)
81 mFile.open(mFilename, std::ios::out | std::ios::app | std::ios::binary);
84 mFile.write((char*)&eventId, sizeof(eventId));
85 mFile.write(pBlock, size);
88 % for name in protos['event_names']:
89 virtual void handle(${name}& event)
91 % if protos['events'][name]['num_fields'] == 0:
92 write(${protos['events'][name]['event_id']}, (char*)&event.data, 0);
94 write(${protos['events'][name]['event_id']}, (char*)&event.data, sizeof(event.data));
100 std::string mFilename;