From 6159d5e62264066a5724d7ddffffb13dd5d8f553 Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Tue, 3 Sep 2013 18:08:29 -0400 Subject: [PATCH] Show inventory lookup rate on Network Status tab --- src/bitmessageqt/__init__.py | 10 ++++++++++ src/bitmessageqt/bitmessageui.py | 14 +++++++++----- src/bitmessageqt/bitmessageui.ui | 30 +++++++++++++++++------------- src/class_receiveDataThread.py | 8 +++++++- src/shared.py | 1 + 5 files changed, 44 insertions(+), 19 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 2cdb2c97..034043c8 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -118,6 +118,10 @@ class MyForm(QtGui.QMainWindow): self.ui.labelSendBroadcastWarning.setVisible(False) + self.timer = QtCore.QTimer() + self.timer.start(2000) # milliseconds + QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"), self.runEveryTwoSeconds) + # FILE MENU and other buttons QtCore.QObject.connect(self.ui.actionExit, QtCore.SIGNAL( "triggered()"), self.quit) @@ -1292,6 +1296,12 @@ class MyForm(QtGui.QMainWindow): elif len(shared.connectedHostsList) == 0: self.setStatusIcon('red') + # timer driven + def runEveryTwoSeconds(self): + self.ui.labelLookupsPerSecond.setText(_translate( + "MainWindow", "Inventory lookups per second: %1").arg(str(shared.numberOfInventoryLookupsPerformed/2))) + shared.numberOfInventoryLookupsPerformed = 0 + # Indicates whether or not there is a connection to the Bitmessage network connected = False diff --git a/src/bitmessageqt/bitmessageui.py b/src/bitmessageqt/bitmessageui.py index 74505f38..f6a76ce1 100644 --- a/src/bitmessageqt/bitmessageui.py +++ b/src/bitmessageqt/bitmessageui.py @@ -2,8 +2,8 @@ # Form implementation generated from reading ui file 'bitmessageui.ui' # -# Created: Thu Aug 15 14:19:52 2013 -# by: PyQt4 UI code generator 4.10 +# Created: Tue Sep 03 15:17:26 2013 +# by: PyQt4 UI code generator 4.10.2 # # WARNING! All changes made in this file will be lost! @@ -430,13 +430,16 @@ class Ui_MainWindow(object): self.labelBroadcastCount = QtGui.QLabel(self.networkstatus) self.labelBroadcastCount.setGeometry(QtCore.QRect(350, 150, 351, 16)) self.labelBroadcastCount.setObjectName(_fromUtf8("labelBroadcastCount")) + self.labelLookupsPerSecond = QtGui.QLabel(self.networkstatus) + self.labelLookupsPerSecond.setGeometry(QtCore.QRect(320, 210, 291, 16)) + self.labelLookupsPerSecond.setObjectName(_fromUtf8("labelLookupsPerSecond")) icon9 = QtGui.QIcon() icon9.addPixmap(QtGui.QPixmap(_fromUtf8(":/newPrefix/images/networkstatus.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.tabWidget.addTab(self.networkstatus, icon9, _fromUtf8("")) self.gridLayout.addWidget(self.tabWidget, 0, 0, 1, 1) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtGui.QMenuBar(MainWindow) - self.menubar.setGeometry(QtCore.QRect(0, 0, 795, 23)) + self.menubar.setGeometry(QtCore.QRect(0, 0, 795, 18)) self.menubar.setObjectName(_fromUtf8("menubar")) self.menuFile = QtGui.QMenu(self.menubar) self.menuFile.setObjectName(_fromUtf8("menuFile")) @@ -554,8 +557,8 @@ class Ui_MainWindow(object): self.textEditMessage.setHtml(_translate("MainWindow", "\n" "\n" -"


", None)) +"\n" +"


