So, I did endup using today. It requires a very high resolution Timer for it to work, I think in Microseconds, and AGS doesn't have one. I tried to use a music clip that would give me a milissecond timer and Chrome just crashes if begin and end time of the same event matches (which is just unfortunately).
profiler.ash// Profiler module header
import void InitProfiler();
import void CloseProfiler();
import void pro(const string cat, const string name, const string ph);
profiler.asc// Profiler module script
File* pf;
AudioChannel* time;
int ts;
void InitProfiler()
{
time = aRain_calm.Play(eAudioPriorityHigh, eRepeat);
pf = File.Open("$SAVEGAMEDIR$/profile.json",eFileWrite);
pf.WriteRawLine("[\n");
pf.Close();
pf = File.Open("$SAVEGAMEDIR$/profile.json",eFileAppend);
}
void CloseProfiler()
{
pf.WriteRawLine("\n]");
pf.Close();
}
void pro(const string cat, const string name, const string ph)
{
ts = DateTime.Now.RawTime;
if(pf)
pf.WriteRawLine(
String.Format("{\"cat\": \"%s\", \"pid\": 1, \"tid\": 1, \"ts\": %d, \"ph\": \"%s\", \"name\": \"%s\", \"args\": {} },\n",
cat, ts, ph, name));
}
Then on your code you use like this
#define PRO
void my_func() {
#ifdef PRO
pro("my","func","B");
#endif
// things inside my function I wish to measure
#ifdef PRO
pro("my","func","E");
#endif
}
The preprocessor Macro is so you can turn off it easily.
On your game save directory, this will generate a
profile.json file. If you force close, you need to open with a text editor and terminate it with a
].
But for the code above to work I had to hack ags datetime.cpp and force it return me time in microsseconds.
int DateTime_GetRawTime(ScriptDateTime *sdt) {
return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::
now().time_since_epoch()).count();
//return sdt->rawUnixTime;
}
But in the end I discovered the Chrome profile is not very good and it's suuuuper slow and doesn't give any meaningful statistics.