Initial Import of beta structs extension.
3 * =============================================================================
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #ifndef _INCLUDE_SOURCEMOD_PLUGIN_PROFILER_H_
33 #define _INCLUDE_SOURCEMOD_PLUGIN_PROFILER_H_
35 #include <sp_vm_api.h>
36 #include <sm_platform.h>
37 #include <sm_trie_tpl.h>
38 #include <sh_vector.h>
41 #include "sm_globals.h"
42 #include "sm_srvcmds.h"
44 using namespace SourcePawn;
45 using namespace SourceHook;
49 #if defined PLATFORM_WINDOWS
51 #elif defined PLATFORM_POSIX
59 int atom_type; /* Type of object we're profiling */
60 int atom_serial; /* Serial number, if appropriate */
61 sp_context_t *ctx; /* Plugin context. */
62 const char *name; /* Name of the function */
63 prof_point_t start; /* Start time */
64 prof_point_t end; /* End time */
65 double base_time; /* Known time from children or pausing. */
68 struct prof_atom_report_t
70 char atom_name[256]; /* Full name to shove to logs */
71 double total_time; /* Total time spent executing, in s */
72 unsigned int num_calls; /* Number of invocations */
73 double min_time; /* Min time spent in one call, in s */
74 double max_time; /* Max time spent in one call, in s */
82 void SaveAtom(const prof_atom_t &atom);
83 size_t GetNumReports();
84 prof_atom_report_t *GetReport(size_t i);
87 KTrie<prof_atom_report_t *> m_ReportLookup;
88 CVector<prof_atom_report_t *> m_Reports;
93 public IRootConsoleCommand,
100 bool GenerateReport(FILE *fp);
102 public: //SMGlobalClass
103 void OnSourceModAllInitialized();
104 void OnSourceModShutdown();
105 public: //IRootConsoleCommand
106 void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
108 void OnNativeBegin(IPluginContext *pContext, sp_native_t *native);
110 void OnFunctionBegin(IPluginContext *pContext, const char *name);
111 void OnFunctionEnd();
112 int OnCallbackBegin(IPluginContext *pContext, sp_public_t *pubfunc);
113 void OnCallbackEnd(int serial);
115 void PushProfileStack(IPluginContext *ctx, int type, const char *name);
116 void PopProfileStack(ProfileReport *reporter);
118 void ResumeParent(double addTime);
119 void WriteReport(FILE *fp, ProfileReport *report, const char *name);
121 CStack<prof_atom_t> m_AtomStack;
122 ProfileReport m_Callbacks;
123 ProfileReport m_Functions;
124 ProfileReport m_Natives;
126 prof_point_t m_ProfStart;
129 extern ProfileEngine g_Profiler;
131 #endif //_INCLUDE_SOURCEMOD_PLUGIN_PROFILER_H_