예제 #1
0
 public static void ShowBanner()
 {
     CH.Write(@"  _   _           _    ", ConsoleColor.White); CH.Write(@" ____            _     ", ConsoleColor.Green); CH.Write(@" _   ___  " + Environment.NewLine, ConsoleColor.DarkGreen);
     CH.Write(@" | | | | __ _ ___| |__ ", ConsoleColor.White); CH.Write(@"|  _ \ ___  __ _| | __ ", ConsoleColor.Green); CH.Write(@"/ | / _ \ " + Environment.NewLine, ConsoleColor.DarkGreen);
     CH.Write(@" | |_| |/ _` / __| '_ \", ConsoleColor.White); CH.Write(@"| |_) / _ \/ _` | |/ / ", ConsoleColor.Green); CH.Write(@"| || | | |   Copyright 2014" + Environment.NewLine, ConsoleColor.DarkGreen);
     CH.Write(@" |  _  | (_| \__ \ | | ", ConsoleColor.White); CH.Write(@"|  __/  __/ (_| |   <  ", ConsoleColor.Green); CH.Write(@"| || |_| |   Rickard Andersson" + Environment.NewLine, ConsoleColor.DarkGreen);
     CH.Write(@" |_| |_|\__,_|___/_| |_", ConsoleColor.White); CH.Write(@"|_|   \___|\__,_|_|\_\ ", ConsoleColor.Green); CH.Write(@"|_(_)___/ " + Environment.NewLine + Environment.NewLine, ConsoleColor.DarkGreen);
 }
예제 #2
0
        public void Run()
        {
            // Query API for version number (verifies connectivity)
            CH.Write(string.Format(" - Connecting to API on {0}:{1}... ", _host, _port), ConsoleColor.White);
            var versionResponse = Send <VersionResponse>(JsonConvert.SerializeObject(new Request {
                Command = "version"
            }));

            CH.Write("Success", ConsoleColor.Green);
            CH.Write(string.Format(" ({0})" + Environment.NewLine, versionResponse.Status[0].Description), ConsoleColor.Gray);

            // The autoDelay feature doesn't make sense when running against cgminer due to the limited API hashrate accuracy
            if (_autoDelayEnabled && versionResponse.Status[0].Description.StartsWith("cgminer"))
            {
                _autoDelayEnabled = false;
                _delay            = 20;

                CH.Write(" - Detected cgminer. Forcing delay to 20 seconds." + Environment.NewLine, ConsoleColor.White);
            }

            // Verify that we have privileged access to the API
            CH.Write(" - Verifying priviliged access to API... ", ConsoleColor.White);
            var statusResponse = Send <StatusResponse>(JsonConvert.SerializeObject(new Request {
                Command = "privileged"
            }));

            if (statusResponse.Status[0].Status == "E")
            {
                CH.Exit("Failure", statusResponse.Status[0].Msg);
            }

            CH.Write("Success" + Environment.NewLine, ConsoleColor.Green);

            // Query API for the specified GPU id
            CH.Write(string.Format(" - Looking for GPU with id {0}... ", _gpuId), ConsoleColor.White);
            var gpuResponse = Send <GpuResponse>(JsonConvert.SerializeObject(new Request {
                Command = "gpu", Parameter = _gpuId.ToString(CultureInfo.InvariantCulture)
            }));

            if (gpuResponse.Gpu == null)
            {
                CH.Exit("Failure", gpuResponse.Status[0].Msg);
            }

            CH.Write("Success", ConsoleColor.Green);
            CH.Write(string.Format(" ({0} {1}/{2})" + Environment.NewLine, gpuResponse.Gpu[0].Status, gpuResponse.Gpu[0].GpuClock, gpuResponse.Gpu[0].MemoryClock), ConsoleColor.Gray);
            _saveMemClock = gpuResponse.Gpu[0].MemoryClock;
            _saveGpuClock = gpuResponse.Gpu[0].GpuClock;

            // TODO: Only proceed if card is "Alive"?

            CH.Write(Environment.NewLine + " Starting measurements." + Environment.NewLine + Environment.NewLine, ConsoleColor.White);

            // Setup
            _logFilename = string.Format(LogFilenameFormat, _host, _gpuId, _saveMemClock, _minGpuClock, _maxGpuClock, DateTime.Now.ToString("yyyyMMdd"));
            var peakHashRate  = 0d;
            var peakGpuClock  = 0;
            var hwErrorsTally = 0;
            var peakHwErrors  = 0;

            _hashRatePoints = new PointPairList();
            _hwErrorPoints  = new PointPairList();

            // Loop through GPU engine clock range
            for (var gpuClock = _minGpuClock; gpuClock <= _maxGpuClock; gpuClock += _step)
            {
                CH.Write(string.Format(" - Setting GPU engine clock to {0}... ", gpuClock), ConsoleColor.White);
                statusResponse = Send <StatusResponse>(JsonConvert.SerializeObject(new Request {
                    Command = "gpuengine", Parameter = _gpuId + "," + gpuClock
                }));
                if (statusResponse.Status[0].Status == "E" || statusResponse.Status[0].Status == "F")
                {
                    CH.Exit("Failure", statusResponse.Status[0].Msg);
                }
                CH.Write("Success" + Environment.NewLine, ConsoleColor.Green);

                double currentHashRate;
                if (_autoDelayEnabled)
                {
                    CH.Write(" - Waiting for hashrate to stabilize... ", ConsoleColor.White);
                    currentHashRate = GetStableHashRate();
                    CH.Write("Done", ConsoleColor.Green);
                    CH.Write(string.Format(" ({0} khash/s)" + Environment.NewLine, currentHashRate), ConsoleColor.Gray);
                }
                else
                {
                    // Wait _delay seconds and then take the measurement
                    // TODO: Wait longer the first time
                    CH.Write(string.Format(" - Waiting {0} seconds for hashrate to stabilize... ", _delay), ConsoleColor.White);
                    System.Threading.Thread.Sleep(_delay * 1000);
                    CH.Write("Done", ConsoleColor.Green);

                    gpuResponse = Send <GpuResponse>(JsonConvert.SerializeObject(new Request {
                        Command = "gpu", Parameter = _gpuId.ToString(CultureInfo.InvariantCulture)
                    }));
                    if (gpuResponse.Gpu == null)
                    {
                        CH.Exit("Failure", gpuResponse.Status[0].Msg);
                    }

                    currentHashRate = gpuResponse.Gpu[0].MhsXs * 1000;
                    CH.Write(string.Format(" ({0} khash/s)" + Environment.NewLine, currentHashRate), ConsoleColor.Gray);
                }

                // Check for hashrate peak
                if (currentHashRate > peakHashRate)
                {
                    peakHashRate = currentHashRate;
                    peakGpuClock = gpuClock;
                }

                // Calculate HW errors delta and check for peak
                var hwErrorsDelta = gpuResponse.Gpu[0].HardwareErrors - hwErrorsTally;
                hwErrorsTally = gpuResponse.Gpu[0].HardwareErrors;
                if (hwErrorsDelta > peakHwErrors)
                {
                    peakHwErrors = hwErrorsDelta;
                }

                // Log to csv file
                AppendToLog(DateTime.Now, gpuResponse.Gpu[0].MemoryClock, gpuClock, currentHashRate, hwErrorsDelta);

                // Save data points for graph
                _hashRatePoints.Add(gpuClock, currentHashRate);
                _hwErrorPoints.Add(gpuClock, hwErrorsDelta);
            }

            CH.Write(string.Format(" - Measurements completed. Resetting GPU engine clock to {0}... ", _saveGpuClock), ConsoleColor.White);
            statusResponse = Send <StatusResponse>(JsonConvert.SerializeObject(new Request {
                Command = "gpuengine", Parameter = _gpuId + "," + _saveGpuClock
            }));
            if (statusResponse.Status[0].Status == "E" || statusResponse.Status[0].Status == "F")
            {
                CH.Exit("Failure", statusResponse.Status[0].Msg);
            }
            CH.Write("Success" + Environment.NewLine, ConsoleColor.Green);

            CH.Write(Environment.NewLine + string.Format("Peak of {0} khash/s detected at GPU clock {1} MHz. See {2} for details.", peakHashRate.ToString("F1"), peakGpuClock, _logFilename) + Environment.NewLine, ConsoleColor.White);

            GenerateGraph();
        }