13using System.Collections;
14using System.Collections.Generic;
24 if (_cachedInstance ==
null) {
25 _cachedInstance = FindObjectOfType<RealtimeGraph>();
27 return _cachedInstance;
83 [Header(
"References")]
117 protected System.Diagnostics.Stopwatch
_stopwatch =
new System.Diagnostics.Stopwatch();
162 graph.
AddSample((
long)(ms * System.Diagnostics.Stopwatch.Frequency * 0.001f));
180 _graphs =
new Dictionary<string, Graph>();
193 _texture.filterMode = FilterMode.Point;
194 _texture.wrapMode = TextureWrapMode.Clamp;
208 Camera.onPreCull += onPreCull;
209 Camera.onPostRender += onPostRender;
211 StartCoroutine(endOfFrameWaiter());
215 Camera.onPreCull -= onPreCull;
216 Camera.onPostRender -= onPostRender;
247 for (var it =
_graphs.GetEnumerator(); it.MoveNext();) {
248 var graph = it.Current.Value;
257 float currValue, currMax;
268 throw new Exception(
"Unexpected graph mode");
288 private IEnumerator endOfFrameWaiter() {
289 WaitForEndOfFrame waiter =
new WaitForEndOfFrame();
290 long endOfFrameTicks =
_stopwatch.ElapsedTicks;
297 endOfFrameTicks = newTicks;
301 float gpuTime = XRSupportUtil.GetGPUTime();
311 private void onPreCull(Camera camera) {
317 private void onPostRender(Camera camera) {
322 return (
float)(ticks / (System.Diagnostics.Stopwatch.Frequency / 1000.0));
325 private string msToString(
float ms) {
326 return (Mathf.Round(ms * 10) * 0.1f).ToString();
329 private long msToTicks(
float ms) {
330 return (
long)(ms * System.Diagnostics.Stopwatch.Frequency * 1000);
333 private float getGraphSpacing() {
340 throw new Exception(
"Unexpected graph units");
344 private void UpdateTexture() {
346 max = (max > 0f) ? Mathf.Max(0.0001f, max) : Mathf.Min(-0.0001f, max);
348 Deque<float> history;
357 throw new Exception(
"Unexpected graph mode");
360 for (
int i = 0; i < history.Count; i++) {
361 float percent = Mathf.Clamp01(history[i] / max);
362 byte percentByte = (byte)(percent * 255.9999f);
363 _colors[i] =
new Color32(percentByte, percentByte, percentByte, percentByte);
366 _graphRenderer.material.SetFloat(
"_GraphScale", max / getGraphSpacing());
375 if(!
float.IsNaN(localP.y) && !
float.IsInfinity(localP.y))
valueMesh.transform.localPosition = localP;
380 if (!
_graphs.TryGetValue(name, out graph)) {
387 Text buttonText = buttonObj.GetComponentInChildren<Text>();
388 buttonText.text = name.Replace(
' ',
'\n');
390 Button button = buttonObj.GetComponentInChildren<
Button>();
393 buttonObj.SetActive(
true);
403 button.onClick.AddListener(() =>
SwtichGraph(name));
411 if (key.name !=
null) {
439 private int maxHistory;
441 private long accumulatedInclusiveTicks, accumulatedExclusiveTicks;
442 private long inclusiveStart, exclusiveStart;
447 this.maxHistory = maxHistory;
455 inclusiveStart = exclusiveStart = currTicks;
459 accumulatedInclusiveTicks += currTicks - inclusiveStart;
463 inclusiveStart = currTicks;
467 accumulatedInclusiveTicks += currTicks - inclusiveStart;
468 accumulatedExclusiveTicks += currTicks - exclusiveStart;
472 accumulatedInclusiveTicks += ticks;
473 accumulatedExclusiveTicks += ticks;
477 accumulatedExclusiveTicks = accumulatedInclusiveTicks = 0;
481 float inclusiveMs =
ticksToMs(accumulatedInclusiveTicks / sampleCount);
482 float exclusiveMs =
ticksToMs(accumulatedExclusiveTicks / sampleCount);
499 throw new Exception(
"Unexpected units type");
UnityEngine.UI.Button Button
long Now()
Returns a timestamp value as close as possible to the current time. Values are in microseconds,...
long Timestamp
The frame capture time in microseconds elapsed since an arbitrary point in time in the past.
float CurrentFramesPerSecond
The instantaneous framerate.
void EndSample(long currTicks)
void BeginSample(long currTicks)
Graph(string name, GraphUnits units, int maxHistory)
void AddSample(long ticks)
void PauseSample(long currTicks)
void RecordSample(int sampleCount)
void ResumeSample(long currTicks)
void BeginSample(string sampleName, GraphUnits units)
virtual void FixedUpdate()
Graph getGraph(string name, GraphUnits units)
string[] _unitySamplerNames
static RealtimeGraph Instance
void SwtichGraph(string graphName)
Dictionary< string, Graph > _graphs
Deque< GraphKey > _keyBuffer
void AddSample(string sampleName, GraphUnits units, float ms)
LeapServiceProvider _provider
static float ticksToMs(long ticks)
void addCallback(Button button, string name)
void BeginSample(GraphKey key)
List< Recorder > _unityRecorders
System.Diagnostics.Stopwatch _stopwatch
float _valueSmoothingDelay
void AddSample(string sampleName, GraphUnits units, long ticks)
SmoothedFloat _smoothedMax
SmoothedFloat _smoothedValue
GameObject customGraphPrefab
virtual void OnValidate()
Stack< Graph > _currentGraphStack
float _framerateLineSpacing
The LeapServiceProvider provides tracked Leap Hand data and images from the device via the Leap servi...
Controller GetLeapController()
Returns the Leap Controller instance.
override Frame CurrentFrame
void AddValue(float value)
Time-step independent exponential smoothing.
float Update(float input, float deltaTime=1f)
GraphKey(string name, GraphUnits units, long tick=0)