External/Aga.Controls/TimeCounter.cs
author StephaneLenclud
Thu, 18 Apr 2013 23:25:10 +0200
branchMiniDisplay
changeset 444 9b09e2ee0968
permissions -rw-r--r--
Front View plug-in does not init if no sensor added.
Fixing some format to make strings shorter.
Now trying to start SoundGraphAccess.exe process from same directory.
Packed mode now can display three sensors along with the current time.
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Text;
     4 using System.Runtime.InteropServices;
     5 using System.Diagnostics.CodeAnalysis;
     6 
     7 namespace Aga.Controls
     8 {
     9 	/// <summary>
    10 	/// High resolution timer, used to test performance
    11 	/// </summary>
    12 	public static class TimeCounter
    13 	{
    14 		private static Int64 _start;
    15 
    16 		/// <summary>
    17 		/// Start time counting
    18 		/// </summary>
    19 		public static void Start()
    20 		{
    21 			_start = 0;
    22 			QueryPerformanceCounter(ref _start);
    23 		}
    24 
    25 		public static Int64 GetStartValue()
    26 		{
    27 			Int64 t = 0;
    28 			QueryPerformanceCounter(ref t);
    29 			return t;
    30 		}
    31 
    32 		/// <summary>
    33 		/// Finish time counting
    34 		/// </summary>
    35 		/// <returns>time in seconds elapsed from Start till Finish	</returns>
    36 		public static double Finish()
    37 		{
    38 			return Finish(_start);
    39 		}
    40 
    41 		public static double Finish(Int64 start)
    42 		{
    43 			Int64 finish = 0;
    44 			QueryPerformanceCounter(ref finish);
    45 
    46 			Int64 freq = 0;
    47 			QueryPerformanceFrequency(ref freq);
    48 			return (finish - start) / (double)freq;
    49 		}
    50 
    51 		[DllImport("Kernel32.dll")]
    52 		[return: MarshalAs(UnmanagedType.Bool)]
    53 		static extern bool QueryPerformanceCounter(ref Int64 performanceCount);
    54 
    55 		[DllImport("Kernel32.dll")]
    56 		[return: MarshalAs(UnmanagedType.Bool)]
    57 		static extern bool QueryPerformanceFrequency(ref Int64 frequency);
    58 	}
    59 }