[Piglit] [PATCH] piglit-run.py: Remove SyncFileWriter as it's not necessary with JSON.

Kenneth Graunke kenneth at whitecape.org
Wed Aug 3 12:09:53 PDT 2011


Prior to JSON-ification, piglit wrote each test's results in a single
call, and SyncFileWriter ensured that these were done sequentially.

Now, the JSON writer internally handles locking and concurrency, so
SyncFileWriter is unnecessary.  Furthermore, outputting a single test's
results now takes multiple write calls, so SyncFileWriter wouldn't actually
guard against concurrency issues anyway.

This also removes a fsync() call on each write, fixing a major
performance regression on machines with non-SSDs.  Prior to the JSON
work, since each test mapped to a single write call, we were doing one
fsync() per test case.  With JSON, we started doing many more fsyncs.
But none of them are actually necessary, so just scrap them all.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=39737
Cc: Chad Versace <chad at chad-versace.us>
Cc: Ian Romanick <idr at freedesktop.org>
Cc: Dave Airlie <airlied at gmail.com>
Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 piglit-run.py |   34 ++--------------------------------
 1 files changed, 2 insertions(+), 32 deletions(-)

diff --git a/piglit-run.py b/piglit-run.py
index bbc3807..c5f5a4a 100755
--- a/piglit-run.py
+++ b/piglit-run.py
@@ -32,37 +32,6 @@ import traceback
 import framework.core as core
 from framework.threads import synchronized_self
 
-class SyncFileWriter:
-	'''
-		Using the 'print' syntax to write to an instance of this class
-		may have unexpected results in a multithreaded program.  For example:
-			print >> file, "a", "b", "c"
-		will call write() to write "a", then call write() to write "b", and so on...
-		This type of execution allows for another thread to call write() before
-		the original statement completes its execution.
-		To avoid this behavior, call file.write() explicitly.  For example:
-			file.write("a", "b", "c", "\n")
-		will ensure that "a b c" gets written to the file before any other thread
-		is given write access.
-	'''
-	def __init__(self, filename):
-		self.file = open(filename, 'w')
-
-	@synchronized_self
-	def write(self, *args):
-		[self.file.write(str(a)) for a in args]
-		self.file.flush()
-		os.fsync(self.file.fileno())
-
-	@synchronized_self
-	def writeLine(self, *args):
-		self.write(*args)
-		self.write('\n')
-
-	@synchronized_self
-	def close(self):
-		self.file.close()
-
 #############################################################################
 ##### Main program
 #############################################################################
@@ -149,7 +118,8 @@ def main():
 
 	# Begin json.
 	result_filepath = os.path.join(resultsDir, 'main')
-	json_writer = core.JSONWriter(SyncFileWriter(result_filepath))
+	result_file = open(result_filepath, 'w')
+	json_writer = core.JSONWriter(result_file)
 	json_writer.open_dict()
 
 	json_writer.write_dict_item('name', results.name)
-- 
1.7.6



More information about the Piglit mailing list