aboutsummaryrefslogtreecommitdiff
path: root/src/mintdb/perf_taler_mintdb_interpreter.h
blob: 3510e3dd45e402771046ce3f2e7ab6e157cbf2ee (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
/*
  This file is part of TALER
  Copyright (C) 2014, 2015 GNUnet e.V.

  TALER 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, or (at your option) any later version.

  TALER 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
  TALER; see the file COPYING.  If not, If not, see <http://www.gnu.org/licenses/>
*/
/**
 * @file mintdb/perf_taler_mintdb_interpreter.h
 * @brief Library for performance analysis of the Taler database
 * @author Nicolas Fournier
 *
 * This library contains functions and macro alowing Taler performance analysis
 * to be written with ease.
 * To do so, create a #PERF_TALER_MINTDB_Cmd array and fill it with the commands
 * to execute in chronological order. Some command have an exposed variable wich
 * can be reused in other commands.
 * Macros are available to make the use much easier so feel free to use them
 * to initialize your own command array.
 */

#ifndef __PERF_TALER_MINTDB_INTERPRETER_H__
#define __PERF_TALER_MINTDB_INTERPRETER_H__

#include <sys/time.h>
#include "taler_mintdb_plugin.h"


#define PERF_TALER_MINTDB_NB_DENOMINATION_INIT  10
#define PERF_TALER_MINTDB_NB_DENOMINATION_SAVE  10

#define PERF_TALER_MINTDB_NB_RESERVE_INIT   100
#define PERF_TALER_MINTDB_NB_RESERVE_SAVE   10

#define PERF_TALER_MINTDB_NB_DEPOSIT_INIT   100
#define PERF_TALER_MINTDB_NB_DEPOSIT_SAVE   10

#define PERF_TALER_MINTDB_NB_WITHDRAW_INIT  100
#define PERF_TALER_MINTDB_NB_WITHDRAW_SAVE  10


/**
 * Marks the end of the command chain
 *
 * @param _label The label of the command
 */
#define PERF_TALER_MINTDB_INIT_CMD_END(_label) \
{ \
  .command = PERF_TALER_MINTDB_CMD_END, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_NONE \
}


/**
 * Prints @ _label to stdout
 *
 * @param _label The label of the command,
 *  will be logged each time the command runs
 */
#define PERF_TALER_MINTDB_INIT_CMD_DEBUG(_label) \
{ \
  .command = PERF_TALER_MINTDB_CMD_DEBUG, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_NONE \
}

/**
 * The begining of a loop
 *
 * @param _label the label of the loop
 * @param _iter the number of iterations of the loop
 */
#define PERF_TALER_MINTDB_INIT_CMD_LOOP(_label, _iter) \
{ \
  .command = PERF_TALER_MINTDB_CMD_LOOP , \
  .label = _label , \
  .exposed.type = PERF_TALER_MINTDB_NONE , \
  .details.loop = { \
    .max_iterations = _iter , \
    .curr_iteration = 0 } \
}

/**
 * Marks the end of the loop @_label_loop
 *
 * @param _label the label of the command
 * @param _label_loop the label of the loop closed by this command
 */
#define PERF_TALER_MINTDB_INIT_CMD_END_LOOP(_label, _label_loop) \
{\
  .command = PERF_TALER_MINTDB_CMD_END_LOOP , \
  .label = _label , \
  .exposed.type = PERF_TALER_MINTDB_NONE , \
  .details.end_loop.label_loop = _label_loop \
}

/**
 * Saves the time of execution to use for logging with Gauger
 *
 * @param _label the label of the command
 */
#define PERF_TALER_MINTDB_INIT_CMD_GET_TIME(_label) \
{ \
  .command = PERF_TALER_MINTDB_CMD_GET_TIME, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_TIME \
}

/**
 * Commits the duration between @a _label_start and @a _label_stop
 * to Gauger with @a _description explaining what was measured.
 *
 * @param _label the label of this command
 * @param _label_start label of the start of the measurment
 * @param _label_stop label of the end of the measurment
 * @param _description description of the measure displayed in Gauger
 * @param _unit the unit of the data measured, typicly something/sec
 * @param _divide number of measurments in the interval
 */
#define PERF_TALER_MINTDB_INIT_CMD_GAUGER(_label, _label_start, _label_stop, _category, _description, _unit, _divide) \
{ \
  .command = PERF_TALER_MINTDB_CMD_GAUGER, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_NONE, \
  .details.gauger = { \
    .label_start = _label_start, \
    .label_stop = _label_stop, \
    .category = _category, \
    .description = _description, \
    .unit = _unit, \
    .divide = _divide, \
  } \
}

/**
 * Initiate a database transaction
 *
 * @param _label the label of the command
 */
#define PERF_TALER_MINTDB_INIT_CMD_START_TRANSACTION(_label) \
{ \
  .command = PERF_TALER_MINTDB_CMD_START_TRANSACTION, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_NONE, \
}

/**
 * Commits a database transaction
 *
 * @param _label the label of the command
 */
#define PERF_TALER_MINTDB_INIT_CMD_COMMIT_TRANSACTION(_label) \
{ \
  .command = PERF_TALER_MINTDB_CMD_COMMIT_TRANSACTION, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_NONE, \
}

/**
 * Abort the current transaction
 *
 * @param _label the label of the command
 */
#define PERF_TALER_MINTDB_INIT_CMD_ABORT_TRANSACTION(_label) \
{ \
  .command = PERF_TALER_MINTDB_CMD_ABORT_TRANSACTION, \
  .label = _label,

/**
 * Saves randomly selected items from @a _label_save
 * Saved items can latter be access using #PERF_TALER_MINTDB_CMD_LOAD_ARRAY
 *
 * @param _label the label of the command, used by other commands to reference it
 * @param _label_loop the label of the loop the array iterates over
 * @param _label_save the label of the command which outout is saved by this command
 * @param _nb_saved the total number of items to be saved
 */
#define PERF_TALER_MINTDB_INIT_CMD_SAVE_ARRAY(_label, _label_loop, _label_save, _nb_saved) \
{ \
  .command = PERF_TALER_MINTDB_CMD_SAVE_ARRAY, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_NONE, \
  .details.save_array = { \
    .label_loop = _label_loop, \
    .label_save = _label_save, \
    .nb_saved = _nb_saved, \
  } \
}

/**
 * Loads data from a #PERF_TALER_MINTDB_CMD_SAVE_ARRAY to allow other
 * commands to access it
 *
 * @param _label the label of this command, referenced by commands to access it's outpout
 * @param _label_loop the label of the loop to iterate over
 * @param _label_save the label of the #PERF_TALER_MINTDB_CMD_SAVE_ARRAY providing data
 */
#define PERF_TALER_MINTDB_INIT_CMD_LOAD_ARRAY(_label, _label_loop, _label_save) \
{ \
  .command = PERF_TALER_MINTDB_CMD_LOAD_ARRAY, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_NONE, \
  .details.load_array = { \
    .label_loop = _label_loop, \
    .label_save = _label_save \
  } \
}

/**
 * Create a denomination key to use
 * Exposes a #PERF_TALER_MINTDB_DENOMINATION_INFO to be used by other commands
 * @exposed #PERF_TALER_MINTDB_DENOMINATION_INFO
 *
 * @param _label the label of this command
 */
#define PERF_TALER_MINTDB_INIT_CMD_CREATE_DENOMINATION(_label) \
{ \
  .command = PERF_TALER_MINTDB_CMD_CREATE_DENOMINATION, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_DENOMINATION_INFO, \
}

/**
 * Inserts informations about a denomination key in the database
 *
 * @param _label the label of this command
 * @param _label_denom the label of the denomination to insert
 */
#define PERF_TALER_MINTDB_INIT_CMD_INSERT_DENOMINATION(_label, _label_denom) \
{ \
  .command = PERF_TALER_MINTDB_CMD_INSERT_DENOMINATION, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_NONE, \
  .details.insert_denomination.label_denom = _label_denom, \
}

/**
 * Polls the database about informations regarding a specific denomination key
 *
 * @param _label the label of this command
 * @param _label_denom the label of the command providing information about the denomination key
 */
#define PERF_TALER_MINTDB_INIT_CMD_GET_DENOMINATION(_label, _label_denom) \
{ \
  .command = PERF_TALER_MINTDB_CMD_GET_DENOMINATION, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_NONE, \
  .details.get_denomination.label_denom = _label_denom \
}

/**
 * Create a reserve to be used later
 * Exposes a #PERF_TALER_MINTDB_RESERVE
 *
 * @param _label the label of the command
 */
#define PERF_TALER_MINTDB_INIT_CMD_CREATE_RESERVE(_label) \
{ \
  .command = PERF_TALER_MINTDB_CMD_CREATE_RESERVE, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_RESERVE \
}

/**
 * Insert a new reserve in the database containing 1000 Euros
 *
 * @param _label the name of this command
 * @param _label_reserve the label of the reserve to insert
 */
#define PERF_TALER_MINTDB_INIT_CMD_INSERT_RESERVE(_label, _label_reserve) \
{ \
  .command = PERF_TALER_MINTDB_CMD_INSERT_RESERVE, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_NONE, \
  .details.insert_reserve.label_reserve = _label_reserve \
}

/**
 * Polls the database for a secific reserve's details
 *
 * @param _label the label of this command
 * @param _label_reserve the reserve to poll
 */
#define PERF_TALER_MINTDB_INIT_CMD_GET_RESERVE(_label, _label_reserve) \
{ \
  .command = PERF_TALER_MINTDB_CMD_GET_RESERVE, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_NONE, \
  .details.get_reserve.label_reserve = _label_reserve \
}

/**
 * Polls the database for the history of a reserve
 *
 * @param _label the label of the command
 * @param _label_reserve the reserve to examine
 */
#define PERF_TALER_MINTDB_INIT_CMD_GET_RESERVE_HISTORY(_label, _label_reserve) \
{ \
  .command = PERF_TALER_MINTDB_CMD_GET_RESERVE_HISTORY, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_NONE, \
  .details.get_reserve_history.label_reserve = _label_reserve \
}

/**
 * Creates a coin to be used later
 *
 * @param _label the label of this command
 * @param _label_dki denomination key used to sign the coin
 * @param _label_reserve reserve used to emmit the coin
 */
#define PERF_TALER_MINTDB_INIT_CMD_CREATE_WITHDRAW(_label, _label_dki, _label_reserve) \
{ \
  .command = PERF_TALER_MINTDB_CMD_CREATE_WITHDRAW, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_COIN, \
  .details.create_withdraw = {\
    .label_dki = _label_dki, \
    .label_reserve = _label_reserve, \
  } \
}

/**
 * Inserts informations about a withdrawal in the database
 *
 * @exposes #PERF_TALER_MINTDB_COIN
 *
 * @param _label the label of this command
 * @param _label_coin the coin to insert
 */
#define PERF_TALER_MINTDB_INIT_CMD_INSERT_WITHDRAW(_label, _label_coin) \
{ \
  .command = PERF_TALER_MINTDB_CMD_INSERT_WITHDRAW, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_NONE, \
  .details.insert_withdraw.label_coin = _label_coin\
}


/**
 * Polls the database about informations regarding a specific withdrawal
 *
 * @param _label the label of this command
 * @param _label_coin the coin to check
 */
#define PERF_TALER_MINTDB_INIT_CMD_GET_WITHDRAW(_label, _label_coin) \
{ \
  .command = PERF_TALER_MINTDB_CMD_GET_WITHDRAW, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_NONE, \
  .details.get_withdraw.label_coin = _label_coin, \
}


/**
 * The /reserve/withdraw api call
 *
 * Exposes #PERF_TALER_MINTDB_COIN
 *
 * @param _label the label of this command
 * @param _label_dki the denomination of the created coin
 * @param _label_reserve the reserve used to provide currency
 */
#define PERF_TALER_MINTDB_INIT_CMD_WITHDRAW_SIGN(_label, _label_dki, _label_reserve) \
  PERF_TALER_MINTDB_INIT_CMD_CREATE_WITHDRAW (_label "withdraw", \
                                              _label_dki, \
                                              _label_reserve), \
  PERF_TALER_MINTDB_INIT_CMD_GET_DENOMINATION(_label "withdraw info", \
                                              _label_dki), \
  PERF_TALER_MINTDB_INIT_CMD_GET_RESERVE_HISTORY(_label "reserve_history", \
                                                 _label_reserve), \
  PERF_TALER_MINTDB_INIT_CMD_INSERT_WITHDRAW(_label "insert withdraw", \
                                             _label "withdraw")

/**
 * Create a deposit for use later
 * @exposes #PERF_TALER_MINTDB_DEPOSIT
 *
 * @param _label the label of this command
 * @param _label_coin the coin used to pay
 */
#define PERF_TALER_MINTDB_INIT_CMD_CREATE_DEPOSIT(_label, _label_coin) \
{ \
  .command = PERF_TALER_MINTDB_CMD_CREATE_DEPOSIT, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_DEPOSIT, \
  .details.create_deposit.label_coin = _label_coin, \
}

/**
 * Insert a deposit into the database
 *
 * @param _label the label of this command
 * @param _label_deposit the deposit inseerted
 */
#define PERF_TALER_MINTDB_INIT_CMD_INSERT_DEPOSIT(_label, _label_deposit) \
{ \
  .command = PERF_TALER_MINTDB_CMD_INSERT_DEPOSIT,\
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_NONE, \
  .details.insert_deposit.label_deposit = _label_deposit, \
}

/**
 * Check if a deposit is in the database
 *
 * @param _label the label of this command
 * @param _label_deposit the deposit to use
 */
#define PERF_TALER_MINTDB_INIT_CMD_GET_DEPOSIT(_label, _label_deposit) \
{ \
  .command = PERF_TALER_MINTDB_CMD_GET_DEPOSIT, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_NONE, \
  .details.get_deposit.label_deposit = _label_deposit \
}

/**
 * Access the transaction history of a coin
 *
 * @param _label the label of the command
 * @param _label_coin the coin which history is checked
 */
#define PERF_TALER_MINTDB_INIT_CMD_GET_COIN_TRANSACTION(_label, _label_coin) \
{ \
  .command = PERF_TALER_MINTDB_CMD_GET_COIN_TRANSACTION, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_NONE, \
  .details.get_coin_transaction.label_coin = _label_coin \
}

/**
 * The /deposit api call
 *
 * @param _label the label of the command
 * @param _label_coin the coin used for the deposit
 */
#define PERF_TALER_MINTDB_INIT_CMD_DEPOSIT(_label, _label_coin) \
  PERF_TALER_MINTDB_INIT_CMD_GET_COIN_TRANSACTION (_label "coin history", \
                                                   _label_coin), \
  PERF_TALER_MINTDB_INIT_CMD_CREATE_DEPOSIT (_label "deposit", \
                                             _label_coin), \
  PERF_TALER_MINTDB_INIT_CMD_INSERT_DEPOSIT (_label "insert", \
                                             _label "deposit")
/**
 * Insert informations about a refresh session
 * melts one coin into another
 *
 * @param _label the label of the command
 */
#define PERF_TALER_MINTDB_INIT_CMD_CREATE_REFRESH_SESSION(_label) \
{ \
  .command = PERF_TALER_MINTDB_CMD_CREATE_REFRESH_SESSION, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_REFRESH_HASH \
}

/**
 * Get informations about a refresh session
 * 
 * @param _label the label of the command
 * @param _label_hash the label of the hash to search
 */
#define PERF_TALER_MINTDB_INIT_CMD_GET_REFRESH_SESSION(_label, \
                                                       _label_hash) \
{ \
  .command = PERF_TALER_MINTDB_CMD_GET_REFRESH_SESSION, \
  .label = _label, \
  .exposed.type = PERF_TALER_MINTDB_NONE \
}

/**
 * Insert a melt operation in the database
 *
 * @param _label the label of the command
 * @param _label_hash the label of the hash of the session
 * @param _label_coin the label of the coin to melt
 */
#define PERF_TALER_MINTDB_INIT_CMD_INSERT_REFRESH_MELT(_label, \
                                                       _label_hash, \
                                                       _label_coin) \
{ \
  .command = PERF_TALER_MINTDB_CMD_INSERT_REFRESH_MELT, \
  .label = _label, \
  .details.insert_refresh_melt.label_hash = _label_hash, \
  .details.insert_refresh_melt.label_coin = _label_coin, \
  .exposed.type = PERF_TALER_MINTDB_NONE \
}

