private double Measure()
        {
            var systemTime = CpuUsageNativeApi.GetSystemTime();
            var usedTime   = getCurrentUsedTime();

            if (isFirstMeasure)
            {
                sysTimePrev    = systemTime;
                usedTimePrev   = usedTime;
                isFirstMeasure = false;
                return(0);
            }

            var sysDelta  = systemTime - sysTimePrev;
            var usedDelta = usedTime - usedTimePrev;

            sysTimePrev  = systemTime;
            usedTimePrev = usedTime;

            var usage = sysDelta <= 0
                ? 0
                : Math.Max(0, Math.Min(1, usedDelta / (double)sysDelta));

            return(usage);
        }
 /// <summary>
 /// Creates <see cref="ProcessCpuUsageMeter"/> for specified process.
 /// </summary>
 public ProcessCpuUsageMeter(int pid)
 {
     handle        = ProcessUtility.OpenLimitedQueryInformationProcessHandle(pid);
     cpuUsageMeter = new CpuUsageMeter(() => CpuUsageNativeApi.GetProcessTime(handle));
 }