Trigger build for hl2sdk-l4d changes.
2 * vim: set ts=4 sw=4 tw=99 noet :
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 <sh_vector.h>
39 #include <sm_namehashset.h>
41 #include "common_logic.h"
42 #include <IRootConsoleMenu.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 */
76 static inline bool matches(const char *name, const prof_atom_report_t *report)
78 return strcmp(report->atom_name, name) == 0;
87 void SaveAtom(const prof_atom_t &atom);
88 size_t GetNumReports();
89 prof_atom_report_t *GetReport(size_t i);
92 NameHashSet<prof_atom_report_t *> m_ReportLookup;
93 CVector<prof_atom_report_t *> m_Reports;
98 public IRootConsoleCommand,
105 bool GenerateReport(FILE *fp);
107 public: //SMGlobalClass
108 void OnSourceModAllInitialized();
109 void OnSourceModShutdown();
110 public: //IRootConsoleCommand
111 void OnRootConsoleCommand2(const char *cmdname, const ICommandArgs *command);
113 void OnNativeBegin(IPluginContext *pContext, sp_native_t *native);
115 void OnFunctionBegin(IPluginContext *pContext, const char *name);
116 void OnFunctionEnd();
117 int OnCallbackBegin(IPluginContext *pContext, sp_public_t *pubfunc);
118 void OnCallbackEnd(int serial);
120 void PushProfileStack(IPluginContext *ctx, int type, const char *name);
121 void PopProfileStack(ProfileReport *reporter);
123 void ResumeParent(double addTime);
124 void WriteReport(FILE *fp, ProfileReport *report, const char *name);
126 CStack<prof_atom_t> m_AtomStack;
127 ProfileReport m_Callbacks;
128 ProfileReport m_Functions;
129 ProfileReport m_Natives;
131 prof_point_t m_ProfStart;
134 extern IProfiler *sm_profiler;
136 #endif //_INCLUDE_SOURCEMOD_PLUGIN_PROFILER_H_