/**
 * Get informations about a melt operation
 *
 * @param _label the label of the command
 * @param _label_hash the label of the hash of the refresh session
 */
#define PERF_TALER_MINTDB_INIT_CMD_GET_REFRESH_MELT(_label, \
                                                    _label_hash) \
{ \
  .command = PERF_TALER_MINTDB_CMD_GET_REFRESH_MELT, \
  .label = _label, \
  .detail.get_refresh_melt.label_hash = _label_hash, \
  .exposed.type = PERF_TALER_MINTDB_NONE \
}

/**
 * The type of data stored in #PERF_TALER_MINTDB_Memory
 */
enum PERF_TALER_MINTDB_Type
{
  PERF_TALER_MINTDB_NONE,
  PERF_TALER_MINTDB_TIME,
  PERF_TALER_MINTDB_DENOMINATION_INFO,
  PERF_TALER_MINTDB_RESERVE,
  PERF_TALER_MINTDB_COIN,
  PERF_TALER_MINTDB_DEPOSIT,
  PERF_TALER_MINTDB_REFRESH_HASH,
  PERF_TALER_MINTDB_REFRESH_MELT
};


/**
 * Structure used to handle several data type
 */
struct PERF_TALER_MINTDB_Data
{
  enum PERF_TALER_MINTDB_Type type;

  /**
   * Storage for a variety of data type
   * The data saved should match #type
   */
  union PERF_TALER_MINTDB_Memory
  {
    /** #PERF_TALER_MINTDB_TIME */
    struct GNUNET_TIME_Absolute *time;
    /** #PERF_TALER_MINTDB_DEPOSIT */
    struct TALER_MINTDB_Deposit *deposit;
    /** #PERF_TALER_MINTDB_COIN */
    struct PERF_TALER_MINTDB_Coin *coin;
    /** #PERF_TALER_MINTDB_RESERVE */
    struct PERF_TALER_MINTDB_Reserve *reserve;
    /** #PERF_TALER_MINTDB_DENOMINATION_INFO */
    struct TALER_MINTDB_DenominationKeyIssueInformation *dki;
    /** #PERF_TALER_MINTDB_REFRESH_HASH */
    struct GNUNET_HashCode *session_hash;
    /** #PERF_TALER_MINTDB_REFRESH_MELT */
    struct TALER_MINTDB_RefreshMelt *refresh_melt;
  } data;
};


/**
 * Name of the command
 */
enum PERF_TALER_MINTDB_CMD_Name
{
  /**
   * All comand chain must hace this as their last command
   */
  PERF_TALER_MINTDB_CMD_END,

  /**
   * Prints it's label
   */
  PERF_TALER_MINTDB_CMD_DEBUG,

