From 13a5807f9ee7966c973c70bdddc7b154ab2feffc Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Wed, 7 Sep 2016 11:52:29 +0000
Subject: [PATCH] Task #9607: added little performance test script

---
 .gitattributes                                |  1 +
 .../test/db_performance_test.py               | 65 +++++++++++++++++++
 2 files changed, 66 insertions(+)
 create mode 100755 LTA/ltastorageoverview/test/db_performance_test.py

diff --git a/.gitattributes b/.gitattributes
index f3226ca8f06..1566c91ee2c 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -3007,6 +3007,7 @@ LTA/ltastorageoverview/lib/webservice/templates/index.html -text
 LTA/ltastorageoverview/lib/webservice/webservice.py -text
 LTA/ltastorageoverview/ltastorageoverview_build.sh -text
 LTA/ltastorageoverview/test/CMakeLists.txt -text
+LTA/ltastorageoverview/test/db_performance_test.py -text
 LTA/ltastorageoverview/test/test_lso_webservice.py -text
 LTA/ltastorageoverview/test/test_lso_webservice.run -text
 LTA/ltastorageoverview/test/test_lso_webservice.sh -text
diff --git a/LTA/ltastorageoverview/test/db_performance_test.py b/LTA/ltastorageoverview/test/db_performance_test.py
new file mode 100755
index 00000000000..dff5bdeed0b
--- /dev/null
+++ b/LTA/ltastorageoverview/test/db_performance_test.py
@@ -0,0 +1,65 @@
+#!/usr/bin/python
+
+# Copyright (C) 2012-2015    ASTRON (Netherlands Institute for Radio Astronomy)
+# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands
+#
+# This file is part of the LOFAR software suite.
+# The LOFAR software suite is free software: you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as published
+# by the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# The LOFAR software suite is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
+
+import logging
+import time
+from datetime import datetime, timedelta
+from ltastorageoverview import store
+from lofar.common.datetimeutils import totalSeconds
+
+logger = logging.getLogger()
+
+def main():
+    from optparse import OptionParser
+    from lofar.common import dbcredentials
+
+    # Check the invocation arguments
+    parser = OptionParser("%prog [options]", description='runs the lta scraper and stores results in the speficied database.')
+    parser.add_option('-V', '--verbose', dest='verbose', action='store_true', help='verbose logging')
+    parser.add_option_group(dbcredentials.options_group(parser))
+    parser.set_defaults(dbcredentials="LTASO")
+    (options, args) = parser.parse_args()
+
+    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
+                        level=logging.DEBUG if options.verbose else logging.INFO)
+
+    dbcreds = dbcredentials.parse_options(options)
+
+    logger.info("Using dbcreds: %s" % dbcreds.stringWithHiddenPassword())
+
+    db = store.LTAStorageDb(dbcreds, options.verbose)
+    db.insertSite('siteA', 'srm://srm.siteA.nl:8444')
+    rootdir_id = db.insertRootDirectory('siteA', '/pnfs/grid.siteA.nl/data/lofar/ops/projects/lc1_001')
+
+    for obsId in range(100000, 100100):
+        obsName = 'L%s' % obsId
+
+        obsdir_id = db.insertSubDirectory(rootdir_id, '/pnfs/grid.siteA.nl/data/lofar/ops/projects/lc1_001/%s' % obsId)
+
+        now = datetime.utcnow()
+        fileinfos = [('%s_SB%3d' % (obsName, sbNr), 1234, now, obsdir_id) for sbNr in range(0, 488)]
+        now = datetime.utcnow()
+        db.insertFileInfos(fileinfos)
+        elapsed = totalSeconds(datetime.utcnow() - now)
+        print '%s,%s' % (db.numFilesInTree(rootdir_id), elapsed)
+
+
+if __name__ == "__main__":
+    main()
+
-- 
GitLab