", None)) self.label.setText(_translate("MainWindow", "To:", None)) self.label_2.setText(_translate("MainWindow", "From:", None)) self.radioButtonBroadcast.setText(_translate("MainWindow", "Broadcast to everyone who is subscribed to your address", None)) @@ -621,6 +624,7 @@ class Ui_MainWindow(object): self.labelMessageCount.setText(_translate("MainWindow", "Processed 0 person-to-person message.", None)) self.labelPubkeyCount.setText(_translate("MainWindow", "Processed 0 public key.", None)) self.labelBroadcastCount.setText(_translate("MainWindow", "Processed 0 broadcast.", None)) + self.labelLookupsPerSecond.setText(_translate("MainWindow", "Inventory lookups per second: 0", None)) self.tabWidget.setTabText(self.tabWidget.indexOf(self.networkstatus), _translate("MainWindow", "Network Status", None)) self.menuFile.setTitle(_translate("MainWindow", "File", None)) self.menuSettings.setTitle(_translate("MainWindow", "Settings", None)) diff --git a/src/bitmessageqt/bitmessageui.ui b/src/bitmessageqt/bitmessageui.ui index 5b597d38..a802cdac 100644 --- a/src/bitmessageqt/bitmessageui.ui +++ b/src/bitmessageqt/bitmessageui.ui @@ -22,16 +22,7 @@ - - 0 - - - 0 - - - 0 - - + 0 @@ -287,8 +278,8 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans'; font-size:9pt; font-weight:400; font-style:normal;"> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'MS Shell Dlg 2';"><br /></p></body></html> +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> @@ -1040,6 +1031,19 @@ p, li { white-space: pre-wrap; } Processed 0 broadcast. + + + + 320 + 210 + 291 + 16 + + + + Inventory lookups per second: 0 + + @@ -1051,7 +1055,7 @@ p, li { white-space: pre-wrap; } 0 0 795 - 23 + 18 diff --git a/src/class_receiveDataThread.py b/src/class_receiveDataThread.py index d04da7a6..9d35dfd2 100644 --- a/src/class_receiveDataThread.py +++ b/src/class_receiveDataThread.py @@ -173,6 +173,7 @@ class receiveDataThread(threading.Thread): self.payloadLength + 24:] # take this message out and then process the next message if self.data == '': while len(self.objectsThatWeHaveYetToCheckAndSeeWhetherWeAlreadyHave) > 0: + shared.numberOfInventoryLookupsPerformed += 1 random.seed() objectHash, = random.sample( self.objectsThatWeHaveYetToCheckAndSeeWhetherWeAlreadyHave, 1) @@ -375,6 +376,7 @@ class receiveDataThread(threading.Thread): print 'The stream number encoded in this broadcast message (' + str(streamNumber) + ') does not match the stream number on which it was received. Ignoring it.' return + shared.numberOfInventoryLookupsPerformed += 1 shared.inventoryLock.acquire() self.inventoryHash = calculateInventoryHash(data) if self.inventoryHash in shared.inventory: @@ -738,6 +740,7 @@ class receiveDataThread(threading.Thread): return readPosition += streamNumberAsClaimedByMsgLength self.inventoryHash = calculateInventoryHash(data) + shared.numberOfInventoryLookupsPerformed += 1 shared.inventoryLock.acquire() if self.inventoryHash in shared.inventory: print 'We have already received this msg message. Ignoring.' @@ -1135,6 +1138,7 @@ class receiveDataThread(threading.Thread): print 'stream number embedded in this pubkey doesn\'t match our stream number. Ignoring.' return + shared.numberOfInventoryLookupsPerformed += 1 inventoryHash = calculateInventoryHash(data) shared.inventoryLock.acquire() if inventoryHash in shared.inventory: @@ -1328,6 +1332,7 @@ class receiveDataThread(threading.Thread): return readPosition += streamNumberLength + shared.numberOfInventoryLookupsPerformed += 1 inventoryHash = calculateInventoryHash(data) shared.inventoryLock.acquire() if inventoryHash in shared.inventory: @@ -1423,6 +1428,7 @@ class receiveDataThread(threading.Thread): return self.someObjectsOfWhichThisRemoteNodeIsAlreadyAware[ data[lengthOfVarint:32 + lengthOfVarint]] = 0 + shared.numberOfInventoryLookupsPerformed += 1 if data[lengthOfVarint:32 + lengthOfVarint] in shared.inventory: with shared.printLock: print 'Inventory (in memory) has inventory item already.' @@ -1480,7 +1486,7 @@ class receiveDataThread(threading.Thread): with shared.printLock: print 'received getdata request for item:', hash.encode('hex') - # print 'inventory is', shared.inventory + shared.numberOfInventoryLookupsPerformed += 1 if hash in shared.inventory: objectType, streamNumber, payload, receivedTime = shared.inventory[ hash] diff --git a/src/shared.py b/src/shared.py index 0ff80978..25892b1d 100644 --- a/src/shared.py +++ b/src/shared.py @@ -66,6 +66,7 @@ clientHasReceivedIncomingConnections = False #used by API command clientStatus numberOfMessagesProcessed = 0 numberOfBroadcastsProcessed = 0 numberOfPubkeysProcessed = 0 +numberOfInventoryLookupsPerformed = 0 #If changed, these values will cause particularly unexpected behavior: You won't be able to either send or receive messages because the proof of work you do (or demand) won't match that done or demanded by others. Don't change them! networkDefaultProofOfWorkNonceTrialsPerByte = 320 #The amount of work that should be performed (and demanded) per byte of the payload. Double this number to double the work.