  /**
   * Define the start of al command chain loop
   */
  PERF_TALER_MINTDB_CMD_LOOP,

  /**
   * Define the end of a command chain loop
   */
  PERF_TALER_MINTDB_CMD_END_LOOP,

  /**
   * Save the time at which the command was executed
   */
  PERF_TALER_MINTDB_CMD_GET_TIME,

  /**
   * Upload performance to Gauger
   */
  PERF_TALER_MINTDB_CMD_GAUGER,

  /**
   * Start a new session
   */
  PERF_TALER_MINTDB_CMD_NEW_SESSION,

  /**
   * Start a database transaction
   */
  PERF_TALER_MINTDB_CMD_START_TRANSACTION,

  /**
   * End a database transaction
   */
  PERF_TALER_MINTDB_CMD_COMMIT_TRANSACTION,

  /**
   * Abort a transaction started with #PERF_TALER_MINTDB_CMD_START_TRANSACTION
   */
  PERF_TALER_MINTDB_CMD_ABORT_TRANSACTION,

  /**
   * Saves random deposits from a loop
   */
  PERF_TALER_MINTDB_CMD_SAVE_ARRAY,

  /**
   * Load items saved earlier in a #PERF_TALER_MINTDB_CMD_SAVE_ARRAY
   * The items are loaded in a random order, but all of them will be loaded
   */
  PERF_TALER_MINTDB_CMD_LOAD_ARRAY,

  /**
   * Loads a random item from a #PERF_TALER_MINTDB_CMD_SAVE_ARRAY
   * A random item is loaded each time the command is run
   */
  PERF_TALER_MINTDB_CMD_LOAD_RANDOM,

  /**
   * Create a denomination to be used later
   */
  PERF_TALER_MINTDB_CMD_CREATE_DENOMINATION,

  /**
   * Insert informations about a denomination key in the database
   */
  PERF_TALER_MINTDB_CMD_INSERT_DENOMINATION,

  /**
   * Polls the database for informations about a specific denomination key
   */
  PERF_TALER_MINTDB_CMD_GET_DENOMINATION,

  /**
   * Create a reserve to be used later
   */
  PERF_TALER_MINTDB_CMD_CREATE_RESERVE,

  /**
   * Insert currency in a reserve / Create a reserve
   */
  PERF_TALER_MINTDB_CMD_INSERT_RESERVE,

  /**
   * Get Informations about a reserve
   */
  PERF_TALER_MINTDB_CMD_GET_RESERVE,

  /**
   * Get the history of a reserve
   */
  PERF_TALER_MINTDB_CMD_GET_RESERVE_HISTORY,

  /**
   * Create a withdrawal to be used later
   */
  PERF_TALER_MINTDB_CMD_CREATE_WITHDRAW,

  /**
   * Insert informations about a withdrawal in the database
   */
  PERF_TALER_MINTDB_CMD_INSERT_WITHDRAW,

  /**
   * Pulls informations about a withdrawal from the database
   */
  PERF_TALER_MINTDB_CMD_GET_WITHDRAW,

  /**
   * Get the list of all transactions the coin has been in
   */
  PERF_TALER_MINTDB_CMD_GET_COIN_TRANSACTION,

  /**
   * Create a deposit to be used later
   */
  PERF_TALER_MINTDB_CMD_CREATE_DEPOSIT,

  /**
   * Insert a deposit into the database
   */
  PERF_TALER_MINTDB_CMD_INSERT_DEPOSIT,

  /**
   * Check if a deposit is in the database
   */
  PERF_TALER_MINTDB_CMD_GET_DEPOSIT,

  /**
   * Create a refresh session
   * The number of melted coins is 1,
   * The number of minted coins is 1
   */
  PERF_TALER_MINTDB_CMD_CREATE_REFRESH_SESSION,

  /**
   * Get a refresh session informations
   */
  PERF_TALER_MINTDB_CMD_GET_REFRESH_SESSION,

  /**
   * Insert a refresh melt
   */
  PERF_TALER_MINTDB_CMD_INSERT_REFRESH_MELT,

  /**
   * Get informations about a refresh melt operation
   */
  PERF_TALER_MINTDB_CMD_GET_REFRESH_MELT,

  /**
   * Insert a melt refresh order
   */
  PERF_TALER_MINTDB_CMD_INSERT_REFRESH_ORDER,

  /**
   * Get informations about a refresh order
   */
  PERF_TALER_MINTDB_CMD_GET_REFRESH_ORDER,

  /**
   * Insert refresh commit coin
   */
  PERF_TALER_MINTDB_CMD_INSERT_REFRESH_COMMIT_COIN,

  /**
   * Get refresh commit coin
   */
  PERF_TALER_MINTDB_CMD_GET_REFRESH_COMMIT_COIN,

  /**
   * Insert refresh commit link
   */
  PERF_TALER_MINTDB_CMD_INSERT_REFRESH_COMMIT_LINK,

  /**
   * Get refresh commit link
   */
  PERF_TALER_MINTDB_CMD_GET_REFRESH_COMMIT_LINK,

