/// <summary>
        /// Calls the specified observable call.
        /// </summary>
        /// <param name="statementMetricHandle">The statement metric handle.</param>
        /// <param name="perfCollector">The perf collector.</param>
        /// <param name="observableCall">The observable call.</param>
        /// <param name="numInput">The num input.</param>
        public static void Call(this StatementMetricHandle statementMetricHandle, PerformanceCollector perfCollector, Action observableCall, int numInput = 1)
        {
            if ((MetricReportingPath.IsMetricsEnabled) && statementMetricHandle.IsEnabled)
            {
#if MONO
                long lCreationTime, lExitTime;
                long lUserTimeA, lKernelTimeA;
                long lUserTimeB, lKernelTimeB;
                //IntPtr thread = GetCurrentThread();
                long lWallTimeA = PerformanceObserverMono.NanoTime;

                //GetThreadTimes(out lUserTimeA, out lKernelTimeA);
                observableCall.Invoke();
                //GetThreadTimes(out lUserTimeB, out lKernelTimeB);

                long lWallTimeB = PerformanceObserverMono.NanoTime;
                long lTimeA     = 0; // lKernelTimeA + lUserTimeA
                long lTimeB     = 0; // lKernelTimeB + lUserTimeB

                perfCollector.Invoke(
                    metricValue,
                    100 * (lTimeB - lTimeA),
                    lWallTimeB - lWallTimeA);
#else
                long   lCreationTime, lExitTime;
                long   lUserTimeA, lKernelTimeA;
                long   lUserTimeB, lKernelTimeB;
                IntPtr thread     = GetCurrentThread();
                long   lWallTimeA = PerformanceObserverMono.NanoTime;

                GetThreadTimes(thread, out lCreationTime, out lExitTime, out lUserTimeA, out lKernelTimeA);
                observableCall.Invoke();
                GetThreadTimes(thread, out lCreationTime, out lExitTime, out lUserTimeB, out lKernelTimeB);

                long lWallTimeB = PerformanceObserverMono.NanoTime;
                long lTimeA     = (lKernelTimeA + lUserTimeA);
                long lTimeB     = (lKernelTimeB + lUserTimeB);

                perfCollector.Invoke(
                    statementMetricHandle,
                    100 * (lTimeB - lTimeA),
                    lWallTimeB - lWallTimeA,
                    numInput);
#endif
            }
            else
            {
                observableCall.Invoke();
            }
        }
Exemple #2
0
        /// <summary>
        /// Calls the specified observable call.
        /// </summary>
        /// <param name="statementMetricHandle">The statement metric handle.</param>
        /// <param name="perfCollector">The perf collector.</param>
        /// <param name="observableCall">The observable call.</param>
        /// <param name="numInput">The num input.</param>
        public static void Call(this StatementMetricHandle statementMetricHandle, PerformanceCollector perfCollector, Action observableCall, int numInput = 1)
        {
            if ((MetricReportingPath.IsMetricsEnabled) && statementMetricHandle.IsEnabled)
            {
#if MONO
                long lCreationTime, lExitTime;
                long lUserTimeA, lKernelTimeA;
                long lUserTimeB, lKernelTimeB;
                //IntPtr thread = GetCurrentThread();
                long lWallTimeA = PerformanceObserverMono.NanoTime;

                //GetThreadTimes(out lUserTimeA, out lKernelTimeA);
                observableCall.Invoke();
                //GetThreadTimes(out lUserTimeB, out lKernelTimeB);

                long lWallTimeB = PerformanceObserverMono.NanoTime;
                long lTimeA     = 0; // lKernelTimeA + lUserTimeA
                long lTimeB     = 0; // lKernelTimeB + lUserTimeB

                perfCollector.Invoke(
                    metricValue,
                    100 * (lTimeB - lTimeA),
                    lWallTimeB - lWallTimeA);
#else
                FILETIME lCreationTime;
                FILETIME lExitTime;
                FILETIME lUserTimeA;
                FILETIME lKernelTimeA;
                FILETIME lUserTimeB;
                FILETIME lKernelTimeB;

                IntPtr thread     = GetCurrentThread();
                long   lWallTimeA = PerformanceObserverMono.NanoTime;

                GetThreadTimes(thread, out lCreationTime, out lExitTime, out lUserTimeA, out lKernelTimeA);
                observableCall.Invoke();
                GetThreadTimes(thread, out lCreationTime, out lExitTime, out lUserTimeB, out lKernelTimeB);

                long lWallTimeB = PerformanceObserverMono.NanoTime;

                // Calculate the time, not that the numbers represent 100-nanosecond intervals since
                // January 1, 601 (UTC).
                // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284(v=vs.85).aspx

                var kernelTimeA = (((long)lKernelTimeA.dwHighDateTime) << 32) | ((long)lKernelTimeA.dwLowDateTime);
                var kernelTimeB = (((long)lKernelTimeB.dwHighDateTime) << 32) | ((long)lKernelTimeB.dwLowDateTime);
                var userTimeA   = (((long)lUserTimeA.dwHighDateTime) << 32) | ((long)lUserTimeA.dwLowDateTime);
                var userTimeB   = (((long)lUserTimeB.dwHighDateTime) << 32) | ((long)lUserTimeB.dwLowDateTime);

                var execTimeNano = 100 * (userTimeB - userTimeA + kernelTimeB - kernelTimeA);

                perfCollector.Invoke(
                    statementMetricHandle,
                    execTimeNano,
                    lWallTimeB - lWallTimeA,
                    numInput);
#endif
            }
            else
            {
                observableCall.Invoke();
            }
        }