summaryrefslogtreecommitdiff
path: root/src/mintdb/perf/perf_taler_mintdb_interpreter.h
blob: a201fd4a8c5a181fe1838956844c8afcf1a6d215 (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
#ifndef __PERF_TALER_MINTDB_INTERPRETER_H__
#define __PERF_TALER_MINTDB_INTERPRETER_H__

#include <sys/time.h>

#include <gnunet/platform.h>
#include <taler/taler_mintdb_lib.h>
#include <taler/taler_mintdb_plugin.h>


#define INIT_CMD_END(label) {.command = CMD_END, .name = label}

#define INIT_CMD_LOOP(label, _iter) { \
    .command = CMD_LOOP, \
    .name = label, \
    .details.loop = { \
       .max_iterations = _iter, \
       .curr_iteration = -1} \
    }

#define INIT_CMD_END_LOOP(label, _loopname) {.command = CMD_END_LOOP, .name = label, .details.end_loop.loop_start = _loopname}


#define INIT_CMD_GET_TIME(label) {.command = CMD_GET_TIME, .name = label}

#define INIT_CMD_GAUGER(label, _start_time, _stop_time, _description) {.command = CMD_GAUGER, .name = label, .details.gauger = {.start_time = _start_time, .end_time = _endtime, .description = _description} }

#define INIT_CMD_START_TRANSACTION(label) {.command = CMD_START_TRANSACTION, .name = label}

#define INIT_CMD_COMMIT_TRANSACTION(label) {.command = CMD_COMMIT_TRANSACTION, .name = label}



#define INIT_CMD_INSERT_DEPOSIT(label) {.command = CMD_INSERT_DEPOSIT, .name = label}

#define INIT_CMD_GET_DEPOSIT(label, _saved) {.command = CMD_GET_DEPOSIT, .name = label, .details.get_deposit.saved = _source }

#define INIT_CMD_SAVE_DEPOSIT(label, _loop, _save, _nb) {.command = CMD_SAVE_ARRAY, .name = label, .details.save_array = {.loop = _loop, .nb = _nb, .saved = _save, saved_type = DEPOSIT} }

#define INIT_CMD_LOAD_DEPOSIT(label, _loop, _save, _nb) {.command = CMD_LOAD_ARRAY, .name = label, .details.load_array = {.loop = _loop, .nb = _nb, .saved = _save} }



enum PERF_TALER_MINTDB_TYPE {
  DEPOSIT,
  TIME,
};

/**
 * Command to be interpreted.
 *
 */
struct PERF_TALER_MINTDB_CMD{

    enum {

        // Define the start of al command chain loop
        CMD_LOOP,
        // Define the end of a command chain loop
        CMD_END_LOOP,

        // All comand chain must hace this as their last command
        CMD_END,

        // Save the time at which the command was executed
        CMD_GET_TIME,

        // Upload performance to Gauger
        CMD_GAUGER,

        // Start a database transaction
        CMD_START_TRANSACTION,

        // End a database transaction
        CMD_COMMIT_TRANSACTION,

        // Insert a deposit into the database
        CMD_INSERT_DEPOSIT,

        // Check if a deposit is in the database
        CMD_GET_DEPOSIT,

        // Saves random deposits from a loop
        CMD_SAVE_ARRAY,

        // Load deposits saved earlyer
        CMD_LOAD_ARRAY,

    } command;

    const char *name; // label!

    // Contains command specific data.
    union {
        struct {
            const int max_iterations;
            int curr_iteration;
        } loop;

        struct {
            char loop_start[40];
        } end_loop;

        struct {
            char start_time[40];
            char stop_time[40];

            char description[40];
        } gauger;

        struct {
          /**
           * Comment!
           */
            unsigned int nb; // Number of deposits to save
            unsigned int index; // The number of deposits already saved
            char loop[40]; // The loop from which the data will be extracted
            char saved[40]; // The deposit saved
            enum PERF_TALER_MINTDB_TYPE saved_type;
            union NAME_IT_TOP_LEVEL {
              struct TALER_MINTDB_Deposit *deposit;
              struct timespec time;
            } *samples;
        } save_array;

        struct {
            int nb; //the number of deposits to save
            char loop[40];
            char saved[40]; // The command where the deposit were saved
            enum PERF_TALER_MINTDB_TYPE loaded_type;
            unsigned int *permutation; // A permutation array to randomize the order the deposits are loaded in
        } load_array;

        struct {
            char source[40];
        } get_deposit;


    } details;
    union  NAME_IT_TOP_LEVEL {
        struct TALER_MINTDB_Deposit *deposit;
        struct timespec time;
    } exposed;

    int exposed_used;
};


int
PERF_TALER_MINTDB_interprete(
    struct TALER_MINTDB_Plugin *db_plugin,
    struct TALER_MINTDB_Session *session, // add START_SESSION CMD
    struct PERF_TALER_MINTDB_CMD cmd[]);


#endif