瀏覽代碼

Improvements on PascalCoinMiner

PascalCoin 4 年之前
父節點
當前提交
10b1daf0b4
共有 3 個文件被更改,包括 41 次插入20 次删除
  1. 5 7
      src/core/UPoolMinerThreads.pas
  2. 6 1
      src/core/UTCPIP.pas
  3. 30 12
      src/pascalcoin_miner.pp

+ 5 - 7
src/core/UPoolMinerThreads.pas

@@ -36,10 +36,11 @@ type
     WorkingMillisecondsTotal : Cardinal;
     WinsCount : Integer;
     Invalids : Integer;
+    InternalComputingRounds : Integer;
   End;
 
 Const
-  CT_TMinerStats_NULL : TMinerStats = (Miners:0;RoundsCount:0;WorkingMillisecondsHashing:0;WorkingMillisecondsTotal:0;WinsCount:0;Invalids:0);
+  CT_TMinerStats_NULL : TMinerStats = (Miners:0;RoundsCount:0;WorkingMillisecondsHashing:0;WorkingMillisecondsTotal:0;WinsCount:0;Invalids:0;InternalComputingRounds:0);
 
 Type
 
@@ -626,11 +627,6 @@ begin
 end;
 
 procedure TCustomMinerDeviceThread.UpdateDeviceStats(Stats: TMinerStats);
-Type TTimeMinerStats = Record
-       tc : Cardinal;
-       stats : TMinerStats;
-     end;
-  PTimeMinerStats = ^TTimeMinerStats;
 Var l : TList<Pointer>;
   i : Integer;
   P : PTimeMinerStats;
@@ -657,6 +653,7 @@ begin
         if ((stats.Miners>foundMaxMiners)) then foundMaxMiners := stats.Miners;
       end;
     end;
+    FPartialDeviceStats.InternalComputingRounds:=l.count;
     If l.count>0 then begin
       P := PTimeMinerStats(l[l.count-1]);
       FPartialDeviceStats.WorkingMillisecondsHashing:=P^.tc - PTimeMinerStats(l[0]).tc + P^.stats.WorkingMillisecondsHashing;
@@ -863,7 +860,7 @@ begin
             if FCurrentMinerValuesForWork.version < CT_PROTOCOL_5 then
               roundsToDo := 20
             else
-              roundsToDo := 200+Random(200);
+              roundsToDo := 100+Random(100);
           end else begin
             roundsToDo := 10000;
           end;
@@ -982,6 +979,7 @@ begin
               finalHashingTC:=TPlatform.GetTickCount;
             end;
             AuxStats.Miners:=FCPUDeviceThread.FCPUs;
+            AuxStats.InternalComputingRounds:=roundsToDo;
             AuxStats.RoundsCount:=LRoundsPerformed;
             AuxStats.WorkingMillisecondsTotal:=TPlatform.GetTickCount - baseRealTC;
             AuxStats.WorkingMillisecondsHashing:= finalHashingTC - baseHashingTC;

+ 6 - 1
src/core/UTCPIP.pas

@@ -333,7 +333,12 @@ end;
 
 destructor TNetTcpIpClient.Destroy;
 begin
-  Disconnect;
+  FLock.Acquire;
+  try
+    Disconnect;
+  finally
+    FLock.Release;
+  end;
   {$IFDEF Synapse}  // Memory leak on 1.5.0
   FreeAndNil(FSendBufferLock);
   {$ENDIF}

+ 30 - 12
src/pascalcoin_miner.pp

@@ -27,8 +27,7 @@ uses
   UBlockChain, UPoolMinerThreads, UGPUMining,
   UPoolMining, ULog, UThread, UAccounts, UCrypto,
   UConst, UTime, UNode, UNetProtocol, USha256,
-  UOpenSSL, UBaseTypes, UCommon,
-  DelphiCL;
+  UOpenSSL, UBaseTypes, UCommon, DelphiCL;
 
 type
 
@@ -44,6 +43,7 @@ type
     procedure WriteLine(nline : Integer; txt : String);
     procedure OnInThreadNewLog(logtype : TLogType; Time : TDateTime; ThreadID : TThreadID; Const sender, logtext : AnsiString);
   protected
+    FOutputAsLogs : Boolean;
     FWindow32X1,FWindow32Y1,FWindow32X2,FWindow32Y2: DWord;
     FLock : TCriticalSection;
     FPoolMinerThread : TPoolMinerThread;
@@ -100,7 +100,6 @@ begin
 end;
 
 procedure TPascalMinerApp.OnConnectionStateChanged(Sender: TObject);
-Const CT_state : Array[boolean] of String = ('Disconnected','Connected');
 var i : Integer;
   s : String;
 begin
@@ -120,8 +119,6 @@ begin
 end;
 
 procedure TPascalMinerApp.OnDeviceStateChanged(Sender: TObject);
-Var i : Integer;
-  s : String;
 begin
   If Sender is TCustomMinerDeviceThread then begin
     If TCustomMinerDeviceThread(Sender).IsMining then WriteLine(CT_Line_DeviceStatus,'') // clear line
