Skip to content

Instantly share code, notes, and snippets.

@wotakuro
Created December 26, 2022 08:30
Show Gist options
  • Save wotakuro/b885af836dba93551da93ecb5516058c to your computer and use it in GitHub Desktop.
Save wotakuro/b885af836dba93551da93ecb5516058c to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Profiling;
using UnityEngine.UI;
using System.Text;
using Unity.Profiling.LowLevel.Unsafe;
public class ReleaseBuildRecordCheck : MonoBehaviour
{
public Text info;
List<ProfilerRecorderHandle> handles = new List<ProfilerRecorderHandle>();
private List<string> recordNames;
private List<ProfilerRecorder> recorders;
private StringBuilder stringBuilder = new StringBuilder();
// Start is called before the first frame update
void Start()
{
this.recordNames = new List<string>();
this.recorders = new List<ProfilerRecorder>();
ProfilerRecorderHandle.GetAvailable(this.handles);
foreach (var handle in handles)
{
if (handle.Valid)
{
var statDesc = ProfilerRecorderHandle.GetDescription(handle);
recordNames.Add(statDesc.Name);
var recorder = new Unity.Profiling.ProfilerRecorder(statDesc.Name);
recorder.Start();
recorders.Add(recorder);
}
}
}
// Update is called once per frame
void Update()
{
if(Time.frameCount%30 != 0) { return; }
stringBuilder.Clear();
stringBuilder.Append("count ").Append(recordNames.Count).Append("\n");
for (int i = 0; i < recordNames.Count; i++)
{
stringBuilder.Append(recordNames[i]).Append("::").
Append(recorders[i].LastValueAsDouble).Append(" ");
if(i % 3 == 0 || true)
{
stringBuilder.Append("\n");
}
}
if (info)
{
info.text = stringBuilder.ToString();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment