-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPerfTools.RanRead.xml
More file actions
817 lines (701 loc) · 21.6 KB
/
PerfTools.RanRead.xml
File metadata and controls
817 lines (701 loc) · 21.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="IRIS" version="26" zv="IRIS for UNIX (Ubuntu Server LTS for ARM64 Containers) 2024.1 (Build 263U)" ts="2024-05-03 20:11:25">
<Class name="PerfTools.RanRead">
<Description>
This IRIS Data Platform tool persists random read storage IO performance statistics for analysis.
The goal of this tool is to drive as many jobs as possible to achieve target IOPS
and ensure acceptable disk response times are also sustained.
Data is stored by date and time to support queries over time.
This utility is designed to run in USER.
For more info run: do ##class(PerfTools.RanRead).Help()</Description>
<IncludeCode>%occInclude</IncludeCode>
<Super>%Persistent</Super>
<TimeChanged>66963,72343.020428592</TimeChanged>
<TimeCreated>64054,57617.929379</TimeCreated>
<Parameter name="EXPORTFILENAME">
<Default>PerfToolsRanRead_</Default>
</Parameter>
<Parameter name="FILEEXTENSION">
<Default>.txt</Default>
</Parameter>
<Parameter name="DELIM">
<Expression>$char(44)</Expression>
</Parameter>
<Parameter name="TIMEDECIMAL">
<Default>4</Default>
</Parameter>
<Property name="RunDate">
<Description>
Date this run was started
RunDate and RunTime uniquely identify a run</Description>
<Type>%Date</Type>
</Property>
<Property name="RunTime">
<Description>
Time this run was started
RunDate and RunTime uniquely identify a run</Description>
<Type>%Time</Type>
</Property>
<Property name="Batch">
<Description>
Run number</Description>
<Type>%Integer</Type>
</Property>
<Property name="Database">
<Description>
Database directory used for the random read test</Description>
<Type>%String</Type>
</Property>
<Property name="Namespace">
<Description>
Namespace used for the random write test</Description>
<Type>%String</Type>
</Property>
<Property name="Processes">
<Description>
Number of processes</Description>
<Type>%Integer</Type>
</Property>
<Property name="Job">
<Description>
Job number</Description>
<Type>%Integer</Type>
</Property>
<Property name="Reads">
<Description>
Number of reads</Description>
<Type>%Integer</Type>
</Property>
<Property name="Writes">
<Description>
Number of writes</Description>
<Type>%Integer</Type>
</Property>
<Property name="ReadsPerSec">
<Description>
Number of reads</Description>
<Type>%Integer</Type>
</Property>
<Property name="WritesPerSec">
<Description>
Number of writes</Description>
<Type>%Integer</Type>
</Property>
<Property name="ProcTime">
<Description>
Worker job runtime</Description>
<Type>%Time</Type>
</Property>
<Property name="ReadPct">
<Description>
Read pct</Description>
<Type>%Integer</Type>
</Property>
<Method name="Help">
<Description>
Display help</Description>
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
#dim str as %String
// write display title
set str=" - "
write !,"do ##class(PerfTools.RanRead).Setup(Directory,DatabaseName,SizeGB,LogLevel)"
write !,str_"Creates database and namespace with the same name. The log level must be in the range of 0 to 3, where 0 is “none” and 3 is “verbose”."
write !,"do ##class(PerfTools.RanRead).Run(Directory,Processes,RunTime in seconds)"
write !,str_"Run the random read IO test."
write !,"do ##class(PerfTools.RanRead).Stop()"
write !,str_"Terminates all background jobs."
write !,"do ##class(PerfTools.RanRead).Reset()"
write !,str_"Deletes statistics of prior runs."
write !,"do ##class(PerfTools.RanRead).Purge(Directory)"
write !,str_"Deletes namespace and database of the same name."
write !,"do ##class(PerfTools.RanRead).Export(Directory)"
write !,str_"Exports a summary of all random read test history to comma delimited text file."
]]></Implementation>
</Method>
<Method name="Run">
<Description>
Run random read test.
Prompt user for database path, processes and iterations if not passed in.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>pDirectory:%String="",pProcesses:%Integer=1,pRunTime:%Integer=300</FormalSpec>
<Implementation><![CDATA[
#dim tSC as %Status = $$$OK
#dim directory,db as %String
#dim h,date,time as %String
#dim i,batch,maxBlock,currentJobs,IOPS as %Integer
#dim respTime as %Double
try {
//Normalize directory
set directory=##class(%Library.File).NormalizeDirectory(pDirectory)
//Check if database exists
if ..IsValidDatabaseDir(directory) {
set return = $NAMESPACE
zn "%SYS"
// Find the DB associated with the directory
set Status=##Class(Config.Databases).DatabasesByDirectory("",directory,.dblist)
if '$$$ISOK(Status) {
write !,"Error="_$SYSTEM.Status.GetErrorText(Status)
return
}
//Convert database name to UPPER case
set namespace=$zconvert(dblist,"U")
set namespace=$zstrip(namespace,"<>WPC")
zn return
//Get database properties
set maxBlock=..GetBlockSize(directory)
//Each run is identified by the start date / time to keep related items together.
set h=$horolog
set date=+h
set startTime=$piece(h,",",2)
set batch=$increment(^PerfTools.RanRead("BATCH"))
write !,"RanRead process ",$JOB," creating "_pProcesses_" worker processes in the background."
//Set run flag to zero - don't start running until all jobs created
set ^PerfTools.RanRead("RUNSTATUS")=0
//For each process
for i=1:1:pProcesses {
//Job off separate processes to perform random read test
set pre = $ZCHILD
job ..RanReadJob(date,startTime,batch,directory,namespace,pProcesses,pRunTime,maxBlock,i)
set post = $ZCHILD
if (pre'=post) {
set ^PerfTools.RanRead("JOBLIST",$j,i)=post
//w !," Prepped RanWriteJob ",$ZCHILD," for parent ",$JOB," as element",i
}
}
write !,"Starting "_pProcesses_" processes for RanRead job number ",$JOB," now!"
//Start all jobs
set ^PerfTools.RanRead("RUNSTATUS")=$$$OK
write !,"To terminate run: do ##class(PerfTools.RanRead).Stop()"
write !,"Waiting to finish."
//Loop while background jobs are running
set timer=0
do {
set currentJobs=..CountJobs()
if timer>29 set timer = 0 write "."
hang 1
set timer = timer + 1
} while currentJobs>0
write !,"Random read background jobs finished for parent ",$JOB
//Get average response time
set RPS=..GetTotalReadsPerSec(batch)
write !,"RanRead job ",$JOB,"'s ",pProcesses_" processes total reads/s = "_RPS
} else {
write !,"ERROR: Directory not valid. See below for parameters."
write !,"do ##class(PerfTools.RanRead).Run(Directory,Processes,RunTime,Mode)"
}
} catch errObj {
set tSC = errObj.AsStatus()
do errObj.Log()
do $system.OBJ.DisplayError(tSC)
}
if (^PerfTools.RanRead("RUNSTATUS")='$$$OK) { // This is what Stop sets it to
if ('$SYSTEM.Process.IsProgrammerMode()) {
do $zu(4,$j,1) h 0
}
}
]]></Implementation>
</Method>
<Method name="RanReadJob">
<ClassMethod>1</ClassMethod>
<FormalSpec>pDate:%Date,pTime:%Time,pBatch:%Integer,pDirectory:%String,pNamespace:%String,pNumProcesses:%Integer,pRunTime:%Integer,pMaxBlocks:%Integer,pJobNum:%Integer</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
#dim db as %String
#dim i as %Integer
#dim startTime,endTime,elapseTime as %String
try {
//Add prefix to database directory
set db="^^"_pDirectory
set startTime=$ztimestamp
//Loop until ready to go
for i=1:1 {
//Wait one second
hang 1
//Exit wait loop when status is ok
quit:^PerfTools.RanRead("RUNSTATUS")=$$$OK
}
set reads = 0
set pIterations = 500
set start = $p(startTime,",",2)
set end = start + pRunTime
while (^PerfTools.RanRead("RUNSTATUS")'=0) {
for i=1:1:pIterations {
//Open the database using the View Buffer
open 63:db
//Use the VIEW block form to read in a random block from the database
Set pBlockNum=$random(pMaxBlocks)+1 // The +1 brings it to [1,max] rather than [0,max-1]
View pBlockNum
close 63
}
set reads = reads + pIterations
//Exit loop if time is up
quit:($p($ztimestamp,",",2) > end)
}
set endTime=$ztimestamp
set elapseTime=$p(endTime,",",2)-$p(startTime,",",2)
//Save job info
set tObj=..%New()
set tObj.RunDate=pDate
set tObj.RunTime=pTime
set tObj.Batch=pBatch
set tObj.Job=pJobNum
set tObj.Database=pDirectory
set tObj.Namespace=pNamespace
set tObj.Reads=reads
set tObj.ReadsPerSec=reads/elapseTime
set tObj.ProcTime=elapseTime
set tObj.Processes=pNumProcesses
set tObj.ReadPct=100
$$$TOE(tSC,tObj.%Save())
} catch errObj {
set tSC = errObj.AsStatus()
do errObj.Log()
do $system.OBJ.DisplayError(tSC)
}
quit tSC
]]></Implementation>
</Method>
<Method name="GetBlockSize">
<Description>
Get database block size</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>pDirectory:%String</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
//Switch to %SYS namespace
New $NAMESPACE
set $NAMESPACE="%SYS"
set db=##Class(SYS.Database).%OpenId(pDirectory)
set maxBlock=(db.Size*1024*1024)/db.BlockSize
//write !,"Database: "_db.Directory
quit maxBlock
]]></Implementation>
</Method>
<Query name="ExportSummary">
<Description>
SQL Query returns summary </Description>
<Type>%SQLQuery</Type>
<SqlQuery> SELECT RunDate,RunTime,Database,Namespace,
{fn ROUND(SUM(Reads),0)} As Reads,
{fn ROUND(SUM(Writes),0)} As Writes,
{fn ROUND(SUM(ReadsPerSec),0)} As "ReadsPS",
{fn ROUND(SUM(WritesPerSec),0)} As "WritesPS",
{fn ROUND(STDDEV_POP(Reads)/AVG(Reads),3)} As "StdDevR",
{fn ROUND(STDDEV_POP(Writes),3)} As "StdDevW",
Processes,ReadPct
FROM PerfTools.RanRead
GROUP BY Batch</SqlQuery>
</Query>
<Method name="Export">
<Description>
Export all test history to comma delimited text file</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>pDirectory:%String</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
#dim tSC as %Status = $$$OK
try {
//Check if directory exists
if ##class(%Library.File).DirectoryExists(pDirectory) {
set pathFilename=..GetPathFileName(pDirectory)
if pathFilename'="" {
write !,"Exporting summary of all random read statistics to "_pathFilename
//Open file
set file = ##class(%File).%New(pathFilename)
$$$TOE(tSC,file.Open("WNS"))
//Execute SQL query
set rs=##class(%ResultSet).%New("PerfTools.RanRead:ExportSummary")
$$$TOE(tSC,rs.Execute())
//Write the headers
set colCount=rs.GetColumnCount()
for col=1:1:colCount {
do file.Write(rs.GetColumnName(col)_..#DELIM)
set type(col)=rs.GetColumnType(col)
}
do file.WriteLine()
//Loop through all rows and write out to comma delimited txt file.
while rs.Next() {
for col=1:1:colCount {
//Get field type
set type=type(col)
set data=rs.GetData(col)
if type=2 { //DATE // region agnostic YYYY-MM-DD format
do file.Write($zdate(data,3)_..#DELIM)
} else {
if type=8 {//TIME// 24 hours HH:MM:SS format
do file.Write($ztime(data,1)_..#DELIM)
} else {
do file.Write(data_..#DELIM)
}
}
}
do file.WriteLine()
}
//Close file
do file.Close()
write !,"Done."
}
} else {
set tSC=$$$ERROR($$$DirectoryNameInvalid,"Directory="_pDirectory)
do $system.OBJ.DisplayError(tSC)
}
} catch errObj {
set tSC = errObj.AsStatus()
do errObj.Log()
do $system.OBJ.DisplayError(tSC)
}
quit tSC
]]></Implementation>
</Method>
<Method name="GetPathFileName">
<Description>
Get full directory filename for export summary txt file.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>pDirectory:%String</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
//Normalize directory
set directory=##class(%Library.File).NormalizeDirectory(pDirectory)
//Get filename
set h=$horolog
//Get date in format yyyymmdd
set date=$zdatetime(+h,8)
//Get time in format hhdd
set time=$replace($ztime($piece(h,",",2),2),":","")
set filename=..#EXPORTFILENAME_date_"-"_time_..#FILEEXTENSION
set pathFilename=##class(%File).NormalizeFilename(filename,directory)
quit pathFilename
]]></Implementation>
</Method>
<Method name="GetTotalReadsPerSec">
<Description>
Return total IOPS for specified batch run</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>pBatch:%Integer</FormalSpec>
<ReturnType>%Double</ReturnType>
<Implementation><![CDATA[
#dim total as %Integer = 0
//Get total RPS
&sql(SELECT SUM(ReadsPerSec)
INTO :total
FROM PerfTools.RanRead
WHERE Batch=:pBatch)
quit total
]]></Implementation>
</Method>
<Method name="CountJobs">
<Description>
Return number of background jobs running</Description>
<ClassMethod>1</ClassMethod>
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[
#dim job as %Integer
#dim jobCount as %Integer = 0
set key=$ORDER(^PerfTools.RanRead("JOBLIST",$j,""))
while (key'="") {
if ($DATA(^$JOB(^PerfTools.RanRead("JOBLIST",$j,key)))=1) {
set jobCount = jobCount + 1
//w !,"Job ",^PerfTools.RanRead("JOBLIST",$j,key)," still exists"
} else {
//w !,"Killing job ",^PerfTools.RanRead("JOBLIST",$j,key)
kill ^PerfTools.RanRead("JOBLIST",$j,key)
}
set key=$ORDER(^PerfTools.RanRead("JOBLIST",$j,key))
}
quit jobCount
]]></Implementation>
</Method>
<Method name="Setup">
<Description>
Create database and namespace for random read test</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>Directory:%String,Name:%String="ZRanRead",sizeGB:%Integer=1,pLogLevel:%Integer=1</FormalSpec>
<Implementation><![CDATA[
#dim tSC as %Status = $$$OK
#dim directory,freeSpace,totalSpace as %String = ""
#dim dbObj as %ObjectHandle
if $g(Name)="" quit 0
set tSC=$$$OK
Try {
set currNS=$namespace
zn "%SYS"
Set Directory = $zstrip(Directory,"<>W")
set directory=##class(%File).NormalizeDirectory(Directory)
//create resource
set Resource="%DB_"_Name
if ##class(Security.Resources).Exists(Resource)=0 {
set tSC=##class(Security.Resources).Create(Resource,"resource for "_Name,0,2)
If $$$ISERR(tSC) {
Set msg = Resource_": "_"Could not create this resource."
Set tSC = $$$ERROR($$$ObjectScriptError,msg)
Throw ##Class(%Exception.StatusException).CreateFromStatus(tSC)
}
}
if ##class(Config.Databases).Exists(Name,.oref)=1 {
set dir=$zconvert(directory,"L")
if $zconvert(oref.Directory,"L")'=dir {
Set msg = Name_": "_"Database already exists but with different directory"
Set tSC = $$$ERROR($$$ObjectScriptError,msg)
throw ##Class(%Exception.StatusException).CreateFromStatus(tSC)
}
}
else {
//create directory for the DB
set tSC = ..SetupDatabaseDirectory(directory,Name)
If $$$ISERR(tSC) {
Set msg = Directory_": "_"Could not create this directory. Please check the directory and try again."
Set tSC = $$$ERROR($$$ObjectScriptError,msg)
Throw ##Class(%Exception.StatusException).CreateFromStatus(tSC)
}
//Convert GB to MB
set sizeMB=sizeGB*1024
//Get availble free disk space in GB
$$$TOE(tSC,##class(%Library.File).GetDirectorySpace(directory,.freeSpace,.totalSpace,2))
if freeSpace<sizeGB {
write !,"ERROR: Database size ("_sizeGB_"GB) cannot be greater than available freeSpace ("_freeSpace_"GB)"
quit
}
//create the pre-expanded DB
write !,"Creating "_sizeGB_"GB database in "_directory
set dbObj=##Class(SYS.Database).%New()
set dbObj.Directory=directory
set dbObj.Size=sizeMB
$$$TOE(tSC,dbObj.%Save())
If $$$ISERR(tSC) throw ##Class(%Exception.StatusException).CreateFromStatus(tSC)
write !,"Database created in "_directory
//update cpf with DB
Set Properties("Directory") = Directory
Set tSC =##class(Config.Databases).Create(Name,.Properties)
If $$$ISERR(tSC) throw ##Class(%Exception.StatusException).CreateFromStatus(tSC)
}
//mount the db
set tSC= ##class(SYS.Database).MountDatabase(Directory)
If $$$ISERR(tSC) {
kill err
if $system.Status.GetErrorText(tSC)="ERROR #19: the file was already mounted" {
set tSC=1
}
else {
Throw ##Class(%Exception.StatusException).CreateFromStatus(tSC)
}
}
Set nsProperties("Globals") = Name
Set nsProperties("Library") = "IRISLIB"
Set nsProperties("Routines") = Name
Set nsProperties("SysGlobals") = "IRISSYS"
Set nsProperties("SysRoutines") = "IRISSYS"
Set nsProperties("TempGlobals") = "IRISTEMP"
Set tSC = ##Class(Config.Namespaces).Create(Name,.nsProperties)
if $system.Status.GetErrorText(tSC)="ERROR #419: Namespace ABCF already exists" set tSC=1
If $$$ISERR(tSC) throw ##Class(%Exception.StatusException).CreateFromStatus(tSC)
zn currNS
}
catch exp {
zn currNS
use 0 write !, exp.Name
}
zn currNS
quit tSC
]]></Implementation>
</Method>
<Method name="Purge">
<Description>
Delete database and namespace for random write test</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>pDirectory:%String,pDBname:%String="ZRanRead"</FormalSpec>
<Implementation><![CDATA[
#dim directory,dbName as %String = ""
#dim dbObj as %ObjectHandle
//Switch to %SYS namespace
New $NAMESPACE
set $NAMESPACE="%SYS"
//Normalize directory
set directory=##class(%Library.File).NormalizeDirectory(pDirectory)
//Convert database name to UPPER case
set dbName=$zconvert(pDBname,"U")
//Check if directory exists
if '(##class(%Library.File).DirectoryExists(directory)) {
w !,"Error: Directory "_directory_" does not exist!"
quit
}
//Check if database exists
if '(##Class(Config.Databases).Exists(dbName,.dbObj)) {
w !,"Error: Database "_dbName_" does not exist!"
quit
}
try {
set Status=##Class(SYS.Database).DismountDatabase(directory)
if '$$$ISOK(Status) {
write !,"Error="_$SYSTEM.Status.GetErrorText(Status)
quit
}
set Status=##Class(SYS.Database).DeleteDatabase(directory)
if '$$$ISOK(Status) {
write !,"Error="_$SYSTEM.Status.GetErrorText(Status)
quit
}
set Status=##Class(Config.Namespaces).Delete(dbName)
if '$$$ISOK(Status) {
write !,"Error="_$SYSTEM.Status.GetErrorText(Status)
quit
}
set Status=##Class(Config.Databases).Delete(dbName)
if '$$$ISOK(Status) {
write !,"Error="_$SYSTEM.Status.GetErrorText(Status)
quit
}
set args=2
set args(1)="-Rf"
set args(2)=directory
do $ZF(-100,"","rm",.args)
}
catch {}
]]></Implementation>
</Method>
<Method name="IsValidDatabaseDir">
<Description>
Return true if database directory is valid</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>pDirectory:%String</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[
#dim found as %Boolean = '$$$OK
#dim dbDir as %String
#dim rs as %ObjectHandle
//Switch to %SYS namespace
New $NAMESPACE
set $NAMESPACE="%SYS"
//If directory exists
if ##class(%Library.File).DirectoryExists(pDirectory) {
//Loop through all databases
set rs=##class(%Library.ResultSet).%New("Config.Databases:LocalDatabaseList")
do rs.Execute("*")
while rs.Next() {
set dbDir=rs.Data("Directory")
set dbDir=##class(%Library.File).NormalizeDirectory(dbDir)
//If directory exists
if pDirectory=dbDir {
set found=$$$OK
quit
}
}
}
quit found
]]></Implementation>
</Method>
<Method name="SetupDatabaseDirectory">
<Description>
Create database directory if it doesn't exist then check if a database already exists.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>pDirectory:%String,pName:%String</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[
#dim directoryOK as %Boolean = $$$OK
#dim objDB as %Object = ""
if ##class(Config.DBName).IsValid(pName) {
//If directory exists
if ##class(%Library.File).DirectoryExists(pDirectory) {
//Check if database exists
if ##Class(Config.Databases).Exists(pName,.objDB) {
write !,"ERROR: Database already exists."
set directoryOK='$$$OK
}
} else {
//Create directory
if ##class(%Library.File).CreateDirectoryChain(pDirectory) {
write !,"Created directory "_pDirectory
} else {
write !,"ERROR: Could not create directory."
set directoryOK='$$$OK
}
}
} else {
write !,"ERROR: Database name is invalid."
set directoryOK='$$$OK
}
quit directoryOK
]]></Implementation>
</Method>
<Method name="Stop">
<Description>
Set the stop flag to terminate all background jobs.</Description>
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[ set ^PerfTools.RanRead("RUNSTATUS")=0
]]></Implementation>
</Method>
<Method name="Reset">
<Description>
Delete all RanRead data</Description>
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
kill ^PerfTools.RanReadD
kill ^PerfTools.RanRead
]]></Implementation>
</Method>
<Storage name="Default">
<Type>%Storage.Persistent</Type>
<DataLocation>^PerfTools.RanReadD</DataLocation>
<DefaultData>RanReadDefaultData</DefaultData>
<IdLocation>^PerfTools.RanReadD</IdLocation>
<IndexLocation>^PerfTools.RanReadI</IndexLocation>
<StreamLocation>^PerfTools.RanReadS</StreamLocation>
<ExtentSize>10</ExtentSize>
<Data name="RanReadDefaultData">
<Value name="1">
<Value>%%CLASSNAME</Value>
</Value>
<Value name="2">
<Value>RunDate</Value>
</Value>
<Value name="3">
<Value>RunTime</Value>
</Value>
<Value name="4">
<Value>Batch</Value>
</Value>
<Value name="5">
<Value>Database</Value>
</Value>
<Value name="6">
<Value>Namespace</Value>
</Value>
<Value name="7">
<Value>Processes</Value>
</Value>
<Value name="8">
<Value>Job</Value>
</Value>
<Value name="9">
<Value>Reads</Value>
</Value>
<Value name="10">
<Value>Writes</Value>
</Value>
<Value name="11">
<Value>ReadsPerSec</Value>
</Value>
<Value name="12">
<Value>WritesPerSec</Value>
</Value>
<Value name="13">
<Value>ProcTime</Value>
</Value>
<Value name="14">
<Value>ReadPct</Value>
</Value>
</Data>
<Property name="%%CLASSNAME">
<Selectivity>100.0000%</Selectivity>
<AverageFieldSize>2</AverageFieldSize>
</Property>
<Property name="%%ID">
<Selectivity>1</Selectivity>
<AverageFieldSize>3</AverageFieldSize>
</Property>
<SQLMap name="IDKEY">
<BlockCount>-4</BlockCount>
</SQLMap>
</Storage>
</Class>
</Export>