Skip to content

Instantly share code, notes, and snippets.

@wotakuro
Last active March 24, 2017 05:50
Show Gist options
  • Save wotakuro/a42641e99707d4b1b624f61f75c6e1f4 to your computer and use it in GitHub Desktop.
Save wotakuro/a42641e99707d4b1b624f61f75c6e1f4 to your computer and use it in GitHub Desktop.
Make inserting Profiler call to your code more easily.
using System.Collections;
#if UNITY_5_5_OR_NEWER
using UnityEngine.Profiling;
#else
using UnityEngine;
#endif
/** Make inserting Profiler call to your code more easily.
*
* // use like this
* void Test(){
* using( ProfilingUtil.Sample("TestFunction") ){
* // execute Something...
* }
* }
*
*/
public class ProfilingUtil : System.IDisposable {
public static ProfilingUtil Sample(string name)
{
return new ProfilingUtil(name);
}
private ProfilingUtil(string name)
{
Profiler.BeginSample(name);
}
public void Dispose()
{
Profiler.EndSample();
}
public static bool SampleMoveNext(string name, IEnumerator e)
{
using (var tmp = new ProfilingUtil(name + e.ToString()))
{
return e.MoveNext();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment