Advertisement
Guest User

[PATCH] Display efficiency in status

a guest
Jun 17th, 2011
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.90 KB | None | 0 0
  1. diff -upbr phoenix-1.50/ConsoleLogger.py phoenix-1.50m/ConsoleLogger.py
  2. --- phoenix-1.50/ConsoleLogger.py   2011-06-14 17:41:40.000000000 -0400
  3. +++ phoenix-1.50m/ConsoleLogger.py  2011-06-17 12:48:14.643674801 -0400
  4. @@ -22,6 +22,7 @@
  5.  import sys
  6.  from time import time
  7.  from datetime import datetime
  8. +from threading import Lock
  9.  
  10.  def formatNumber(n):
  11.      """Format a positive integer in a more readable fashion."""
  12. @@ -55,6 +56,8 @@ class ConsoleLogger(object):
  13.          self.accepted = 0
  14.          self.invalid = 0
  15.          self.lineLength = 0
  16. +        self.workCount = 0
  17. +        self.lock = Lock()
  18.          self.connectionType = None
  19.      
  20.      def reportRate(self, rate, update=True):
  21. @@ -100,48 +103,30 @@ class ConsoleLogger(object):
  22.          if self.verbose:
  23.              self.log(message)
  24.          
  25. +    def reportWork(self):
  26. +        self.workCount += 1
  27. +        
  28.      def updateStatus(self, force=False):
  29.          #only update if last update was more than a second ago
  30.          dt = time() - self.lastUpdate
  31.          if force or dt > self.UPDATE_TIME:
  32.              rate = self.rate if (not self.miner.idle) else 0
  33.              type = " [" + str(self.connectionType) + "]" if self.connectionType is not None else ''
  34. -            status = (
  35. -                "[" + formatNumber(rate) + "hash/sec] "
  36. -                "[" + str(self.accepted) + " Accepted] "
  37. -                "[" + str(self.invalid) + " Rejected]" + type)
  38. -            self.say(status)
  39. +            eff = round(float(self.accepted) / float(self.workCount) * 100.00, 2) if self.workCount is not 0 else 0
  40. +            self.say("[%shash/s] [%d ACC] [%d REJ] [%.2f%% EFF]%s", hideTimestamp=True, args=(formatNumber(rate), self.accepted, self.invalid, eff, type))
  41.              self.lastUpdate = time()
  42.          
  43. -    def say(self, message, newLine=False, hideTimestamp=False):
  44. -        #add new line if requested
  45. -        if newLine:
  46. -            message += '\n'
  47. -            if hideTimestamp:
  48. -                timestamp = ''
  49. -            else:
  50. -                timestamp = datetime.now().strftime(self.TIME_FORMAT) + ' '
  51. -                
  52. -            message = timestamp + message
  53. -        
  54. -        #erase the previous line
  55. -        if self.lineLength > 0:
  56. -            sys.stdout.write('\b \b' * self.lineLength)
  57. -            sys.stdout.write(' ' * self.lineLength)
  58. -            sys.stdout.write('\b \b' * self.lineLength)
  59. -
  60. -        #print the line
  61. -        sys.stdout.write(message)
  62. +    def say(self, message, newLine=False, hideTimestamp=False, args=()):
  63. +        with self.lock:
  64. +            if (not hideTimestamp):
  65. +                message = '%s %s' % (datetime.now().strftime(self.TIME_FORMAT), message)
  66. +            if (newLine):
  67. +                message = '%s\n' % (message)
  68. +            sys.stdout.write('\r                                                                               \r' + message % args)
  69.          sys.stdout.flush()
  70.          
  71. -        #cache the current line length
  72. -        if newLine:
  73. -            self.lineLength = 0
  74. -        else:
  75. -            self.lineLength = len(message)
  76. -
  77.      def log(self, message, update=True, hideTimestamp=False):
  78. -        self.say(message, True, hideTimestamp)
  79. +        self.say(message, newLine=True, hideTimestamp=hideTimestamp)
  80.          if update:
  81.              self.updateStatus(True)
  82.          
  83. \ No newline at end of file
  84. diff -upbr phoenix-1.50/Miner.py phoenix-1.50m/Miner.py
  85. --- phoenix-1.50/Miner.py   2011-06-14 17:41:40.000000000 -0400
  86. +++ phoenix-1.50m/Miner.py  2011-06-15 20:57:27.000000000 -0400
  87. @@ -59,6 +59,7 @@ class Miner(object):
  88.          self.logger.reportMsg(msg)
  89.      def onWork(self, work):
  90.          self.logger.reportDebug('Server gave new work; passing to WorkQueue')
  91. +        self.logger.reportWork()
  92.          self.queue.storeWork(work)
  93.      def onLongpoll(self, lp):
  94.          self.logger.reportType('RPC' + (' (+LP)' if lp else ''))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement