[Title] Show the transfer rate for file-tranferring
authordonghee yang <donghee.yang@samsung.com>
Mon, 8 Apr 2013 15:16:01 +0000 (00:16 +0900)
committerdonghee yang <donghee.yang@samsung.com>
Mon, 8 Apr 2013 15:16:01 +0000 (00:16 +0900)
src/common/FileTransferViaDirect.rb

index 744c6f60cd2d060da0273e12cf999897bce25dca..4f78222f07884c101a05fb8c7ed5e4f1843eb131 100644 (file)
@@ -64,6 +64,7 @@ class FileTransferDirect
                                old_progress = 0
                                # read file contents
                                # send via tcp/ip
+                               trBegin = Time.now()
                                File.open(src_file, "rb") do |io|
                                        while size > 0
                                                buf = io.read(size > 1024*1024 ? 1024*1024 : size)
@@ -77,8 +78,9 @@ class FileTransferDirect
                                                end
                                        end
                                end
-
-                               @log.info "Upload is succeeded!"
+                               trEnd = Time.now()
+                               trRate = (full_size * 1000 / (trEnd - trBegin) / 1000).to_i
+                               @log.info "Upload is succeeded! #{trRate}KByte/s"
                                conn.puts "SEND_OK"
 
                                # wait for download result
@@ -114,12 +116,14 @@ class FileTransferDirect
                                @log.info "Received file info from remote site"
                                filename = tok[1].strip
                                size = tok[2].strip.to_i
+                               full_size = size
                                checksum = tok[3].strip
 
                                if File.directory? dst_file then
                                        dst_file = File.join(dst_file, filename)
                                end
 
+                               trBegin = Time.now()
                                File.open( dst_file, "wb" ) do  |io|
                                        while size > 0
                                                buf = conn.read(size > 1024*1024 ? 1024*1024 : size)
@@ -131,6 +135,9 @@ class FileTransferDirect
                                                size -= buf.length
                                        end
                                end
+                               trEnd = Time.now()
+                               trRate = (full_size * 1000 / (trEnd - trBegin) / 1000).to_i
+                               @log.info "Download is succeeded! #{trRate}KByte/s"
 
                                conn.puts "RECEIVE_OK"