@@ -153,6 +150,10 @@ Var i : Integer;
 begin
   FLock.Acquire;
   try
+    if FOutputAsLogs then begin
+      WriteLn(Format('%s %s',[FormatDateTime('hh:nn:ss.zzz',Now()),txt]));
+      Exit;
+    end;
     i := length(txt);
     if i<=(FWindow32X2-FWindow32X1+1) then begin
       setlength(txt,FWindow32X2-FWindow32X1+1);
@@ -280,9 +281,9 @@ var
   end;
 
   Procedure DoWaitAndLog;
-  Var tc : TTickCount;
+  Var tc, LMaxElapsed : TTickCount;
     gs,ms : TMinerStats;
-    hrReal,hrHashing, glhrHashing, glhrReal : Real;
+    hrHashing  : Real;
     i : Integer;
     devt : TCustomMinerDeviceThread;
     s : String;
@@ -297,7 +298,9 @@ var
       end;
       while (Not Terminated) do begin
         sleep(100);
-        If TPlatform.GetElapsedMilliseconds(tc)>1000 then begin
+        if FOutputAsLogs then LMaxElapsed := 10000
+        else LMaxElapsed:=1000;
+        If TPlatform.GetElapsedMilliseconds(tc)>LMaxElapsed then begin
           tc := TPlatform.GetTickCount;
           For i:=0 to FDeviceThreads.Count-1 do begin
             devt := TCustomMinerDeviceThread(FDeviceThreads[i]);
@@ -307,7 +310,7 @@ var
               else hrHashing := 0;
               gs := devt.GlobalDeviceStats;
               If ms.RoundsCount>0 then begin
-                s := FormatDateTime('hh:nn:ss',now)+Format(' Miner:"%s" at %0.1f H/s - Rounds: %0.2f K Found: %d',[devt.MinerValuesForWork.payload_start.ToString,hrHashing, gs.RoundsCount/1000, gs.WinsCount]);
+                s := FormatDateTime('hh:nn:ss',now)+Format(' Miner:"%s" at %0.1f H/s (%d %0.2f) - Rounds: %0.2f K Found: %d',[devt.MinerValuesForWork.payload_start.ToString,hrHashing, ms.InternalComputingRounds, ms.RoundsCount/1000, gs.RoundsCount/1000, gs.WinsCount]);
                 If (gs.Invalids>0) then s := s +' '+inttostr(gs.Invalids)+' ERRORS!';
                 WriteLine(CT_Line_MiningStatus+i,s);
               end else begin
@@ -427,7 +430,7 @@ begin
   FLock := TCriticalSection.Create;
   Try
     // quick check parameters
-    ErrorMsg:=CheckOptions('hp:d:s::c:n::t:u::x::l::', 'help platform device server cpu minername testmode user pwd logfile logall');
+    ErrorMsg:=CheckOptions('hp:d:s::c:n::t:u::x::l::', 'help platform: device: server: cpu: minername: testmode: user: pwd: logfile: logall: outputlogs:');
     if ErrorMsg<>'' then begin
       //ShowException(Exception.Create(ErrorMsg));
       WriteLn(ErrorMsg);
@@ -440,10 +443,19 @@ begin
       Exit;
     end;
 
-    if (Not HasOption('p','platform')) And (Not HasOption('d','device')) And (Not HasOption('c','cpu:')) then begin
+    if HasOption('outputlogs') then begin
+      s := Trim(GetOptionValue('outputlogs'));
+      if (s='0') or (s='false') then FOutputAsLogs:=False
+      else if (s='1') or (s='-1') or (s='true') then FOutputAsLogs:=True
+      else begin
+        Writeln('Invalid outputlogs argument "'+s+'"');
+        Exit;
+      end;
+    end;
+
+    if (Not HasOption('p','platform')) And (Not HasOption('d','device')) And (Not HasOption('c','cpu')) then begin
       Writeln('Need to specify -p X and -d Y for GPU mining or -c N for CPU mining');
       Writeln('Execute ',ExtractFileName(ExeName),' -h for more info');
-      ShowGPUDrivers;
       Exit;
     end;
 
@@ -511,6 +523,11 @@ begin
   FDeviceThreads := TList.Create;
   StopOnException:=True;
   FAppStartTime := Now;
+  {$IF Defined(WINDOWS)}
+  FOutputAsLogs := False;
+  {$ELSE}
+  FOutputAsLogs := True;
+  {$ENDIF}
 end;
 
 destructor TPascalMinerApp.Destroy;
@@ -537,6 +554,7 @@ begin
   writeln('  (Not needed for PascalCoin core, only some third party pools)');
   writeln('  -u USERNAME');
   writeln('  -x PASSWORD');
+  writeln('  --outputlogs=BOOLEAN (Show output style as a log)');
   writeln('');
   writeln('Basic example GPU mining over multiple devices: ');
   writeln('  ',ExtractFileName(ExeName),' -p 0 -d 0,1,2,3 -s -n ABC');