Adventure Game Studio

Community => General Discussion => Topic started by: eri0o on Wed 05/02/2020 02:44:30

Title: Interesting article on using chrome://tracing/
Post by: eri0o on Wed 05/02/2020 02:44:30
https://www.gamasutra.com/view/news/176420/Indepth_Using_Chrometracing_to_view_your_inline_profiling_data.php | webarchive link (http://web.archive.org/web/20190324100037/https://www.gamasutra.com/view/news/176420/Indepth_Using_Chrometracing_to_view_your_inline_profiling_data.php)

QuoteIn-depth: Using Chrome://tracing to view your inline profiling data

If you have an inline profiling system, with some slight modifications, you can view that data in the Chrome web browser rather than writing a visualization tool yourself.

Having a nice graphical representation of profiling data is crucial to finding critical hotspots in a realtime application. Creating a viewer application for that custom data is a massive time sink, so before you start writing ones, know your options.

Getting started with profiling your game...

If you are using a Google Chrome / Chromium browser, you can click the link chrome://tracing/, to open an already included profiling tool - you need to copy and paste it into your address bar since the forums automatically add http to the link, and it's not an http link. I found the above article very interesting on how to use it offline on your game to visualize system bottlenecks by producing a json file with a predefined structured. This may be useful to someone else, so I am leaving it linked here.
Title: Re: Interesting article on using chrome://tracing/
Post by: Mandle on Wed 05/02/2020 10:18:08
I understood some of those words.
Title: Re: Interesting article on using chrome://tracing/
Post by: eri0o on Wed 05/02/2020 10:25:47
I was feeling lonely, sorry  :embarrassed:
Title: Re: Interesting article on using chrome://tracing/
Post by: Mandle on Wed 05/02/2020 22:50:25
Quote from: eri0o on Wed 05/02/2020 10:25:47
I was feeling lonely, sorry  :embarrassed:

Hey, I was just kidding, man. Buck up! Dry those eyes, my friend. There are many people here a LOT more technically savvy than me who will find this valuable.  ;)
Title: Re: Interesting article on using chrome://tracing/
Post by: Monsieur OUXX on Thu 06/02/2020 15:52:51
I don't understand : Does this apply to AGS?


EDIT: Oh yes, yes it does! And I already have the logging module ;)
Title: Re: Interesting article on using chrome://tracing/
Post by: Wyz on Thu 06/02/2020 20:51:28
Ah yes, that is quite useful indeed! :-D
I use it to inspect the profiling reports I get from gprof more easily. It nice to have that already built-in your browser. (nod)
Title: Re: Interesting article on using chrome://tracing/
Post by: eri0o on Mon 10/02/2020 13:28:00
Awesome you guys found it interesting :)
Title: Re: Interesting article on using chrome://tracing/
Post by: Snarky on Tue 11/02/2020 10:02:06
Quote from: Monsieur OUXX on Thu 06/02/2020 15:52:51
I don't understand : Does this apply to AGS?


EDIT: Oh yes, yes it does! And I already have the logging module ;)


Please explain. How would you performance-profile an AGS game?
Title: Re: Interesting article on using chrome://tracing/
Post by: Monsieur OUXX on Tue 11/02/2020 14:32:07
Quote from: Snarky on Tue 11/02/2020 10:02:06
Quote from: Monsieur OUXX on Thu 06/02/2020 15:52:51
I don't understand : Does this apply to AGS?


EDIT: Oh yes, yes it does! And I already have the logging module ;)


Please explain. How would you performance-profile an AGS game?

I was mistaken. This does not apply to AGS. At least for performance. For a moment there I thought it could be useful to visualize stuff like "how much time does my tester spend in that room?" if you write it into a Json file during the game session.
Title: Re: Interesting article on using chrome://tracing/
Post by: eri0o on Wed 17/02/2021 22:09:55
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
Code (ags) Select
// Profiler module header
import void InitProfiler();
import void CloseProfiler();
import void pro(const string cat, const string name, const string ph);


profiler.asc
Code (ags) Select
// 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

Code (ags) Select
#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.

Code (cpp) Select
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.