Interesting article on using chrome://tracing/

Started by eri0o, Wed 05/02/2020 02:44:30

Previous topic - Next topic

eri0o

https://www.gamasutra.com/view/news/176420/Indepth_Using_Chrometracing_to_view_your_inline_profiling_data.php | webarchive link

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.

Mandle


eri0o


Mandle

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.  ;)

Monsieur OUXX

#4
I don't understand : Does this apply to AGS?


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

Wyz

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)
Life is like an adventure without the pixel hunts.

eri0o


Snarky

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?

Monsieur OUXX

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.
 

eri0o

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
// 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
// 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
#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
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.

SMF spam blocked by CleanTalk