// [MenuItem("Window/pb_Profiler Test")] public static void Init() { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < ITERATIONS; i++) { Thread.Sleep(SLEEP); } stopwatch.Stop(); pb_Profiler profiler = new pb_Profiler("pb_Profiler Tests"); profiler.BeginSample("Sleep"); for (int i = 0; i < ITERATIONS; i++) { profiler.BeginSample("Thread.Sleep"); Thread.Sleep(SLEEP); profiler.EndSample(); } profiler.EndSample(); profiler.EndSample(); long s_sum = stopwatch.ElapsedMilliseconds; long p_sum = profiler.GetRootSample().sum; if (System.Math.Abs(p_sum - s_sum) > MAX_SUM_DELTA) { UE.Debug.LogError("Stopwatch: " + s_sum + "\nProfiler: " + s_sum); } else { UE.Debug.Log("Stopwatch: " + s_sum + "\nProfiler: " + s_sum); } }
static void MenuTestProfiler() { profiler.BeginSample("test a"); profiler.BeginSample("iteration"); for (int i = 0; i < 64; i++) { profiler.BeginSample("random"); Thread.Sleep((int)UnityEngine.Random.Range(2f, 10f)); profiler.EndSample(); } profiler.EndSample(); profiler.BeginSample("sleep 100ms"); Thread.Sleep(100); profiler.EndSample(); profiler.BeginSample("test b"); profiler.BeginSample("sleep 20ms"); Thread.Sleep(20); profiler.EndSample(); profiler.BeginSample("sleep 10ms"); Thread.Sleep(10); profiler.EndSample(); profiler.BeginSample("sleep 40ms"); Thread.Sleep(40); profiler.EndSample(); profiler.BeginSample("sleep 10ms"); Thread.Sleep(10); profiler.EndSample(); profiler.EndSample(); profiler.EndSample(); }
public static void End() { s_Profiler.EndSample(); }
public static void Run() { // Run some intensive calculations an time them. pb_Profiler profiler = new pb_Profiler(); float[] rand = new float[SAMPLE_COUNT]; bool superBreak = false; profiler.BeginSample("Run CPU Intensive Tasks"); profiler.BeginSample("Generate Random Numbers"); { for(int i = 0; i < SAMPLE_COUNT; i++) { profiler.BeginSample("Show Progress Bar"); if( EditorUtility.DisplayCancelableProgressBar("Doing some CPU intensive tasks...", "Generating lots of random numbers.", (i/(float)SAMPLE_COUNT) / 2f) ) { superBreak = true; break; } profiler.EndSample(); profiler.BeginSample("Random.Range"); rand[i] = Random.Range(0f, 1000f); profiler.EndSample(); } } profiler.EndSample(); profiler.BeginSample("Do Math with Random Numbers"); { for(int i = 0; i < SAMPLE_COUNT-3; i++) { profiler.BeginSample("Show Progress Bar"); if( EditorUtility.DisplayCancelableProgressBar("Doing some CPU intensive tasks...", "Generating lots of random numbers.", ((i/(float)SAMPLE_COUNT) / 2f) + .5f) || superBreak) break; profiler.EndSample(); profiler.BeginSample("Allocate Vector3"); Vector3 v0 = new Vector3( rand[i+0], rand[i+1], rand[i+2] ); Vector3 v1 = new Vector3( rand[i+1], rand[i+2], rand[i+0] ); profiler.EndSample(); profiler.BeginSample("Cross -> Dot Product"); profiler.BeginSample("Cross Product"); Vector3 f = Vector3.Cross(v0, v1); profiler.EndSample(); profiler.BeginSample("Dot Product"); f.x = Vector3.Dot(f, v0); profiler.EndSample(); profiler.EndSample(); profiler.BeginSample("Normalize"); f = Vector3.Normalize(v0); profiler.EndSample(); } } EditorUtility.ClearProgressBar(); profiler.EndSample(); // </Do Math> profiler.EndSample(); // </Run CPU> Debug.Log(profiler.ToString()); }
public static void Run() { // Run some intensive calculations an time them. pb_Profiler profiler = new pb_Profiler("Demo"); float[] rand = new float[SAMPLE_COUNT]; bool superBreak = false; profiler.BeginSample("Run CPU Intensive Tasks"); profiler.BeginSample("Generate Random Numbers"); { for (int i = 0; i < SAMPLE_COUNT; i++) { profiler.BeginSample("Show Progress Bar"); if (EditorUtility.DisplayCancelableProgressBar("Doing some CPU intensive tasks...", "Generating lots of random numbers.", (i / (float)SAMPLE_COUNT) / 2f)) { superBreak = true; break; } profiler.EndSample(); profiler.BeginSample("Random.Range"); rand[i] = Random.Range(0f, 1000f); profiler.EndSample(); } } profiler.EndSample(); profiler.BeginSample("Do Math with Random Numbers"); { for (int i = 0; i < SAMPLE_COUNT - 3; i++) { profiler.BeginSample("Show Progress Bar"); if (EditorUtility.DisplayCancelableProgressBar("Doing some CPU intensive tasks...", "Generating lots of random numbers.", ((i / (float)SAMPLE_COUNT) / 2f) + .5f) || superBreak) { break; } profiler.EndSample(); profiler.BeginSample("Allocate Vector3"); Vector3 v0 = new Vector3(rand[i + 0], rand[i + 1], rand[i + 2]); Vector3 v1 = new Vector3(rand[i + 1], rand[i + 2], rand[i + 0]); profiler.EndSample(); profiler.BeginSample("Cross -> Dot Product"); profiler.BeginSample("Cross Product"); Vector3 f = Vector3.Cross(v0, v1); profiler.EndSample(); profiler.BeginSample("Dot Product"); f.x = Vector3.Dot(f, v0); profiler.EndSample(); profiler.EndSample(); profiler.BeginSample("Normalize"); f = Vector3.Normalize(v0); profiler.EndSample(); } } EditorUtility.ClearProgressBar(); profiler.EndSample(); // </Do Math> profiler.EndSample(); // </Run CPU> Debug.Log(profiler.ToString()); }