diff --git a/Samples/Advanced/Advanced.cpp b/Samples/Advanced/Advanced.cpp new file mode 100644 index 0000000..9f8d505 --- /dev/null +++ b/Samples/Advanced/Advanced.cpp @@ -0,0 +1,55 @@ +/* +The zlib/libpng License + +Copyright (c) 2007 Aidin Abedi (http://sourceforge.net/projects/shinyprofiler) + +This software is provided 'as-is', without any express or implied warranty. In no event will +the authors be held liable for any damages arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, including commercial +applications, and to alter it and redistribute it freely, subject to the following +restrictions: + + 1. The origin of this software must not be misrepresented; you must not claim that + you wrote the original software. If you use this software in a product, + an acknowledgment in the product documentation would be appreciated but is + not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "Shiny.h" +#include + +#include "Shared.h" + + +//----------------------------------------------------------------------------- + +PROFILE_SHARED_DEFINE(Math); + +void DoSomeMath() { + PROFILE_SHARED_BLOCK(Math); // begin profile until end of block +} + + +//----------------------------------------------------------------------------- + +void Recursion(int calls_left) { + PROFILE_FUNC(); // begin profile until end of block + + millisleep(20); + + if (calls_left > 0) Recursion(calls_left - 1); +} + + +//----------------------------------------------------------------------------- + +void ExecuteCommand(const char *command) { + + PROFILE_CODE(system(command)); +} diff --git a/Samples/Recursion/Demo_Recursion.vcproj b/Samples/Advanced/Demo_Advanced.vcproj similarity index 91% rename from Samples/Recursion/Demo_Recursion.vcproj rename to Samples/Advanced/Demo_Advanced.vcproj index 2e79dd4..7b779ad 100644 --- a/Samples/Recursion/Demo_Recursion.vcproj +++ b/Samples/Advanced/Demo_Advanced.vcproj @@ -2,7 +2,7 @@ + + + + diff --git a/Samples/Recursion/Recursion.cpp b/Samples/Advanced/Main.cpp similarity index 81% rename from Samples/Recursion/Recursion.cpp rename to Samples/Advanced/Main.cpp index e3da605..b0e3fe6 100644 --- a/Samples/Recursion/Recursion.cpp +++ b/Samples/Advanced/Main.cpp @@ -22,13 +22,16 @@ applications, and to alter it and redistribute it freely, subject to the followi */ #include "Shiny.h" +#include #ifdef _WIN32 -#include +#include // Sleep #else // assume POSIX -#include +#include // usleep #endif +#include "Shared.h" + //----------------------------------------------------------------------------- @@ -43,12 +46,8 @@ void millisleep(unsigned int milliseconds) { //----------------------------------------------------------------------------- -void Recursion(int calls_left) { - PROFILE_FUNC(); // begin profile until end of block - - millisleep(20); - - if (calls_left > 0) Recursion(calls_left - 1); +void YetMoreMath() { + PROFILE_SHARED_BLOCK(Math); // begin profile until end of block } @@ -56,8 +55,16 @@ void Recursion(int calls_left) { int main() { + DoSomeMath(); + YetMoreMath(); Recursion(12); +#ifdef _WIN32 + ExecuteCommand("cls"); +#else + ExecuteCommand("clear"); +#endif + PROFILE_UPDATE(); // update all profiles PROFILE_OUTPUT(stdout); // print to cout diff --git a/Samples/Advanced/Shared.h b/Samples/Advanced/Shared.h new file mode 100644 index 0000000..9597c98 --- /dev/null +++ b/Samples/Advanced/Shared.h @@ -0,0 +1,43 @@ +/* +The zlib/libpng License + +Copyright (c) 2007 Aidin Abedi (http://sourceforge.net/projects/shinyprofiler) + +This software is provided 'as-is', without any express or implied warranty. In no event will +the authors be held liable for any damages arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, including commercial +applications, and to alter it and redistribute it freely, subject to the following +restrictions: + + 1. The origin of this software must not be misrepresented; you must not claim that + you wrote the original software. If you use this software in a product, + an acknowledgment in the product documentation would be appreciated but is + not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "Shiny.h" + + +//----------------------------------------------------------------------------- + +PROFILE_SHARED_EXTERN(Math); + + +//----------------------------------------------------------------------------- + +void DoSomeMath(); + +void Recursion(int calls_left); + +void ExecuteCommand(const char *command); + + +//----------------------------------------------------------------------------- + +void millisleep(unsigned int milliseconds); diff --git a/Samples/MainLoop/MainLoop.cpp b/Samples/MainLoop/MainLoop.cpp index 46d55f8..4e2b0dd 100644 --- a/Samples/MainLoop/MainLoop.cpp +++ b/Samples/MainLoop/MainLoop.cpp @@ -22,11 +22,12 @@ applications, and to alter it and redistribute it freely, subject to the followi */ #include "Shiny.h" +#include #ifdef _WIN32 -#include +#include // Sleep #else // assume POSIX -#include +#include // usleep #endif diff --git a/Samples/Simple/Simple.cpp b/Samples/Simple/Simple.cpp index 25bd77a..23697c2 100644 --- a/Samples/Simple/Simple.cpp +++ b/Samples/Simple/Simple.cpp @@ -22,11 +22,12 @@ applications, and to alter it and redistribute it freely, subject to the followi */ #include "Shiny.h" +#include #ifdef _WIN32 -#include +#include // Sleep #else // assume POSIX -#include +#include // usleep #endif diff --git a/Shiny.sln b/Shiny.sln index d5efaf5..643349a 100644 --- a/Shiny.sln +++ b/Shiny.sln @@ -8,12 +8,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo_Simple", "Samples\Simp {D44CCFEB-7FC2-46E6-8290-E0B00D06A636} = {D44CCFEB-7FC2-46E6-8290-E0B00D06A636} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo_Recursion", "Samples\Recursion\Demo_Recursion.vcproj", "{D0EB96F2-10EC-4DCC-AC4F-93E20D2717AC}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo_MainLoop", "Samples\MainLoop\Demo_MainLoop.vcproj", "{23595110-7DBF-45AE-95B6-A1A888AED9BF}" ProjectSection(ProjectDependencies) = postProject {D44CCFEB-7FC2-46E6-8290-E0B00D06A636} = {D44CCFEB-7FC2-46E6-8290-E0B00D06A636} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo_MainLoop", "Samples\MainLoop\Demo_MainLoop.vcproj", "{23595110-7DBF-45AE-95B6-A1A888AED9BF}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo_Advanced", "Samples\Advanced\Demo_Advanced.vcproj", "{D0EB96F2-10EC-4DCC-AC4F-93E20D2717AC}" ProjectSection(ProjectDependencies) = postProject {D44CCFEB-7FC2-46E6-8290-E0B00D06A636} = {D44CCFEB-7FC2-46E6-8290-E0B00D06A636} EndProjectSection @@ -32,14 +32,14 @@ Global {CE0B3567-5D70-4AA4-8F7C-29FE8E9CA7A3}.Debug|Win32.Build.0 = Debug|Win32 {CE0B3567-5D70-4AA4-8F7C-29FE8E9CA7A3}.Release|Win32.ActiveCfg = Release|Win32 {CE0B3567-5D70-4AA4-8F7C-29FE8E9CA7A3}.Release|Win32.Build.0 = Release|Win32 - {D0EB96F2-10EC-4DCC-AC4F-93E20D2717AC}.Debug|Win32.ActiveCfg = Debug|Win32 - {D0EB96F2-10EC-4DCC-AC4F-93E20D2717AC}.Debug|Win32.Build.0 = Debug|Win32 - {D0EB96F2-10EC-4DCC-AC4F-93E20D2717AC}.Release|Win32.ActiveCfg = Release|Win32 - {D0EB96F2-10EC-4DCC-AC4F-93E20D2717AC}.Release|Win32.Build.0 = Release|Win32 {23595110-7DBF-45AE-95B6-A1A888AED9BF}.Debug|Win32.ActiveCfg = Debug|Win32 {23595110-7DBF-45AE-95B6-A1A888AED9BF}.Debug|Win32.Build.0 = Debug|Win32 {23595110-7DBF-45AE-95B6-A1A888AED9BF}.Release|Win32.ActiveCfg = Release|Win32 {23595110-7DBF-45AE-95B6-A1A888AED9BF}.Release|Win32.Build.0 = Release|Win32 + {D0EB96F2-10EC-4DCC-AC4F-93E20D2717AC}.Debug|Win32.ActiveCfg = Debug|Win32 + {D0EB96F2-10EC-4DCC-AC4F-93E20D2717AC}.Debug|Win32.Build.0 = Debug|Win32 + {D0EB96F2-10EC-4DCC-AC4F-93E20D2717AC}.Release|Win32.ActiveCfg = Release|Win32 + {D0EB96F2-10EC-4DCC-AC4F-93E20D2717AC}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/include/ShinyMacros.h b/include/ShinyMacros.h index 0953bd5..d535405 100644 --- a/include/ShinyMacros.h +++ b/include/ShinyMacros.h @@ -89,21 +89,23 @@ applications, and to alter it and redistribute it freely, subject to the followi //----------------------------------------------------------------------------- // public preprocessor +#ifdef __cplusplus #define PROFILE_BLOCK( name ) \ \ _PROFILE_BLOCK_DEFINE(_PROFILE_ID_BLOCK()); \ PROFILE_BEGIN(name) - +#endif //----------------------------------------------------------------------------- // public preprocessor +#ifdef __cplusplus #define PROFILE_FUNC() \ \ _PROFILE_BLOCK_DEFINE(_PROFILE_ID_BLOCK()); \ static _PROFILE_ZONE_DEFINE(_PROFILE_ID_ZONE_FUNC(), __FUNCTION__); \ _PROFILE_ZONE_BEGIN(_PROFILE_ID_ZONE_FUNC()) - +#endif //----------------------------------------------------------------------------- // public preprocessor @@ -144,11 +146,12 @@ applications, and to alter it and redistribute it freely, subject to the followi //----------------------------------------------------------------------------- // public preprocessor +#ifdef __cplusplus #define PROFILE_SHARED_BLOCK( name ) \ \ _PROFILE_BLOCK_DEFINE(_PROFILE_ID_BLOCK()); \ _PROFILE_ZONE_BEGIN(_PROFILE_ID_ZONE_SHARED(name)) - +#endif //----------------------------------------------------------------------------- // public preprocessor diff --git a/src/ShinyManager.c b/src/ShinyManager.c index 4532841..889d9b9 100644 --- a/src/ShinyManager.c +++ b/src/ShinyManager.c @@ -70,7 +70,7 @@ ShinyManager Shiny_instance = { /* rootZone = */ { /* next = */ NULL, /* _state = */ SHINY_ZONE_STATE_HIDDEN, - /* name = */ "", + /* name = */ "", /* data = */ { { 0, 0 }, { 0, 0 }, { 0, 0 } } }, /* damping = */ 0.9f,