Mercurial > hg > orthanc-tests
annotate PerfsDb/Run.py @ 611:09fc76fbd46d
Added tag Orthanc-1.12.3 for changeset ec657d1a62a6
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 31 Jan 2024 13:51:40 +0100 |
parents | 29cb1ee97035 |
children |
rev | line source |
---|---|
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
1 import argparse |
160 | 2 import fnmatch |
164 | 3 import csv |
4 import datetime | |
5 import os | |
160 | 6 |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
7 from ConfigFileBuilder import ConfigFileBuilder |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
8 from TestConfig import TestConfig |
160 | 9 from Tests import * |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
10 from DbServer import DbServer |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
11 from DbType import DbType |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
12 from DbSize import DbSize |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
13 |
160 | 14 |
15 allTestConfigs = [ | |
16 TestConfig(label= "mysql-small", dbSize=DbSize.Small, dbServer=DbServer(dbType=DbType.MySQL, port=2000)), | |
17 TestConfig(label= "pg9-small", dbSize=DbSize.Small, dbServer=DbServer(dbType=DbType.PG9, port=2001)), | |
196 | 18 TestConfig(label= "pg9bis-small", dbSize=DbSize.Small, dbServer=DbServer(dbType=DbType.PG9, port=2011)), |
160 | 19 TestConfig(label= "pg10-small", dbSize=DbSize.Small, dbServer=DbServer(dbType=DbType.PG10, port=2002)), |
20 TestConfig(label= "pg11-small", dbSize=DbSize.Small, dbServer=DbServer(dbType=DbType.PG11, port=2003)), | |
21 TestConfig(label= "mssql-small", dbSize=DbSize.Small, dbServer=DbServer(dbType=DbType.MSSQL, port=2004)), | |
22 TestConfig(label= "sqlite-small", dbSize=DbSize.Small, dbType=DbType.Sqlite), | |
23 TestConfig(label= "sqliteplugin-small", dbSize=DbSize.Small, dbType=DbType.SqlitePlugin), | |
24 | |
25 TestConfig(label= "mysql-tiny", dbSize=DbSize.Tiny, dbServer=DbServer(dbType=DbType.MySQL, port=3000)), | |
26 TestConfig(label= "pg9-tiny", dbSize=DbSize.Tiny, dbServer=DbServer(dbType=DbType.PG9, port=3001)), | |
196 | 27 TestConfig(label= "pg9bis-tiny", dbSize=DbSize.Tiny, dbServer=DbServer(dbType=DbType.PG9, port=3011)), |
160 | 28 TestConfig(label= "pg10-tiny", dbSize=DbSize.Tiny, dbServer=DbServer(dbType=DbType.PG10, port=3002)), |
29 TestConfig(label= "pg11-tiny", dbSize=DbSize.Tiny, dbServer=DbServer(dbType=DbType.PG11, port=3003)), | |
30 TestConfig(label= "mssql-tiny", dbSize=DbSize.Tiny, dbServer=DbServer(dbType=DbType.MSSQL, port=3004)), | |
31 TestConfig(label= "sqlite-tiny", dbSize=DbSize.Tiny, dbType=DbType.Sqlite), | |
32 TestConfig(label= "sqliteplugin-tiny", dbSize=DbSize.Tiny, dbType=DbType.SqlitePlugin), | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
33 |
160 | 34 TestConfig(label= "mysql-medium", dbSize=DbSize.Medium, dbServer=DbServer(dbType=DbType.MySQL, port=4000)), |
35 TestConfig(label= "pg9-medium", dbSize=DbSize.Medium, dbServer=DbServer(dbType=DbType.PG9, port=4001)), | |
36 TestConfig(label= "pg10-medium", dbSize=DbSize.Medium, dbServer=DbServer(dbType=DbType.PG10, port=4002)), | |
37 TestConfig(label= "pg11-medium", dbSize=DbSize.Medium, dbServer=DbServer(dbType=DbType.PG11, port=4003)), | |
38 TestConfig(label= "mssql-medium", dbSize=DbSize.Medium, dbServer=DbServer(dbType=DbType.MSSQL, port=4004)), | |
39 TestConfig(label= "sqlite-medium", dbSize=DbSize.Medium, dbType=DbType.Sqlite), | |
40 TestConfig(label= "sqliteplugin-medium", dbSize=DbSize.Medium, dbType=DbType.SqlitePlugin), | |
161 | 41 |
42 TestConfig(label= "mysql-large", dbSize=DbSize.Large, dbServer=DbServer(dbType=DbType.MySQL, port=5000)), | |
43 TestConfig(label= "pg9-large", dbSize=DbSize.Large, dbServer=DbServer(dbType=DbType.PG9, port=5001)), | |
44 TestConfig(label= "pg10-large", dbSize=DbSize.Large, dbServer=DbServer(dbType=DbType.PG10, port=5002)), | |
45 TestConfig(label= "pg11-large", dbSize=DbSize.Large, dbServer=DbServer(dbType=DbType.PG11, port=5003)), | |
46 TestConfig(label= "mssql-large", dbSize=DbSize.Large, dbServer=DbServer(dbType=DbType.MSSQL, port=5004)), | |
47 TestConfig(label= "sqlite-large", dbSize=DbSize.Large, dbType=DbType.Sqlite), | |
48 TestConfig(label= "sqliteplugin-large", dbSize=DbSize.Large, dbType=DbType.SqlitePlugin), | |
160 | 49 ] |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
50 |
160 | 51 allTests = [ |
52 TestStatistics(), | |
53 TestFindStudyByStudyDescription1Result(), | |
54 TestFindStudyByPatientId1Result(), | |
55 TestFindStudyByStudyDescription0Results(), | |
56 TestFindStudyByPatientId0Results(), | |
57 TestFindStudyByPatientId5Results(), | |
165 | 58 TestFindStudyByPatientId100Results(), |
161 | 59 TestUploadNextPatientFile(), |
60 TestUploadFirstPatientFile(), | |
162 | 61 TestUploadLargeFile10MB(), |
62 TestToolsFindStudyByStudyInstanceUID(), | |
63 TestToolsFindPatientByPatientID() | |
160 | 64 ] |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
65 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
66 selectedTestConfigs = [] |
160 | 67 selectedTests = [] |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
68 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
69 parser = argparse.ArgumentParser(description = "Initializes/Runs/Clears PerfsDb setup.") |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
70 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
71 # create a cli option for each config |
160 | 72 for testConfig in allTestConfigs: |
73 parser.add_argument("--" + testConfig.label, action = "store_true") | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
74 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
75 parser.add_argument("--init", help = "initializes DBs", action = "store_true") |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
76 parser.add_argument("--run", help = "runs tests", action = "store_true") |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
77 parser.add_argument("--clear", help = "clear DBs", action = "store_true") |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
78 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
79 parser.add_argument("--orthanc-path", help = "path to the folder containing Orthanc executable", default=".") |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
80 parser.add_argument("--plugins-path", help = "path to the folder containing Orthanc executable", default=".") |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
81 parser.add_argument("--repeat", help = "number of times to repeat each test to average timings", type=int, default=50) |
160 | 82 parser.add_argument("--test-filter", help = "filter tests by names (wildcards are allowed)", default="*") |
161 | 83 parser.add_argument("--verbose", help = "start Orthanc in verbose mode", action = "store_true") |
84 parser.add_argument("--trace", help = "start Orthanc in trace mode", action = "store_true") | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
85 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
86 args = parser.parse_args() |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
87 |
160 | 88 for testConfig in allTestConfigs: |
89 if args.__dict__[testConfig.label.replace("-", "_")]: | |
90 selectedTestConfigs.append(testConfig) | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
91 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
92 # if no test config specified, take them all |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
93 if len(selectedTestConfigs) == 0: |
160 | 94 selectedTestConfigs = allTestConfigs |
95 | |
96 selectedTestConfigs.sort(key=lambda x: x.label) | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
97 |
160 | 98 # filter tests |
99 for test in allTests: | |
100 if fnmatch.fnmatch(test.name, args.test_filter): | |
101 selectedTests.append(test) | |
102 | |
103 selectedTests.sort(key=lambda x: x.name) | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
104 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
105 # if no action specified, it means only run |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
106 if not (args.init | args.run | args.clear): |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
107 args.init = False |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
108 args.run = True |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
109 args.clear = False |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
110 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
111 print("***** Orthanc *******") |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
112 print("path :", args.orthanc_path) |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
113 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
114 results = {} |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
115 |
160 | 116 for testConfig in selectedTestConfigs: |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
117 testConfig.setRepeatCount(args.repeat) |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
118 |
160 | 119 print("======= " + testConfig.label + " ========") |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
120 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
121 if args.clear: |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
122 print("** Clearing Db") |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
123 testConfig.clearDb() |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
124 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
125 if args.init or args.run: |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
126 print("** Generating config files") |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
127 testConfig.generateOrthancConfigurationFile(args.plugins_path) |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
128 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
129 print("** Launching DbServer") |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
130 testConfig.launchDbServer() |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
131 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
132 print("** Launching Orthanc") |
161 | 133 orthancWasAlreadyRunning = not testConfig.launchOrthanc(args.orthanc_path, verboseEnabled=args.verbose, traceEnabled=args.trace) |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
134 if orthancWasAlreadyRunning and len(selectedTestConfigs) > 1: |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
135 print("Error: Can't execute multiple configuration on already running Orthanc. Exit Orthanc and let this script start Orthanc instances") |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
136 exit(-1) |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
137 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
138 if args.init: |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
139 testConfig.initializeDb() |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
140 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
141 if args.run: |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
142 print("** Runnnig tests") |
160 | 143 results[testConfig.label] = testConfig.runTests(selectedTests) |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
144 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
145 print("** Stopping Orthanc") |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
146 testConfig.stopOrthanc() |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
147 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
148 print("++++++++++++++ results summary +++++++++++++++") |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
149 testNames = set() |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
150 resultsByTestName = {} |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
151 for configName, configResult in results.items(): |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
152 for result in configResult: |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
153 testNames.add(result.name) |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
154 if not result.name in resultsByTestName: |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
155 resultsByTestName[result.name] = {} |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
156 resultsByTestName[result.name][configName] = result |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
157 |
164 | 158 resultFileName = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Results/run-" + datetime.datetime.now().strftime("%Y.%m.%d.%H.%M.%S")) |
159 | |
160 with open(resultFileName, 'w', newline='') as resultFile: | |
161 resultWriter = csv.writer(resultFile) | |
162 resultHeaderRow = [""] | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
163 |
164 | 164 headerLine = "{empty:<40}|".format(empty="") |
165 | |
166 for testConfig in selectedTestConfigs: | |
167 headerLine += "{configName:^15}|".format(configName=testConfig.label) | |
168 resultHeaderRow.append(configName) | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
169 |
164 | 170 print(headerLine) |
171 resultWriter.writerow(resultHeaderRow) | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
diff
changeset
|
172 |
164 | 173 for testName in sorted(testNames): |
174 resultLine = "{name:<40}|".format(name=testName) | |
175 resultRow=[testName] | |
176 | |
177 for testConfig in selectedTestConfigs: | |
178 resultLine += "{avg:>11.2f} ms |".format(avg = resultsByTestName[testName][testConfig.label].averageTimeInMs) | |
179 resultRow.append(resultsByTestName[testName][testConfig.label].averageTimeInMs) | |
180 | |
181 print(resultLine) | |
182 resultWriter.writerow(resultRow) | |
183 | |
184 print("** Done; results saved in " + resultFileName) |