-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1
executable file
·2594 lines (2480 loc) · 110 KB
/
1
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
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "Util.hpp"
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
string total_comp[]={"ul","um","uh","bl","bm","bh"};
bool initialized=false; //indicates wether user has connected to DB or not
void initDB(string data_set_host,string data_set,string user_name,string user_pass){
//Initiates connection to DB
/* Create a connection */
try{
driver = get_driver_instance();
con = driver->connect(data_set_host, user_name, user_pass);
/* Connect to the MySQL test database */
con->setSchema(data_set);
initialized=true;
srand(time(0));
}
catch(sql::InvalidArgumentException &e) {
cout << "#\t Invalid Argument: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
catch (sql::MethodNotImplementedException &e){
cout << "#\t Not implemented: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
catch (sql::SQLException &e){
/*
The MySQL Connector/C++ throws three different exceptions:
- sql::MethodNotImplementedException (derived from sql::SQLException)
- sql::InvalidArgumentException (derived from sql::SQLException)
- sql::SQLException (derived from std::runtime_error)
sql::SQLException is the base class.
*/
cout << endl;
cout << "# ERR: DbcException in " << __FILE__;
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
/* Use what(), getErrorCode() and getSQLState() */
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
if (e.getErrorCode() == 1047) {
/*
Error: 1047 SQLSTATE: 08S01 (ER_UNKNOWN_COM_ERROR)
Message: Unknown command
*/
cout << "# ERR: Your server seems not to support PS at all because its MYSQL <4.1" << endl;
}
cout << "not ok 1 - examples/exceptions.cpp" << endl;
}
catch (std::runtime_error &e) {
cout << endl;
cout << "# ERR: runtime_error in " << __FILE__;
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
cout << "# ERR: " << e.what() << endl;
cout << "not ok 1 - examples/exceptions.cpp" << endl;
}
catch(exception e){
cout<<"Exception in initDB():"<<e.what()<<endl;
}
}
void endDB(){
//Deletes connection to DB and deletes parameters
try{
delete stmt;
delete con;
initialized=false;
}
catch(sql::InvalidArgumentException &e) {
cout << "#\t Invalid Argument: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
catch (sql::MethodNotImplementedException &e){
cout << "#\t Not implemented: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
catch (sql::SQLException &e){
/*
The MySQL Connector/C++ throws three different exceptions:
- sql::MethodNotImplementedException (derived from sql::SQLException)
- sql::InvalidArgumentException (derived from sql::SQLException)
- sql::SQLException (derived from std::runtime_error)
sql::SQLException is the base class.
*/
cout << endl;
cout << "# ERR: DbcException in " << __FILE__;
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
/* Use what(), getErrorCode() and getSQLState() */
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
if (e.getErrorCode() == 1047) {
/*
Error: 1047 SQLSTATE: 08S01 (ER_UNKNOWN_COM_ERROR)
Message: Unknown command
*/
cout << "# ERR: Your server seems not to support PS at all because its MYSQL <4.1" << endl;
}
cout << "not ok 1 - examples/exceptions.cpp" << endl;
}
catch (std::runtime_error &e) {
cout << endl;
cout << "# ERR: runtime_error in " << __FILE__;
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
cout << "# ERR: " << e.what() << endl;
cout << "not ok 1 - examples/exceptions.cpp" << endl;
}
catch(exception e){
cout<<"Exception in endDB():"<<e.what()<<endl;
}
}
int comp_dist(string s){
//Checks required total transactions length distribution
try{
int siz=sizeof(total_comp)/sizeof(total_comp[0]);
for(int i=0;i<siz;i++){
if(!total_comp[i].compare(s)){
//String exists. Return 1
return 1;
}
}
//String does not exist
return 0;
}
catch(sql::InvalidArgumentException &e) {
cout << "#\t Invalid Argument: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
catch (sql::MethodNotImplementedException &e){
cout << "#\t Not implemented: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
catch (sql::SQLException &e){
/*
The MySQL Connector/C++ throws three different exceptions:
- sql::MethodNotImplementedException (derived from sql::SQLException)
- sql::InvalidArgumentException (derived from sql::SQLException)
- sql::SQLException (derived from std::runtime_error)
sql::SQLException is the base class.
*/
cout << endl;
cout << "# ERR: DbcException in " << __FILE__;
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
/* Use what(), getErrorCode() and getSQLState() */
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
if (e.getErrorCode() == 1047) {
/*
Error: 1047 SQLSTATE: 08S01 (ER_UNKNOWN_COM_ERROR)
Message: Unknown command
*/
cout << "# ERR: Your server seems not to support PS at all because its MYSQL <4.1" << endl;
}
cout << "not ok 1 - examples/exceptions.cpp" << endl;
}
catch (std::runtime_error &e) {
cout << endl;
cout << "# ERR: runtime_error in " << __FILE__;
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
cout << "# ERR: " << e.what() << endl;
cout << "not ok 1 - examples/exceptions.cpp" << endl;
}
catch(exception e){
cout<<"Exception in comp_dist():"<<e.what()<<endl;
}
}
vector<double> selectPeriod(int hyperperiod){
//Returns all available periods that are devisors of hyperperiod and lying between the specified
//period limits
try{
int period[]={10000,100000}; //min and max period values in micro_sec
//the next element is 0 or 1. 1 means the value is included in interval, 0 means the reverse
return findDevisors(hyperperiod,period[0],period[1]);
}
catch(sql::InvalidArgumentException &e) {
cout << "#\t Invalid Argument: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
catch (sql::MethodNotImplementedException &e){
cout << "#\t Not implemented: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
catch (sql::SQLException &e){
/*
The MySQL Connector/C++ throws three different exceptions:
- sql::MethodNotImplementedException (derived from sql::SQLException)
- sql::InvalidArgumentException (derived from sql::SQLException)
- sql::SQLException (derived from std::runtime_error)
sql::SQLException is the base class.
*/
cout << endl;
cout << "# ERR: DbcException in " << __FILE__;
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
/* Use what(), getErrorCode() and getSQLState() */
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
if (e.getErrorCode() == 1047) {
/*
Error: 1047 SQLSTATE: 08S01 (ER_UNKNOWN_COM_ERROR)
Message: Unknown command
*/
cout << "# ERR: Your server seems not to support PS at all because its MYSQL <4.1" << endl;
}
cout << "not ok 1 - examples/exceptions.cpp" << endl;
}
catch (std::runtime_error &e) {
cout << endl;
cout << "# ERR: runtime_error in " << __FILE__;
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
cout << "# ERR: " << e.what() << endl;
cout << "not ok 1 - examples/exceptions.cpp" << endl;
}
catch(exception e){
cout<<"Exception in selectPeriod():"<<e.what()<<endl;
}
}
double selectUtil(string util_dist,double stm_inst,double rt_inst,double period){
//Return utilization for current task. min_ratio is the minimum value for util percentage
try{
int min_ratio=(int)(rt_inst>stm_inst?ceil(rt_inst/period):ceil(stm_inst/period)); //min_ratio=min(wcet/period)|min(wcet)=max(one read/write stm instruction time,normal real_time instruction time)
min_ratio=min_ratio<1?1:min_ratio; //Just be sure min_ratio is not 0
int ratio_int=(100-min_ratio)/3;
int util_uniform_light[]={min_ratio,min_ratio+ratio_int};
int util_uniform_medium[]={min_ratio+ratio_int,min_ratio+2*ratio_int};
int util_uniform_heavy[]={min_ratio+2*ratio_int,100};
int sel_util=1; //Selected utilization, initialized at 1
if(!util_dist.compare("ul")){
//utilization is drawn from uniform light distribution
do{
sel_util=(rand()%(util_uniform_light[1]-util_uniform_light[0]))+util_uniform_light[0];
}while(sel_util<min_ratio);
}
else if(!util_dist.compare("um")){
//utilization is drawn from uniform medium distribution
do{
sel_util=(rand()%(util_uniform_medium[1]-util_uniform_medium[0]))+util_uniform_medium[0];
}while(sel_util<min_ratio);
}
else if(!util_dist.compare("uh")){
//utilization is drawn from uniform heavy distribution
do{
sel_util=(rand()%(util_uniform_heavy[1]-util_uniform_heavy[0]))+util_uniform_heavy[0];
}while(sel_util<min_ratio);
}
return (double)sel_util/100.0;
}
catch(sql::InvalidArgumentException &e) {
cout << "#\t Invalid Argument: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
catch (sql::MethodNotImplementedException &e){
cout << "#\t Not implemented: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
catch (sql::SQLException &e){
/*
The MySQL Connector/C++ throws three different exceptions:
- sql::MethodNotImplementedException (derived from sql::SQLException)
- sql::InvalidArgumentException (derived from sql::SQLException)
- sql::SQLException (derived from std::runtime_error)
sql::SQLException is the base class.
*/
cout << endl;
cout << "# ERR: DbcException in " << __FILE__;
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
/* Use what(), getErrorCode() and getSQLState() */
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
if (e.getErrorCode() == 1047) {
/*
Error: 1047 SQLSTATE: 08S01 (ER_UNKNOWN_COM_ERROR)
Message: Unknown command
*/
cout << "# ERR: Your server seems not to support PS at all because its MYSQL <4.1" << endl;
}
cout << "not ok 1 - examples/exceptions.cpp" << endl;
}
catch (std::runtime_error &e) {
cout << endl;
cout << "# ERR: runtime_error in " << __FILE__;
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
cout << "# ERR: " << e.what() << endl;
cout << "not ok 1 - examples/exceptions.cpp" << endl;
}
catch(exception e){
cout<<"Exception in selectUtil():"<<e.what()<<endl;
}
}
double selectTotalTx(string total_tx_dist,double stm_inst,double wcet){
//Returns selected total percentage of transactional length according to required distribution
//min_ratio is the minimum value for total_tx_dist perc=min(one read/write stm instruction time/wcet)
try{
int min_ratio=(int)ceil(stm_inst/wcet);
min_ratio=min_ratio<1?1:min_ratio; //Just be sure min_ratio is not 0
int int_diff=(100-min_ratio)/3;
int total_tx_uniform_light[]={min_ratio,min_ratio+int_diff};
int total_tx_uniform_medium[]={min_ratio+int_diff,min_ratio+2*int_diff};
int total_tx_uniform_heavy[]={min_ratio+2*int_diff,100};
int sel_total=1; //Selected total value, initialized at 1
if(!total_tx_dist.compare("ul")){
//utilization is drawn from uniform light distribution
do{
sel_total=(rand()%(total_tx_uniform_light[1]-total_tx_uniform_light[0]))+total_tx_uniform_light[0];
}while(sel_total<min_ratio);
}
else if(!total_tx_dist.compare("um")){
//utilization is drawn from uniform medium distribution
do{
sel_total=(rand()%(total_tx_uniform_medium[1]-total_tx_uniform_medium[0]))+total_tx_uniform_medium[0];
}while(sel_total<min_ratio);
}
else if(!total_tx_dist.compare("uh")){
//utilization is drawn from uniform heavy distribution
do{
sel_total=(rand()%(total_tx_uniform_heavy[1]-total_tx_uniform_heavy[0]))+total_tx_uniform_heavy[0];
}while(sel_total<min_ratio);
}
return (double)sel_total/100.0;
}
catch(sql::InvalidArgumentException &e) {
cout << "#\t Invalid Argument: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
catch (sql::MethodNotImplementedException &e){
cout << "#\t Not implemented: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
catch (sql::SQLException &e){
/*
The MySQL Connector/C++ throws three different exceptions:
- sql::MethodNotImplementedException (derived from sql::SQLException)
- sql::InvalidArgumentException (derived from sql::SQLException)
- sql::SQLException (derived from std::runtime_error)
sql::SQLException is the base class.
*/
cout << endl;
cout << "# ERR: DbcException in " << __FILE__;
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
/* Use what(), getErrorCode() and getSQLState() */
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
if (e.getErrorCode() == 1047) {
/*
Error: 1047 SQLSTATE: 08S01 (ER_UNKNOWN_COM_ERROR)
Message: Unknown command
*/
cout << "# ERR: Your server seems not to support PS at all because its MYSQL <4.1" << endl;
}
cout << "not ok 1 - examples/exceptions.cpp" << endl;
}
catch (std::runtime_error &e) {
cout << endl;
cout << "# ERR: runtime_error in " << __FILE__;
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
cout << "# ERR: " << e.what() << endl;
cout << "not ok 1 - examples/exceptions.cpp" << endl;
}
catch(exception e){
cout<<"Error in selectTotalTx():"<<e.what()<<endl;
}
}
double selectMaxTx(string max_tx_dist,double total_tx,double stm_inst,double wcet){
//Returns selected max percentage of transactional length according to required distribution
try{
int min_ratio=(int)ceil(stm_inst/wcet); //min_ratio is the minimum value for max_tx_dist perc=min(one read/write stm instruction time/wcet)
min_ratio=min_ratio<1?1:min_ratio;
int tmp_int=(100-min_ratio)/3;
int max_tx_uniform_light[]={min_ratio,min_ratio+tmp_int};
int max_tx_uniform_medium[]={min_ratio+tmp_int,min_ratio+2*tmp_int};
int max_tx_uniform_heavy[]={min_ratio+2*tmp_int,100};
int sel_max=1; //selected maximum value, initialized at 1
int high_max_bound; //Holds the higher distribution boundary in following comparisons
total_tx=(total_tx*100)+1; //To enable comparison against different boundaries as given below
//total_tx is incremented by 1 (after it is converted to integer)to enable max_tx to gain values
//at most equal to total_tx
if(!max_tx_dist.compare("ul")){
//utilization is drawn from uniform light distribution
if(total_tx<max_tx_uniform_light[0]){
cout<<"Error: total_tx is lower than max_tx"<<endl;
exit(0);
}
high_max_bound=total_tx>(max_tx_uniform_light[1]+1)?(max_tx_uniform_light[1]+1):total_tx;
do{
sel_max=(rand()%(high_max_bound-max_tx_uniform_light[0]))+max_tx_uniform_light[0];
}while(sel_max<min_ratio);
}
else if(!max_tx_dist.compare("um")){
//utilization is drawn from uniform medium distribution
if(total_tx<max_tx_uniform_medium[0]){
cout<<"Error: total_tx is lower than max_tx"<<endl;
exit(0);
}
high_max_bound=total_tx>(max_tx_uniform_medium[1]+1)?(max_tx_uniform_medium[1]+1):total_tx;
do{
sel_max=(rand()%(high_max_bound-max_tx_uniform_medium[0]))+max_tx_uniform_medium[0];
}while(sel_max<min_ratio);
}
else if(!max_tx_dist.compare("uh")){
//utilization is drawn from uniform heavy distribution
if(total_tx<max_tx_uniform_heavy[0]){
cout<<"Error: total_tx is lower than max_tx"<<endl;
exit(0);
}
high_max_bound=total_tx>(max_tx_uniform_heavy[1]+1)?(max_tx_uniform_heavy[1]+1):total_tx;
do{
sel_max=(rand()%(high_max_bound-max_tx_uniform_heavy[0]))+max_tx_uniform_heavy[0];
}while(sel_max<min_ratio);
}
return (double)sel_max/100.0;
}
catch(sql::InvalidArgumentException &e) {
cout << "#\t Invalid Argument: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
catch (sql::MethodNotImplementedException &e){
cout << "#\t Not implemented: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
catch (sql::SQLException &e){
/*
The MySQL Connector/C++ throws three different exceptions:
- sql::MethodNotImplementedException (derived from sql::SQLException)
- sql::InvalidArgumentException (derived from sql::SQLException)
- sql::SQLException (derived from std::runtime_error)
sql::SQLException is the base class.
*/
cout << endl;
cout << "# ERR: DbcException in " << __FILE__;
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
/* Use what(), getErrorCode() and getSQLState() */
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
if (e.getErrorCode() == 1047) {
/*
Error: 1047 SQLSTATE: 08S01 (ER_UNKNOWN_COM_ERROR)
Message: Unknown command
*/
cout << "# ERR: Your server seems not to support PS at all because its MYSQL <4.1" << endl;
}
cout << "not ok 1 - examples/exceptions.cpp" << endl;
}
catch (std::runtime_error &e) {
cout << endl;
cout << "# ERR: runtime_error in " << __FILE__;
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
cout << "# ERR: " << e.what() << endl;
cout << "not ok 1 - examples/exceptions.cpp" << endl;
}
catch(exception e){
cout<<"Exception in selectMaxTx():"<<e.what()<<endl;
}
}
double selectMinTx(string min_tx_dist,double max_tx,double stm_inst,double wcet){
//Returns selected min percentage of transactional length according to required distribution
try{
int min_ratio=(int)ceil(stm_inst/wcet); //min_ratio is the minimum value for min_tx_dist perc=min(one read/write stm instruction time/wcet)
min_ratio=min_ratio<1?1:min_ratio; //Just be sure min_ratio is not 0
int tmp_int=(100-min_ratio)/3;
int min_tx_uniform_light[]={min_ratio,min_ratio+tmp_int};
int min_tx_uniform_medium[]={min_ratio+tmp_int,min_ratio+2*tmp_int};
int min_tx_uniform_heavy[]={min_ratio+2*tmp_int,100};
int sel_min=1; //selected minimum value. Initialized at 1
int high_min_bound; //To enable comparison against different distribution boundaries
max_tx=(max_tx*100)+1; //max_tx is incremented by 1 (after it is converted into integer) to enable min_tx to gain values
//at most equal to max_tx
if(!min_tx_dist.compare("ul")){
//utilization is drawn from uniform light distribution
if(max_tx<min_tx_uniform_light[0]){
cout<<"Error: max_tx is lower than min_tx"<<endl;
exit(0);
}
high_min_bound=max_tx>(min_tx_uniform_light[1]+1)?(min_tx_uniform_light[1]+1):max_tx;
do{
//This loop guarantees that min is never 0
sel_min=(rand()%(high_min_bound-min_tx_uniform_light[0]))+min_tx_uniform_light[0];
}while(sel_min<min_ratio);
}
else if(!min_tx_dist.compare("um")){
//utilization is drawn from uniform medium distribution
if(max_tx<min_tx_uniform_medium[0]){
cout<<"Error: max_tx is lower than min_tx"<<endl;
exit(0);
}
high_min_bound=max_tx>(min_tx_uniform_medium[1]+1)?(min_tx_uniform_medium[1]+1):max_tx;
do{
sel_min=(rand()%(high_min_bound-min_tx_uniform_medium[0]))+min_tx_uniform_medium[0];
}while(sel_min<min_ratio);
}
else if(!min_tx_dist.compare("uh")){
//utilization is drawn from uniform heavy distribution
if(max_tx<min_tx_uniform_heavy[0]){
cout<<"Error: max_tx is lower than min_tx"<<endl;
exit(0);
}
high_min_bound=max_tx>(min_tx_uniform_heavy[1]+1)?(min_tx_uniform_heavy[1]+1):max_tx;
do{
sel_min=(rand()%(high_min_bound-min_tx_uniform_heavy[0]))+min_tx_uniform_heavy[0];
}while(sel_min<min_ratio);
}
return (double)sel_min/100.0;
}
catch(sql::InvalidArgumentException &e) {
cout << "#\t Invalid Argument: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
catch (sql::MethodNotImplementedException &e){
cout << "#\t Not implemented: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
catch (sql::SQLException &e){
/*
The MySQL Connector/C++ throws three different exceptions:
- sql::MethodNotImplementedException (derived from sql::SQLException)
- sql::InvalidArgumentException (derived from sql::SQLException)
- sql::SQLException (derived from std::runtime_error)
sql::SQLException is the base class.
*/
cout << endl;
cout << "# ERR: DbcException in " << __FILE__;
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
/* Use what(), getErrorCode() and getSQLState() */
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
if (e.getErrorCode() == 1047) {
/*
Error: 1047 SQLSTATE: 08S01 (ER_UNKNOWN_COM_ERROR)
Message: Unknown command
*/
cout << "# ERR: Your server seems not to support PS at all because its MYSQL <4.1" << endl;
}
cout << "not ok 1 - examples/exceptions.cpp" << endl;
}
catch (std::runtime_error &e) {
cout << endl;
cout << "# ERR: runtime_error in " << __FILE__;
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
cout << "# ERR: " << e.what() << endl;
cout << "not ok 1 - examples/exceptions.cpp" << endl;
}
catch(exception e){
cout<<"Exception in selectMinTx():"<<e.what()<<endl;
}
}
vector<double> selectObj(string obj_dist,int total_no_obj,double por_len,double stm_inst){
//Return a vector of selected objects according to total number of objects and object distribution
//Selected number of objects should fit in selected por_len. stm_inst is the time for one read/write stm instruction
//por_len should be greater or equal to stm_inst*no_objects
try{
int max_no_obj=(int)floor(por_len/stm_inst); //maximum number of objects to fit in current portion length
if(max_no_obj==0){
cout<<"############ Error:selectObj()-> maximum number of objects is 0 ############"<<endl;
cout<<"por_len:"<<por_len<<", stm_inst:"<<stm_inst<<endl;
exit(0);
}
int obj_uniform_light[]={0,30};
int obj_uniform_medium[]={30,50};
int obj_uniform_heavy[]={50,100};
int sel_no_obj=1; //selected total number of objects, initialized to one object
int obj_indx; //Index of selected object from vector of total objects
vector<double> total_objs; //List of all objects
vector<double> sel_objs; //Holds selected objects
/* Initialize a list of all objects to select desired objects from it */
for(int i=0;i<total_no_obj;i++){
total_objs.push_back(i);
}
/* Generate vector of desired objects according to object distribution and total number of objects */
if(!obj_dist.compare("ul")){
//uniform light
do{
//This loop guarantees that total_no_obj in this case is never 0
sel_no_obj=ceil(((rand()%(obj_uniform_light[1]-obj_uniform_light[0]))+obj_uniform_light[0])*total_no_obj/100);
}while(sel_no_obj==0);
}
else if(!obj_dist.compare("um")){
//uniform medium
sel_no_obj=ceil(((rand()%(obj_uniform_medium[1]-obj_uniform_medium[0]))+obj_uniform_medium[0])*total_no_obj/100);
}
else if(!obj_dist.compare("uh")){
//uniform heavy
sel_no_obj=ceil(((rand()%(obj_uniform_heavy[1]-obj_uniform_heavy[0]))+obj_uniform_heavy[0])*total_no_obj/100);
}
sel_no_obj=sel_no_obj>max_no_obj?max_no_obj:sel_no_obj;
for(int i=0;i<sel_no_obj;i++){
obj_indx=rand()%(total_objs.size());
sel_objs.push_back(total_objs[obj_indx]);
total_objs.erase(total_objs.begin()+obj_indx);
}
return sel_objs;
}
catch(sql::InvalidArgumentException &e) {
cout << "#\t Invalid Argument: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
catch (sql::MethodNotImplementedException &e){
cout << "#\t Not implemented: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
catch (sql::SQLException &e){
/*
The MySQL Connector/C++ throws three different exceptions:
- sql::MethodNotImplementedException (derived from sql::SQLException)
- sql::InvalidArgumentException (derived from sql::SQLException)
- sql::SQLException (derived from std::runtime_error)
sql::SQLException is the base class.
*/
cout << endl;
cout << "# ERR: DbcException in " << __FILE__;
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
/* Use what(), getErrorCode() and getSQLState() */
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
if (e.getErrorCode() == 1047) {
/*
Error: 1047 SQLSTATE: 08S01 (ER_UNKNOWN_COM_ERROR)
Message: Unknown command
*/
cout << "# ERR: Your server seems not to support PS at all because its MYSQL <4.1" << endl;
}
cout << "not ok 1 - examples/exceptions.cpp" << endl;
}
catch (std::runtime_error &e) {
cout << endl;
cout << "# ERR: runtime_error in " << __FILE__;
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
cout << "# ERR: " << e.what() << endl;
cout << "not ok 1 - examples/exceptions.cpp" << endl;
}
catch(exception e){
cout<<"Exception in selectObj():"<<e.what()<<endl;
}
}
void checkPortions(vector<struct task_por> *portions){
//Currently, checks no two consecuitive portions are of the same type
try{
if(portions->size()<2){
//No need to check
return;
}
for(int i=0;i<(portions->size())-1;i++){
if(portions->at(i).por_type==portions->at(i+1).por_type){
/* Two consecuitive portions of the same type. Change it */
portions->at(i).por_len+=portions->at(i+1).por_len;
portions->at(i).mod_por_len=portions->at(i).por_len;
if(portions->at(i).por_obj.size()<portions->at(i+1).por_obj.size()){
portions->at(i).por_obj=portions->at(i+1).por_obj;
}
portions->erase(portions->begin()+i+1);
i--; //keep the current element for next comparison
}
}
}
catch(sql::InvalidArgumentException &e) {
cout << "#\t Invalid Argument: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
catch (sql::MethodNotImplementedException &e){
cout << "#\t Not implemented: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
catch (sql::SQLException &e){
/*
The MySQL Connector/C++ throws three different exceptions:
- sql::MethodNotImplementedException (derived from sql::SQLException)
- sql::InvalidArgumentException (derived from sql::SQLException)
- sql::SQLException (derived from std::runtime_error)
sql::SQLException is the base class.
*/
cout << endl;
cout << "# ERR: DbcException in " << __FILE__;
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
/* Use what(), getErrorCode() and getSQLState() */
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
if (e.getErrorCode() == 1047) {
/*
Error: 1047 SQLSTATE: 08S01 (ER_UNKNOWN_COM_ERROR)
Message: Unknown command
*/
cout << "# ERR: Your server seems not to support PS at all because its MYSQL <4.1" << endl;
}
cout << "not ok 1 - examples/exceptions.cpp" << endl;
}
catch (std::runtime_error &e) {
cout << endl;
cout << "# ERR: runtime_error in " << __FILE__;
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
cout << "# ERR: " << e.what() << endl;
cout << "not ok 1 - examples/exceptions.cpp" << endl;
}
catch(exception e){
cout<<"Exception in checkPortions():"<<e.what()<<endl;
}
}
void addPortions(double total_tx,double max_tx,double min_tx,double wcet,string obj_dist,int total_no_obj,vector<struct task_por> *portions,double stm_inst,double rt_inst){
try{
double non_tx_sum=0; //Accumulated length of non-critical sections
double tx_sum=0; //Accumulated length of critical sections
int max_non_tx_no; //Holds maximum number of non-critical sections
int tx_indx; //Current index of critical section
int non_tx_indx; //Current index of non-critical section
int max_non_tx_indx; //Maximum index of non-critical section
if(portions==NULL){
cout<<"Error: addPortions()->portions vector is null";
exit(0);
}
if(!portions->empty()){
portions->clear(); //Be sure that portions is empty
}
/* Initially, choose portion length for critical sections */
if(total_tx==1){
//The whole task is a transaction or not
struct task_por tmp_por;
tmp_por.por_type=1;
tmp_por.por_len=wcet;
tmp_por.mod_por_len=tmp_por.por_len;
tmp_por.por_obj=selectObj(obj_dist,total_no_obj,tmp_por.mod_por_len,stm_inst);
portions->push_back(tmp_por);
}
else if(total_tx==0){
//Task does not contain any critical sections
struct task_por tmp_por;
tmp_por.por_type=0;
tmp_por.por_len=wcet;
tmp_por.mod_por_len=tmp_por.por_len;
tmp_por.por_obj.push_back(-1);
portions->push_back(tmp_por);
}
else{
//Task contains both critical and non-critical sections
/* NOTE THAT THIS MEHTOD OF GENERATING PORTIONS MAY BE MODIFIED LATER */
/* PORTIONS ARE GENERATED AS FOLLOWS:
* 1- ALL TRANSACTIONAL PORTIONS ARE PRODUCED.
* 2- TASK STARTS WITH A TRANSACTIONAL PORTION.
* 3- NUMBER OF NON-CRITICAL SECTIONS AT MOST EQUALS NUMBER OF CRITICAL SECTIONS.
* POINTS 2 AND 3 CAN BE MODIFIED SUCH THAT THE FIRST PORTION IS RANDOMLY CHOSEN AS
* A CRITICAL OR NON-CRITICAL SECTION, AND TOTAL NUMBER OF ONE TYPE OF PORTIONS CAN
* MOSTLY INCREASE OVER THE OTHER TYPE BY 1 */
/* Initially, generate all transactional portions */
struct task_por tmp_por;
tx_indx=0;
do{
tmp_por.por_type=1;
tmp_por.por_len=(fmod((double)rand(),(max_tx-min_tx)*100)/100.0+min_tx)*wcet;
if(tmp_por.por_len<stm_inst){
tmp_por.por_len=stm_inst;
}
tx_sum+=tmp_por.por_len;
tmp_por.mod_por_len=tmp_por.por_len;
tmp_por.por_obj.clear();
tmp_por.por_obj=selectObj(obj_dist,total_no_obj,tmp_por.por_len,stm_inst);
tx_indx++;
portions->push_back(tmp_por);
}while(tx_sum<(wcet*total_tx) && wcet*total_tx-tx_sum>=stm_inst && tx_indx<=floor(total_tx/min_tx));
//remove the last portion that broke the loop
portions->erase((portions->end())-1);
/* Now, generate non-critical sections */
max_non_tx_no=portions->size()==1?1:portions->size()-1; //Used to limit length of each non-critical section
//If there's only 1 critical section,
//then at most 1 non-critical section
max_non_tx_indx=2*portions->size()-1; //Maximum index of non-critical sections
non_tx_indx=1; //According to generation algorithm, non-critical sections start at index 1
while(non_tx_indx<=max_non_tx_indx){
tmp_por.por_type=0;
tmp_por.por_obj.clear();
tmp_por.por_obj.push_back(-1);
if(non_tx_indx==max_non_tx_indx){
//Reached last non-critical section
tmp_por.por_len=wcet*(1-total_tx)-non_tx_sum;
}
else{
//Still more non-critical sections to add
/* The non-critical length divided over at most max_non_tx_no+1
But it is divided over max_non_tx_no because number of non-critical
sections can either be max_non_tx_no or max_non_tx_no+1 */
tmp_por.por_len=fmod((double)rand(),wcet*(1-total_tx)/max_non_tx_no);
}
//por_len cannot be lower than rt_inst
if(tmp_por.por_len<rt_inst){
/* Check if selected length is less than rt_inst */
tmp_por.por_len=rt_inst;
}
non_tx_sum+=tmp_por.por_len;
portions->insert(portions->begin()+non_tx_indx,tmp_por);
non_tx_indx+=2;
}
}
checkPortions(portions);
}
catch(sql::InvalidArgumentException &e) {
cout << "#\t Invalid Argument: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
catch (sql::MethodNotImplementedException &e){
cout << "#\t Not implemented: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
catch (sql::SQLException &e){
/*
The MySQL Connector/C++ throws three different exceptions:
- sql::MethodNotImplementedException (derived from sql::SQLException)
- sql::InvalidArgumentException (derived from sql::SQLException)
- sql::SQLException (derived from std::runtime_error)
sql::SQLException is the base class.
*/
cout << endl;
cout << "# ERR: DbcException in " << __FILE__;
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
/* Use what(), getErrorCode() and getSQLState() */
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
if (e.getErrorCode() == 1047) {
/*
Error: 1047 SQLSTATE: 08S01 (ER_UNKNOWN_COM_ERROR)
Message: Unknown command
*/
cout << "# ERR: Your server seems not to support PS at all because its MYSQL <4.1" << endl;
}
cout << "not ok 1 - examples/exceptions.cpp" << endl;
}
catch (std::runtime_error &e) {
cout << endl;
cout << "# ERR: runtime_error in " << __FILE__;
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
cout << "# ERR: " << e.what() << endl;
cout << "not ok 1 - examples/exceptions.cpp" << endl;
}
catch(exception e){
cout<<"Exception in addPortions():"<<e.what()<<endl;
}
}
void modifyPortions(string data_set_host,string data_set,string user_name,string user_pass,double stm_inst,double rt_inst,bool add){
//Modifies portions not meeting requirements
//If "add" is true, then function adds missed portions, otherwise, it fixes them
try{
if(!initialized){
initDB(data_set_host,data_set,user_name,user_pass);
}
sql::ResultSet *dataset_res;
sql::ResultSet *task_res;
sql::ResultSet *por_res;
stringstream ss;
int dataset,task,total_no_obj,por_type,por_id;
double total_tx,max_tx,min_tx,wcet,por_len,period;
string obj_dist;
stmt=con->createStatement();
/* tmp step */ ss<<"select * from datasets where id=3";
dataset_res=stmt->executeQuery(ss.str());
while(dataset_res->next()){
/**///cout<<"************ DATATSET "<<dataset_res->getInt("id")<<" ************"<<endl;
dataset=dataset_res->getInt("id");
/**///cout<<"dataset_id:"<<dataset<<endl;
total_tx=dataset_res->getDouble("total_tx");
/**///cout<<"total_tx:"<<total_tx<<endl;
max_tx=dataset_res->getDouble("max_tx");
/**///cout<<"max_tx:"<<max_tx<<endl;
min_tx=dataset_res->getDouble("min_tx");
/**///cout<<"min_tx:"<<min_tx<<endl;
total_no_obj=atoi((dataset_res->getString("total_no_obj")).c_str());
/**///cout<<"total_no_obj:"<<total_no_obj<<endl;
obj_dist=dataset_res->getString("no_obj_tx_dis");
/**///cout<<"obj_dist:"<<obj_dist<<endl;
ss.str("");
ss<<"select id, wcet, period from tasks where dataset="<<dataset;
task_res=stmt->executeQuery(ss.str());
while(task_res->next()){
/**///cout<<"************* TASK "<<task_res->getInt("id")<<" ***************"<<endl;
task=task_res->getInt("id");
wcet=task_res->getDouble("wcet");
period=task_res->getDouble("period");
ss.str("");
ss<<"select * from task_st where dataset="<<dataset<<" and task="<<task;
por_res=stmt->executeQuery(ss.str());
if(add && !(por_res->next())){
//There're no portions for the specified dataset and task
//Add portions for this dataset and task
/* Generate task structure for current task in task_st table */
/**/cout<<"dataset: "<<dataset<<", task: "<<task;
vector<struct task_por> portions; //selected portion length for all portions of current task
addPortions(total_tx,max_tx,min_tx,wcet,obj_dist,total_no_obj,&portions,stm_inst,rt_inst);
/* tmp_step */ cout<<", size:"<<portions.size()<<endl;
/* Insert task structure for current task in task_st table */
for(int k=0;k<portions.size();k++){
stmt=con->createStatement();
ss.str("");
ss<<"INSERT INTO `test`.`task_st`(`dataset`,`task`,`id`,`por_type`,`por_len`,`objs`) VALUES(";
ss<<dataset<<","<<task<<","<<k<<","<<portions[k].por_type<<","<<portions[k].por_len;
// Insert list of objects for current portion
ss<<",'";
for(int h=0;h<portions[k].por_obj.size();h++){
ss<<portions[k].por_obj[h];
if(h!=portions[k].por_obj.size()-1){
ss<<",";
}
else{
ss<<"')";
}
}
stmt->execute(ss.str());
portions.clear();
}
}
else if(!add){
//Found portions. Check them and modify if necessary
while(por_res->next()){
/**/cout<<"************ PORTION "<<por_res->getInt("id")<<" ************"<<endl;
por_id=por_res->getInt("id");
por_len=por_res->getDouble("por_len");
por_type=por_res->getInt("por_type");
if(por_type==0 && por_len<rt_inst){
ss.str("");
ss<<"update task_st set por_len="<<rt_inst<<" where dataset="<<dataset;
ss<<" and task="<<task<<" and id="<<por_id;
stmt->executeUpdate(ss.str());
}
else if(por_type==1 && ((por_len/wcet)<(min_tx-0.01) || (por_len/wcet)>(max_tx+0.01))){
//this task needs modification
vector<struct task_por> portions;
ss.str("");
ss<<"delete from task_st where dataset="<<dataset<<" and task="<<task;
stmt->executeUpdate(ss.str());
addPortions(total_tx,max_tx,min_tx,wcet,obj_dist,total_no_obj,&portions,stm_inst,rt_inst);