Skip to content

Commit

Permalink
Changed interface PROFILE* => BROFILE*
Browse files Browse the repository at this point in the history
  • Loading branch information
bombomby committed Jul 3, 2015
1 parent 1a871d1 commit 7ecb66b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 40 deletions.
4 changes: 2 additions & 2 deletions ProfilerCore/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,12 @@ OutputDataStream& operator<<(OutputDataStream& stream, const ThreadEntry* entry)
return stream << entry->description;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
PROFILER_API void NextFrame()
BROFILER_API void NextFrame()
{
return Core::NextFrame();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
PROFILER_API bool IsActive()
BROFILER_API bool IsActive()
{
return Core::Get().isActive;
}
Expand Down
12 changes: 6 additions & 6 deletions ProfilerCore/Hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,47 +253,47 @@ typedef VOID (WINAPI *SleepFunction)(_In_ DWORD dwMilliseconds);
static FuncOverride<SleepFunction> SleepOverride("Kernel32.dll", "Sleep");
VOID WINAPI SleepHooked(_In_ DWORD dwMilliseconds)
{
PROFILER_CATEGORY("Sleep", Profiler::Color::White)
BROFILER_CATEGORY("Sleep", Profiler::Color::White)
SleepOverride.originalFunction(dwMilliseconds);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef VOID (WINAPI *SleepExFunction)(_In_ DWORD dwMilliseconds, _In_ BOOL bAlertable);
static FuncOverride<SleepExFunction> SleepExOverride("Kernel32.dll", "SleepEx");
VOID WINAPI SleepExHooked(_In_ DWORD dwMilliseconds, _In_ BOOL bAlertable)
{
PROFILER_CATEGORY("SleepEx", Profiler::Color::White)
BROFILER_CATEGORY("SleepEx", Profiler::Color::White)
SleepExOverride.originalFunction(dwMilliseconds, bAlertable);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef DWORD (WINAPI *WaitForSingleObjectFunction)(_In_ HANDLE hHandle, _In_ DWORD dwMilliseconds);
static FuncOverride<WaitForSingleObjectFunction> WaitForSingleObjectOverride("Kernel32.dll", "WaitForSingleObject");
DWORD WINAPI WaitForSingleObjectHooked(_In_ HANDLE hHandle, _In_ DWORD dwMilliseconds)
{
PROFILER_CATEGORY("WaitForSingleObject", Profiler::Color::White)
BROFILER_CATEGORY("WaitForSingleObject", Profiler::Color::White)
return WaitForSingleObjectOverride.originalFunction(hHandle, dwMilliseconds);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef DWORD (WINAPI *WaitForSingleObjectExFunction)(_In_ HANDLE hHandle, _In_ DWORD dwMilliseconds, _In_ BOOL bAlertable);
static FuncOverride<WaitForSingleObjectExFunction> WaitForSingleObjectExOverride("Kernel32.dll", "WaitForSingleObjectEx");
DWORD WINAPI WaitForSingleObjectExHooked(_In_ HANDLE hHandle, _In_ DWORD dwMilliseconds, _In_ BOOL bAlertable)
{
PROFILER_CATEGORY("WaitForSingleObjectEx", Profiler::Color::White)
BROFILER_CATEGORY("WaitForSingleObjectEx", Profiler::Color::White)
return WaitForSingleObjectExOverride.originalFunction(hHandle, dwMilliseconds, bAlertable);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef DWORD (WINAPI *WaitForMultipleObjectsFunction)(_In_ DWORD nCount, _In_ const HANDLE *lpHandles, _In_ BOOL bWaitAll, _In_ DWORD dwMilliseconds);
static FuncOverride<WaitForMultipleObjectsFunction> WaitForMultipleObjectsOverride("Kernel32.dll", "WaitForMultipleObjects");
DWORD WINAPI WaitForMultipleObjectsHooked(_In_ DWORD nCount, _In_ const HANDLE *lpHandles, _In_ BOOL bWaitAll, _In_ DWORD dwMilliseconds)
{
PROFILER_CATEGORY("WaitForMultipleObjects", Profiler::Color::White)
BROFILER_CATEGORY("WaitForMultipleObjects", Profiler::Color::White)
return WaitForMultipleObjectsOverride.originalFunction(nCount, lpHandles, bWaitAll, dwMilliseconds);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef DWORD (WINAPI *WaitForMultipleObjectsExFunction)(_In_ DWORD nCount, _In_ const HANDLE *lpHandles, _In_ BOOL bWaitAll, _In_ DWORD dwMilliseconds, _In_ BOOL bAlertable);
static FuncOverride<WaitForMultipleObjectsExFunction> WaitForMultipleObjectsExOverride("Kernel32.dll", "WaitForMultipleObjectsEx");
DWORD WINAPI WaitForMultipleObjectsExHooked(_In_ DWORD nCount, _In_ const HANDLE *lpHandles, _In_ BOOL bWaitAll, _In_ DWORD dwMilliseconds, _In_ BOOL bAlertable)
{
PROFILER_CATEGORY("WaitForMultipleObjectsEx", Profiler::Color::White)
BROFILER_CATEGORY("WaitForMultipleObjectsEx", Profiler::Color::White)
return WaitForMultipleObjectsExOverride.originalFunction(nCount, lpHandles, bWaitAll, dwMilliseconds, bAlertable);
}

Expand Down
46 changes: 22 additions & 24 deletions ProfilerCore/Profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
// EXPORTS
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef PROFILER_EXPORTS
#define PROFILER_API __declspec(dllexport)
#define BROFILER_API __declspec(dllexport)
#else
#define PROFILER_API //__declspec(dllimport)
#define BROFILER_API //__declspec(dllimport)
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define BRO_CONCAT_IMPL(x, y) x##y
Expand Down Expand Up @@ -179,18 +179,18 @@ namespace Profiler
namespace Profiler
{
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct PROFILER_API ThreadDescription
struct BROFILER_API ThreadDescription
{
unsigned long threadID;
const char* name;

ThreadDescription(const char* threadName = "MainThread");
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
extern "C" PROFILER_API __int64 GetTime();
PROFILER_API __int64 GetTimeMicroSeconds();
PROFILER_API void NextFrame();
PROFILER_API bool IsActive();
extern "C" BROFILER_API __int64 GetTime();
BROFILER_API __int64 GetTimeMicroSeconds();
BROFILER_API void NextFrame();
BROFILER_API bool IsActive();
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct EventDescription;
struct Frame;
Expand All @@ -209,7 +209,7 @@ struct EventData : public EventTime
const EventDescription* description;
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct PROFILER_API EventDescription
struct BROFILER_API EventDescription
{
bool isSampling;

Expand All @@ -230,7 +230,7 @@ struct PROFILER_API EventDescription
EventDescription& operator=(const EventDescription&);
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct PROFILER_API Event
struct BROFILER_API Event
{

EventData* data;
Expand All @@ -250,7 +250,7 @@ struct PROFILER_API Event
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct PROFILER_API Category : public Event
struct BROFILER_API Category : public Event
{
Category( const EventDescription& description );
};
Expand All @@ -259,29 +259,27 @@ struct PROFILER_API Category : public Event
#pragma endregion

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define PROFILER_EVENT(NAME) static Profiler::EventDescription* BRO_CONCAT(autogenerated_description_, __LINE__) = Profiler::EventDescription::Create( NAME, __FILE__, __LINE__ ); \
#define BROFILER_EVENT(NAME) static Profiler::EventDescription* BRO_CONCAT(autogenerated_description_, __LINE__) = Profiler::EventDescription::Create( NAME, __FILE__, __LINE__ ); \
Profiler::Event BRO_CONCAT(autogenerated_event_, __LINE__)( *(BRO_CONCAT(autogenerated_description_, __LINE__)) ); \

#define PROFILE PROFILER_EVENT(__FUNCSIG__)
#define DEVELOPER_PROFILE
#define PROFILE BROFILER_EVENT(__FUNCSIG__)

#define PROFILER_INLINE_EVENT(NAME, CODE) { PROFILER_EVENT(NAME) CODE; }
#define BROFILER_INLINE_EVENT(NAME, CODE) { BROFILER_EVENT(NAME) CODE; }

#define PROFILER_CATEGORY(NAME, COLOR) static Profiler::EventDescription* BRO_CONCAT(autogenerated_description_, __LINE__) = Profiler::EventDescription::Create( NAME, __FILE__, __LINE__, (unsigned long)COLOR ); \
#define BROFILER_CATEGORY(NAME, COLOR) static Profiler::EventDescription* BRO_CONCAT(autogenerated_description_, __LINE__) = Profiler::EventDescription::Create( NAME, __FILE__, __LINE__, (unsigned long)COLOR ); \
Profiler::Category BRO_CONCAT(autogenerated_event_, __LINE__)( *(BRO_CONCAT(autogenerated_description_, __LINE__)) ); \

#define PROFILER_FRAME(FRAME_NAME) static Profiler::ThreadDescription currentFrameDescription(FRAME_NAME);\
#define BROFILER_FRAME(FRAME_NAME) static Profiler::ThreadDescription currentFrameDescription(FRAME_NAME);\
Profiler::NextFrame(); \
PROFILER_EVENT("Frame") \
BROFILER_EVENT("Frame") \

#define PROFILER_THREAD(FRAME_NAME) Profiler::ThreadDescription currentFrameDescription(FRAME_NAME);\
#define BROFILER_THREAD(FRAME_NAME) Profiler::ThreadDescription currentFrameDescription(FRAME_NAME);\

#else
#define PROFILER_EVENT(NAME)
#define BROFILER_EVENT(NAME)
#define PROFILE
#define DEVELOPER_PROFILE
#define PROFILER_INLINE_EVENT(NAME, CODE) { CODE; }
#define PROFILER_CATEGORY(NAME, COLOR)
#define PROFILER_FRAME(NAME)
#define PROFILER_THREAD(FRAME_NAME)
#define BROFILER_INLINE_EVENT(NAME, CODE) { CODE; }
#define BROFILER_CATEGORY(NAME, COLOR)
#define BROFILER_FRAME(NAME)
#define BROFILER_THREAD(FRAME_NAME)
#endif
16 changes: 8 additions & 8 deletions ProfilerTest/TestEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Test
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
DWORD WINAPI WorkerThread(PVOID params)
{
PROFILER_THREAD("Worker")
BROFILER_THREAD("Worker")
Engine* engine = (Engine*)params;

while (engine->IsAlive())
Expand Down Expand Up @@ -52,7 +52,7 @@ void SlowFunction2()

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool Engine::Update()
{ PROFILER_FRAME("MainThread")
{ BROFILER_FRAME("MainThread")
UpdateInput();

UpdateMessages();
Expand All @@ -69,32 +69,32 @@ bool Engine::Update()
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Engine::UpdateInput()
{ PROFILER_CATEGORY( "UpdateInput", Profiler::Color::SteelBlue )
{ BROFILER_CATEGORY( "UpdateInput", Profiler::Color::SteelBlue )
SlowFunction2();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Engine::UpdateMessages()
{ PROFILER_CATEGORY( "UpdateMessages", Profiler::Color::Orange )
{ BROFILER_CATEGORY( "UpdateMessages", Profiler::Color::Orange )
SlowFunction<REPEAT_COUNT>();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Engine::UpdateLogic()
{ PROFILER_CATEGORY( "UpdateLogic", Profiler::Color::Orchid )
{ BROFILER_CATEGORY( "UpdateLogic", Profiler::Color::Orchid )
SlowFunction<REPEAT_COUNT>();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Engine::UpdateScene()
{ PROFILER_CATEGORY( "UpdateScene", Profiler::Color::SkyBlue )
{ BROFILER_CATEGORY( "UpdateScene", Profiler::Color::SkyBlue )
SlowFunction<REPEAT_COUNT>();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Engine::Draw()
{ PROFILER_CATEGORY( "Draw", Profiler::Color::Salmon )
{ BROFILER_CATEGORY( "Draw", Profiler::Color::Salmon )
SlowFunction<REPEAT_COUNT>();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Engine::UpdatePhysics()
{ PROFILER_CATEGORY( "UpdatePhysics", Profiler::Color::Wheat )
{ BROFILER_CATEGORY( "UpdatePhysics", Profiler::Color::Wheat )
int64 time = Profiler::GetTimeMicroSeconds();
while (Profiler::GetTimeMicroSeconds() - time < 20 * 1000) {}
}
Expand Down

0 comments on commit 7ecb66b

Please sign in to comment.