  /**
   * Get information avout the melt commit
   */
  PERF_TALER_MINTDB_CMD_GET_MELT_COMMITMENT,

  /**
   * Insert a new coin into the database after a melt operation
   */
  PERF_TALER_MINTDB_CMD_INSERT_REFRESH_OUT,

  /**
   * Get the link data list of a coin
   */
  PERF_TALER_MINTDB_CMD_GET_LINK_DATA_LIST,

  /**
   * Get the shared secret and the transfere public key
   */
  PERF_TALER_MINTDB_CMD_GET_TRANSFER

};


/**
 * Contains extra data required for any command
 */
union PERF_TALER_MINTDB_CMD_Details
{
  /**
   * Extra data requiered for the #PERF_TALER_MINTDB_CMD_LOOP command
   */
  struct PERF_TALER_MINTDB_CMD_loopDetails
  {
    /**
     * Maximum number of iteration in the loop
     */
    const unsigned int max_iterations;

    /**
     * The current iteration of the loop
     */
    unsigned int curr_iteration;
  } loop;

  /**
   * Extra data requiered by the #PERF_TALER_MINTDB_CMD_END_LOOP command
   */
  struct PERF_TALER_MINTDB_CMD_endLoopDetails
  {
    /**
     * Label of the loop closed by the command
     */
    const char *label_loop;
    unsigned int index_loop;
  } end_loop;

  /**
   * Details about the #PERF_TALER_MINTDB_CMD_GAUGER  command
   */
  struct PERF_TALER_MINTDB_CMD_gaugerDetails
  {
    /**
     * Label of the starting timestamp
     */
    const char *label_start;
    unsigned int index_start;

    /**
     * Label of the ending timestamp
     */
    const char *label_stop;
    unsigned int index_stop;

    /**
     * The category of the measurment
     */
    const char *category;

    /**
     * Description of the metric, used in Gauger
     */
    const char *description;

    /**
     * The name of the metric beeing used
     */
    const char *unit;

    /**
     * Constant the result needs to be divided by
     * to get the result per unit
     */
    float divide;
  } gauger;

  /**
   * Contains extra data requiered by the #PERF_TALER_MINTDB_CMD_SAVE_ARRAY command
   */
  struct PERF_TALER_MINTDB_CMD_saveArrayDetails
  {
    /**
     * Number of items to save
     */
    unsigned int nb_saved;

    /**
     * Number of items already saved
     */
    unsigned int index;

    /**
     * Label of the loop it is attached to
     */
    const char *label_loop;
    unsigned int index_loop;

    /**
     * Label of the command exposing the item
     */
    const char *label_save;
    unsigned int index_save;

    /**
     * Array of data saved
     */
    struct PERF_TALER_MINTDB_Data *data_saved;

    /**
     * Type of the data that will be stored in @a data_saved, for
     * 'static' type checking.
     */
    enum PERF_TALER_MINTDB_Type type_saved;

  } save_array;

  /**
   * Extra data required for the #PERF_TALER_MINTDB_CMD_LOAD_ARRAY command
   */
  struct PERF_TALER_MINTDB_CMD_loadArrayDetails
  {
    /**
     * The loop in which the command is located
     */
    const char *label_loop;
    unsigned int index_loop;

    /**
     * Label of the command where the items were saved
     */
    const char *label_save;
    unsigned int index_save;

    /**
     * A permutation array used to randomize the order the items are loaded in
     */
    unsigned int *permutation;
  } load_array;

  /**
   * Contains data for the #PERF_TALER_MINTDB_CMD_LOAD_RANDOM command
   */
  struct PERF_TALER_MINTDB_CMD_loadRandomDetails
  {
    /**
     * The label of the #PERF_TALER_MINTDB_CMD_SAVE_ARRAY the items will be extracted from
     */
    const char *label_save;
    unsigned int index_save;
  } load_random;

  /**
   * Extra data requiered by the #PERF_TALER_MINTDB_CMD_INSERT_DENOMINATION command
   */
  struct PERF_TALER_MINTDB_CMD_insertDenominationDetails
  {
    /**
     * The label of the source of the denomination to insert
     */
    const char *label_denom;
    unsigned int index_denom;
  } insert_denomination;  
  
  /**
   * Extra data requiered by the #PERF_TALER_MINTDB_CMD_GET_DENOMINATION command
   */
  struct PERF_TALER_MINTDB_CMD_getDenominationDetails
  {
    /**
     * The label of the source of the denomination to check
     */
    const char *label_denom;
    unsigned int index_denom;
  } get_denomination;

  /**
   * Extra data requiered for the #PERF_TALER_MINTDB_CMD_INSERT_RESERVE command
   */
  struct PERF_TALER_MINTDB_CMD_insertReserveDetails
  {
    /**
     * The label of the source of the reserve to insert
     */
    const char *label_reserve;
    unsigned int index_reserve;
  } insert_reserve;

