diff --git a/opendm/system.py b/opendm/system.py index a7e20252..6da38e33 100644 --- a/opendm/system.py +++ b/opendm/system.py @@ -31,6 +31,21 @@ def now(): return datetime.datetime.now().strftime('%a %b %d %H:%M:%S %Z %Y') +def now_raw(): + return datetime.datetime.now() + + +def benchmark(start, benchmarking_file, process): + """ + runs a benchmark with a start datetime object + :return: the running time (delta) + """ + # Write to benchmark file + delta = (datetime.datetime.now() - start).total_seconds() + with open(benchmarking_file, 'a') as b: + b.write('%s runtime: %s seconds\n' % (process, delta)) + + def run_and_return(cmdSrc, cmdDest=None): """Run a system command and return the output""" process = subprocess.Popen(cmdSrc, stdout=subprocess.PIPE, shell=True) diff --git a/opendm/types.py b/opendm/types.py index e8ba490f..4e104589 100644 --- a/opendm/types.py +++ b/opendm/types.py @@ -319,6 +319,9 @@ class ODM_Tree(object): # important files paths + # benchmarking + self.benchmarking = io.join_paths(self.root_path, 'benchmark.txt') + # opensfm self.opensfm_bundle = io.join_paths(self.opensfm, 'bundle_r000.out') self.opensfm_bundle_list = io.join_paths(self.opensfm, 'list_r000.out') diff --git a/scripts/cmvs.py b/scripts/cmvs.py index 77d47484..91b7a204 100644 --- a/scripts/cmvs.py +++ b/scripts/cmvs.py @@ -21,6 +21,9 @@ class ODMCmvsCell(ecto.Cell): outputs.declare("reconstruction", "list of ODMReconstructions", []) def process(self, inputs, outputs): + + # Benchmarking + start_time = system.now_raw() log.ODM_INFO('Running OMD CMVS Cell') @@ -56,5 +59,8 @@ class ODMCmvsCell(ecto.Cell): log.ODM_WARNING('Found a valid CMVS file in: %s' % tree.pmvs_bundle) + if args['time']: + system.benchmark(start_time, tree.benchmarking, 'CMVS') + log.ODM_INFO('Running OMD CMVS Cell - Finished') return ecto.OK if args['end_with'] != 'cmvs' else ecto.QUIT diff --git a/scripts/odm_app.py b/scripts/odm_app.py index 5a61de08..8cfd172e 100644 --- a/scripts/odm_app.py +++ b/scripts/odm_app.py @@ -1,8 +1,11 @@ import ecto +import os from opendm import context from opendm import types from opendm import config +from opendm import io +from opendm import system from dataset import ODMLoadDatasetCell from resize import ODMResizeCell @@ -70,6 +73,13 @@ class ODMApp(ecto.BlackBox): tree = types.ODM_Tree(p.args['project_path']) self.tree = ecto.Constant(value=tree) + # TODO(dakota) put this somewhere better maybe + if config.args.get('time') and io.file_exists(tree.benchmarking): + # Delete the previously made file + os.remove(tree.benchmarking) + with open(tree.benchmarking, 'a') as b: + b.write('ODM Benchmarking file created %s\nNumber of Cores: %s\n\n' % (system.now(), context.num_cores)) + def connections(self, _p): # define initial task # TODO: What is this? diff --git a/scripts/odm_georeferencing.py b/scripts/odm_georeferencing.py index c1fbdf84..a3deef04 100644 --- a/scripts/odm_georeferencing.py +++ b/scripts/odm_georeferencing.py @@ -25,6 +25,8 @@ class ODMGeoreferencingCell(ecto.Cell): outputs.declare("reconstruction", "list of ODMReconstructions", []) def process(self, inputs, outputs): + # Benchmarking + start_time = system.now_raw() log.ODM_INFO('Running OMD Georeferencing Cell') @@ -139,5 +141,8 @@ class ODMGeoreferencingCell(ecto.Cell): log.ODM_WARNING('Found a valid georeferenced model in: %s' % tree.odm_georeferencing_model_ply_geo) + if args['time']: + system.benchmark(start_time, tree.benchmarking, 'Georeferencing') + log.ODM_INFO('Running OMD Georeferencing Cell - Finished') return ecto.OK if args['end_with'] != 'odm_georeferencing' else ecto.QUIT diff --git a/scripts/odm_meshing.py b/scripts/odm_meshing.py index 54575d48..24e7b214 100644 --- a/scripts/odm_meshing.py +++ b/scripts/odm_meshing.py @@ -28,6 +28,9 @@ class ODMeshingCell(ecto.Cell): def process(self, inputs, outputs): + # Benchmarking + start_time = system.now_raw() + log.ODM_INFO('Running OMD Meshing Cell') # get inputs @@ -67,5 +70,8 @@ class ODMeshingCell(ecto.Cell): log.ODM_WARNING('Found a valid ODM Mesh file in: %s' % tree.odm_mesh) + if args['time']: + system.benchmark(start_time, tree.benchmarking, 'Meshing') + log.ODM_INFO('Running OMD Meshing Cell - Finished') return ecto.OK if args['end_with'] != 'odm_meshing' else ecto.QUIT diff --git a/scripts/odm_orthophoto.py b/scripts/odm_orthophoto.py index 829305c2..c4790867 100644 --- a/scripts/odm_orthophoto.py +++ b/scripts/odm_orthophoto.py @@ -18,6 +18,9 @@ class ODMOrthoPhotoCell(ecto.Cell): def process(self, inputs, outputs): + # Benchmarking + start_time = system.now_raw() + log.ODM_INFO('Running OMD OrthoPhoto Cell') # get inputs @@ -95,5 +98,8 @@ class ODMOrthoPhotoCell(ecto.Cell): else: log.ODM_WARNING('Found a valid orthophoto in: %s' % tree.odm_orthophoto_file) + if args['time']: + system.benchmark(start_time, tree.benchmarking, 'Orthophoto') + log.ODM_INFO('Running OMD OrthoPhoto Cell - Finished') return ecto.OK if args['end_with'] != 'odm_orthophoto' else ecto.QUIT diff --git a/scripts/odm_texturing.py b/scripts/odm_texturing.py index 6c18eae5..233168d4 100644 --- a/scripts/odm_texturing.py +++ b/scripts/odm_texturing.py @@ -22,6 +22,9 @@ class ODMTexturingCell(ecto.Cell): def process(self, inputs, outputs): + # Benchmarking + start_time = system.now_raw() + log.ODM_INFO('Running OMD Texturing Cell') # get inputs @@ -66,5 +69,8 @@ class ODMTexturingCell(ecto.Cell): log.ODM_WARNING('Found a valid ODM Texture file in: %s' % tree.odm_textured_model_obj) + if args['time']: + system.benchmark(start_time, tree.benchmarking, 'Texturing') + log.ODM_INFO('Running OMD Texturing Cell - Finished') return ecto.OK if args['end_with'] != 'odm_texturing' else ecto.QUIT diff --git a/scripts/opensfm.py b/scripts/opensfm.py index 4ce3f4df..cd4551d7 100644 --- a/scripts/opensfm.py +++ b/scripts/opensfm.py @@ -23,6 +23,9 @@ class ODMOpenSfMCell(ecto.Cell): def process(self, inputs, outputs): + # Benchmarking + start_time = system.now_raw() + log.ODM_INFO('Running OMD OpenSfm Cell') # get inputs @@ -97,5 +100,8 @@ class ODMOpenSfMCell(ecto.Cell): else: log.ODM_WARNING('Found a valid CMVS file in: %s' % tree.pmvs_visdat) + if args['time']: + system.benchmark(start_time, tree.benchmarking, 'OpenSfM') + log.ODM_INFO('Running OMD OpenSfm Cell - Finished') return ecto.OK if args['end_with'] != 'opensfm' else ecto.QUIT diff --git a/scripts/pmvs.py b/scripts/pmvs.py index f4b9fe0f..0c2dc36b 100644 --- a/scripts/pmvs.py +++ b/scripts/pmvs.py @@ -34,6 +34,9 @@ class ODMPmvsCell(ecto.Cell): def process(self, inputs, outputs): + # Benchmarking + start_time = system.now_raw() + log.ODM_INFO('Running OMD PMVS Cell') # get inputs @@ -72,5 +75,8 @@ class ODMPmvsCell(ecto.Cell): else: log.ODM_WARNING('Found a valid PMVS file in %s' % tree.pmvs_model) + if args['time']: + system.benchmark(start_time, tree.benchmarking, 'PMVS') + log.ODM_INFO('Running OMD PMVS Cell - Finished') return ecto.OK if args['end_with'] != 'pmvs' else ecto.QUIT diff --git a/scripts/resize.py b/scripts/resize.py index da16c4af..17ed8bdb 100644 --- a/scripts/resize.py +++ b/scripts/resize.py @@ -20,6 +20,9 @@ class ODMResizeCell(ecto.Cell): def process(self, inputs, outputs): + # Benchmarking + start_time = system.now_raw() + log.ODM_INFO('Running ODM Resize Cell') # get inputs @@ -91,5 +94,8 @@ class ODMResizeCell(ecto.Cell): # append photos to cell output self.outputs.photos = photos + if args['time']: + system.benchmark(start_time, tree.benchmarking, 'Resizing') + log.ODM_INFO('Running ODM Resize Cell - Finished') return ecto.OK if args['end_with'] != 'resize' else ecto.QUIT