Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

Commit

Permalink
added advanced example
Browse files Browse the repository at this point in the history
  • Loading branch information
aidinabedi committed Dec 14, 2009
1 parent 6d7f985 commit 482153b
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 24 deletions.
55 changes: 55 additions & 0 deletions Samples/Advanced/Advanced.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
The zlib/libpng License
Copyright (c) 2007 Aidin Abedi (http:https://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 <stdlib.h>

#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));
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="Demo_Recursion"
Name="Demo_Advanced"
ProjectGUID="{D0EB96F2-10EC-4DCC-AC4F-93E20D2717AC}"
RootNamespace="Demo_Simple"
Keyword="Win32Proj"
Expand Down Expand Up @@ -177,7 +177,15 @@
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\Recursion.cpp"
RelativePath=".\Advanced.cpp"
>
</File>
<File
RelativePath=".\Main.cpp"
>
</File>
<File
RelativePath=".\Shared.h"
>
</File>
</Filter>
Expand Down
23 changes: 15 additions & 8 deletions Samples/Recursion/Recursion.cpp → Samples/Advanced/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ applications, and to alter it and redistribute it freely, subject to the followi
*/

#include "Shiny.h"
#include <stdlib.h>

#ifdef _WIN32
#include <windows.h>
#include <windows.h> // Sleep
#else // assume POSIX
#include <unistd.h>
#include <unistd.h> // usleep
#endif

#include "Shared.h"


//-----------------------------------------------------------------------------

Expand All @@ -43,21 +46,25 @@ 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
}


//-----------------------------------------------------------------------------

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

Expand Down
43 changes: 43 additions & 0 deletions Samples/Advanced/Shared.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
The zlib/libpng License
Copyright (c) 2007 Aidin Abedi (http:https://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);
5 changes: 3 additions & 2 deletions Samples/MainLoop/MainLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ applications, and to alter it and redistribute it freely, subject to the followi
*/

#include "Shiny.h"
#include <stdlib.h>

#ifdef _WIN32
#include <windows.h>
#include <windows.h> // Sleep
#else // assume POSIX
#include <unistd.h>
#include <unistd.h> // usleep
#endif


Expand Down
5 changes: 3 additions & 2 deletions Samples/Simple/Simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ applications, and to alter it and redistribute it freely, subject to the followi
*/

#include "Shiny.h"
#include <stdlib.h>

#ifdef _WIN32
#include <windows.h>
#include <windows.h> // Sleep
#else // assume POSIX
#include <unistd.h>
#include <unistd.h> // usleep
#endif


Expand Down
12 changes: 6 additions & 6 deletions Shiny.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 6 additions & 3 deletions include/ShinyMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ShinyManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ ShinyManager Shiny_instance = {
/* rootZone = */ {
/* next = */ NULL,
/* _state = */ SHINY_ZONE_STATE_HIDDEN,
/* name = */ "<Unprofiled>",
/* name = */ "<unprofiled>",
/* data = */ { { 0, 0 }, { 0, 0 }, { 0, 0 } }
},
/* damping = */ 0.9f,
Expand Down

0 comments on commit 482153b

Please sign in to comment.