  /**
   * Extra data requiered for the #PERF_TALER_MINTDB_CMD_GET_RESERVE command
   */
  struct PERF_TALER_MINTDB_CMD_getReserveDetails
  {
    /**
     * The label of the source of the reserve to check
     */
    const char *label_reserve;
    unsigned int index_reserve;
  } get_reserve;

  /**
   * Extra data requiered for the #PERF_TALER_MINTDB_CMD_GET_RESERVE_HISTORY command
   */
  struct PERF_TALER_MINTDB_CMD_getReserveHistoryDetails
  {
    /**
     * The label of the source of the reserve to check
     */
    const char *label_reserve;
    unsigned int index_reserve;
  } get_reserve_history;

  /**
   * Extra data related to the #PERF_TALER_MINTDB_CMD_CREATE_WITHDRAW command
   */
  struct PERF_TALER_MINTDB_CMD_createWithdrawDetails
  {
    /**
     * label of the denomination key used to sign the coin
     */
    const char *label_dki;
    unsigned int index_dki;

    /**
     * label of the reserve the money to mint the coin comes from
     */
    const char *label_reserve;
    unsigned int index_reserve;
  } create_withdraw;

  /**
   * data requiered for the #PERF_TALER_MINTDB_CMD_INSERT_WITHDRAW
   */
  struct PERF_TALER_MINTDB_CMD_insertWithdrawDetails
  {
    /**
     * label of the source for the coin information
     */
    const char *label_coin;
    unsigned int index_coin;
  } insert_withdraw;

  /**
   * data requiered for the #PERF_TALER_MINTDB_CMD_GET_WITHDRAW
   */
  struct PERF_TALER_MINTDB_CMD_getWithdraw
  {
    /**
     * label of the source for the coin information
     */
    const char *label_coin;
    unsigned int index_coin;
  } get_withdraw;

  /**
   * Data requiered for the #PERF_TALER_MINTDB_CMD_GET_COIN_TRANSACTION command
   */
  struct PERF_TALER_MINTDB_CMD_getCoinTransactionDetails
  {
    /**
     * The coin which history is checked
     */
    const char *label_coin;
    unsigned int index_coin;
  } get_coin_transaction;

  /**
   * Data used by the #PERF_TALER_MINTDB_CMD_CREATE_DEPOSIT command
   */
  struct PERF_TALER_MINTDB_CMD_createDepositDetails
  {
    /**
     * Label of the source where the reserve used to create the coin is
     */
    const char *label_coin;
    unsigned int index_coin;
  } create_deposit;

  /**
   * Extra data requiered for the #PERF_TALER_MINTDB_CMD_INSERT_DEPOSIT command
   */
  struct PERF_TALER_MINTDB_CMD_insertDepositDetails
  {
    /**
     * The label of the source of the deposit to check
     */
    const char *label_deposit;
    unsigned int index_deposit;
  } insert_deposit;

  /**
   * Extra data requiered for the #PERF_TALER_MINTDB_CMD_GET_DEPOSIT command
   */
  struct PERF_TALER_MINTDB_CMD_getDepositDetails
  {
    /**
     * The label of the source of the deposit to check
     */
    const char *label_deposit;
    unsigned int index_deposit;
  } get_deposit;

 /**
   * Data requiered for the #PERF_TALER_MINTDB_CMD_GET_REFRESH_SESSION command
   */
  struct PERF_TALER_MINTDB_CMD_getRefreshSessionDetails
  {
    /**
     * label of the source of the hash of the session
     */
    const char *label_hash;
    unsigned int index_hash;
  } get_refresh_session;

  /**
   * Data requiered for the #PERF_TALER_MINTDB_CMD_INSERT_REFRESH_MELT command
   */
  struct PERF_TALER_MINTDB_CMD_insertRefreshMeltDetails
  {
    /**
     * The label of the hash of the refresh session
     */
    const char *label_hash;
    unsigned int index_hash;

    /**
     * The label of the coin to melt
     */
    const char *label_coin;
    unsigned int index_coin;
  } insert_refresh_melt;

  /**
   * Data requiered for the #PERF_TALER_MINTDB_CMD_GET_REFRESH_MELT command
   */
  struct PERF_TALER_MINTDB_CMD_getRefreshMeltDetails
  {
    /**
     * The label of the hash of the session
     */
    const char *label_hash;
    unsigned int index_hash;
  } get_refresh_melt;

  /**
   * Data requiered for the #PERF_TALER_MINTDB_CMD_INSERT_REFRESH_ORDER command
   */
  struct PERF_TALER_MINTDB_CMD_insertRefreshOrderDetails
  {
   /**
    * The refresh session hash
    */
   const char *label_hash;
    unsigned int index_hash;

   /**
    * The new coin denomination
    */
   const char *label_denom;
   unsigned int index_denom;
  } insert_refresh_order;

  /**
   * Data requiered for the #PERF_TALER_MINTDB_CMD_GET_REFRESH_ORDER command
   */
  struct PERF_TALER_MINTDB_CMD_getRefreshOrderDetails
  {
    /**
     * The session hash
     */
    const char *label_hash;
    unsigned int index_hash;

  } get_refresh_order;

  /**
   * Data requiered for the #PERF_TALER_MINTDB_CMD_INSERT_REFRESH_COMMIT_COIN command
   */
  struct PERF_TALER_MINTDB_CMD_insertRefreshCommitCoinDetails
  {
    /**
     * The refresh session hash
     */
    const char *label_hash;
    unsigned int index_hash;

  } insert_refresh_commit_coin;

  /**
   * Data requiered for the #PERF_TALER_MINTDB_CMD_GET_REFRESH_COMMIT_COIN command
   */
  struct PERF_TALER_MINTDB_CMD_getRefreshCommitCoinDetails
  {
    /**
     * The refresh session hash
     */
    const char *label_hash;
    unsigned int index_hash;

  } get_refresh_commit_coin;

  /**
   * Data requiered for the #PERF_TALER_MINTDB_CMD_INSERT_REFRESH_COMMIT_LINK command
   */
  struct PERF_TALER_MINTDB_CMD_insertRefreshCommitLinkDetails
  {
    /**
     * The refresh session hash
     */
    const char *label_hash;
    unsigned int index_hash;

  } insert_refresh_commit_link;

  /**
   * Data requiered by the #PERF_TALER_MINTDB_CMD_GET_REFRESH_COMMIT_LINK command
   */
  struct PERF_TALER_MINTDB_CMD_getRefreshCommitLinkDetails
  {
    /**
     * The refresh session hash
     */
    const char *label_hash;
    unsigned int index_hash;
  } get_refresh_commit_link;

  /**
   * Data requiered for the #PERF_TALER_MINTDB_CMD_GET_MELT_COMMITMENT command
   */
  struct PERF_TALER_MINTDB_CMD_getMeltCommitmentDaetails
  {
    /**
     * The refresh session hash
     */
    const char *label_hash;
    unsigned int index_hash;
  } get_melt_commitment;

  /**
   * Data requiered by the #PERF_TALER_MINTDB_CMD_INSERT_REFRESH_OUT command
   */
  struct PERF_TALER_MINTDB_CMD_insertRefreshOutDetails
  {
    /**
     * The refresh session hash
     */
    const char *label_hash;
    unsigned int index_hash;
  } insert_refresh_out;

  /**
   * Data requiered by the #PERF_TALER_MINTDB_CMD_GET_LINK_DATA_LIST command
   */
  struct PERF_TALER_MINTDB_CMD_getLinkDataListDetails
  {
    /**
     * The refresh session hash
     */
    const char *label_hash;
    unsigned int index_hash;
  } get_link_data_list;

  /**
   * Data requiered by the #PERF_TALER_MINTDB_CMD_GET_TRANSFER command
   */
  struct PERF_TALER_MINTDB_CMD_getTransferDetails
  {
    /**
     * The refresh session hash
     */
    const char *label_hash;
    unsigned int index_hash;
  } get_transfer;

};


/**
 * Command to be interpreted.
 */
struct PERF_TALER_MINTDB_Cmd
{
  /**
   *  Type of the command
   */
  enum PERF_TALER_MINTDB_CMD_Name command;

  /**
   * Label to refer to the command
   */
  const char *label;

  /**
   * Command specific data
   */
  union PERF_TALER_MINTDB_CMD_Details details;

  /**
   * Data easily accessible
   */
  struct PERF_TALER_MINTDB_Data exposed;
};


/**
 * Run a benchmark
 *
 * @param benchmark_name the name of the benchmark, displayed in the logs
 * @param configuration_file path to the taler configuration file to use
 * @param init the commands to use for the database initialisation,
 * if #NULL the standard initialization is used
 * @param benchmark the commands for the benchmark
 * @return GNUNET_OK upon success; GNUNET_SYSERR upon failure
 */
int
PERF_TALER_MINTDB_run_benchmark (const char *benchmark_name,
                                 const char *configuration_file,
                                 struct PERF_TALER_MINTDB_Cmd *init,
                                 struct PERF_TALER_MINTDB_Cmd *benchmark);


/**
 * Runs the command array @a cmd
 * using @a db_plugin to connect to the database
 *
 * @param db_plugin the connection to the database
 * @param cmd the commands to run
 */
int
PERF_TALER_MINTDB_interpret(
  struct TALER_MINTDB_Plugin *db_plugin,
  struct PERF_TALER_MINTDB_Cmd cmd[]);


/**
 * Check if the given command array is syntaxicly correct
 * This will check if the label are corrects but will not check if
 * they are pointing to an apropriate command.
 *
 * @param cmd the command array to check
 * @return #GNUNET_OK is @a cmd is correct; #GNUNET_SYSERR if it is'nt
 */
int
PERF_TALER_MINTDB_check (const struct PERF_TALER_MINTDB_Cmd *cmd);

#endif