New load_random command
This commit is contained in:
parent
7ad57d7a67
commit
ff7cb5edbb
@ -24,6 +24,8 @@
|
||||
#include "gauger.h"
|
||||
|
||||
|
||||
#define FIND_TEST(cmd, string, arg) \
|
||||
|
||||
/**
|
||||
* Represents the state of the interpreter
|
||||
*/
|
||||
@ -374,6 +376,26 @@ interpret_load_array (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Part of the interpreter specific to
|
||||
* #PERF_TALER_MINTDB_CMD_LOAD_RANDOM
|
||||
* Get a random element from a #PERF_TALER_MINTDB_CMD_SAVE_ARRAY and exposes it
|
||||
*/
|
||||
static void
|
||||
interpret_load_random (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
{
|
||||
unsigned int index;
|
||||
int save_index;
|
||||
|
||||
GNUNET_assert (0 <=
|
||||
(save_index = cmd_find (state->cmd,
|
||||
state->cmd[state->i].details.load_random.label_save)));
|
||||
index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
|
||||
state->cmd[save_index].details.save_array.nb_saved);
|
||||
state->cmd[state->i].exposed =
|
||||
data_copy (state->cmd[save_index].details.data_saved[index]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate over the commands, acting accordingly at each step
|
||||
*
|
||||
@ -382,7 +404,6 @@ interpret_load_array (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
static int
|
||||
interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
{
|
||||
|
||||
for (state->i=0; PERF_TALER_MINTDB_CMD_END != state->cmd[state->i].command; state->i++)
|
||||
{
|
||||
switch (state->cmd[state->i].command)
|
||||
@ -448,6 +469,7 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
case PERF_TALER_MINTDB_CMD_ABORT_TRANSACTION:
|
||||
state->plugin->rollback (state->plugin->cls,
|
||||
state->session);
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_SAVE_ARRAY:
|
||||
interpret_save_array (state);
|
||||
@ -457,6 +479,10 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
interpret_load_array (state);
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_LOAD_RANDOM:
|
||||
interprete_load_random(state);
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_INSERT_DEPOSIT:
|
||||
{
|
||||
int dki_index;
|
||||
@ -642,13 +668,14 @@ PERF_TALER_MINTDB_interpret (struct TALER_MINTDB_Plugin *db_plugin,
|
||||
|
||||
|
||||
/**
|
||||
* Initialize the database and run the 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
|
||||
* @return #GNUNET_OK upon success; GNUNET_SYSERR upon failure
|
||||
*/
|
||||
int
|
||||
PERF_TALER_MINTDB_run_benchmark (const char *benchmark_name,
|
||||
@ -752,8 +779,6 @@ PERF_TALER_MINTDB_run_benchmark (const char *benchmark_name,
|
||||
"Error connectiong to the database");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
ret = plugin->create_tables (plugin->cls,
|
||||
GNUNET_YES);
|
||||
if (GNUNET_OK != ret)
|
||||
@ -769,6 +794,9 @@ PERF_TALER_MINTDB_run_benchmark (const char *benchmark_name,
|
||||
{
|
||||
init = init_def;
|
||||
}
|
||||
if (GNUNET_SYSERR ==PERF_TALER_MINTDB_check (init))
|
||||
return GNUNET_SYSERR;
|
||||
|
||||
ret = PERF_TALER_MINTDB_interpret (plugin,
|
||||
init);
|
||||
if (GNUNET_OK != ret)
|
||||
@ -780,6 +808,8 @@ PERF_TALER_MINTDB_run_benchmark (const char *benchmark_name,
|
||||
/*
|
||||
* Running the benchmark
|
||||
*/
|
||||
if (GNUNET_SYSERR ==PERF_TALER_MINTDB_check (benchmark))
|
||||
return GNUNET_SYSERR;
|
||||
ret = PERF_TALER_MINTDB_interpret (plugin,
|
||||
benchmark);
|
||||
if (GNUNET_OK != ret)
|
||||
@ -808,3 +838,140 @@ PERF_TALER_MINTDB_run_benchmark (const char *benchmark_name,
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests if @a label is reference to a command of @a cmd
|
||||
* Prints an error containing @a desc if a problem occurs
|
||||
*
|
||||
* @param cmd the cmd array checked
|
||||
* @param label the label checked
|
||||
* @param i the index of the command beeing checked (used for error reporting
|
||||
* @param desc a description of the label checked
|
||||
*/
|
||||
static int
|
||||
find_test (const struct PERF_TALER_MINTDB_Cmd *cmd,
|
||||
const char *label,
|
||||
const unsigned int i,
|
||||
const char *desc)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = cmd_find (cmd, label);
|
||||
if (GNUNET_SYSERR == ret)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"Error at %s:index %d wrong label for %s",
|
||||
cmd[i].label,
|
||||
i,
|
||||
desc);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
unsigned int i;
|
||||
int ret = GNUNET_OK;
|
||||
|
||||
for (i = 0; PERF_TALER_MINTDB_CMD_END != cmd[i].command; i++)
|
||||
{
|
||||
int ret_loc = GNUNET_OK;
|
||||
switch (cmd[i].command)
|
||||
{
|
||||
case PERF_TALER_MINTDB_CMD_END_LOOP:
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.end_loop.label_loop,
|
||||
i,
|
||||
"label_loop");
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_GAUGER:
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.gauger.label_start,
|
||||
i,
|
||||
"label_start");
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_SAVE_ARRAY:
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.save_array.label_loop,
|
||||
i,
|
||||
"label_loop");
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.save_array.label_save,
|
||||
i,
|
||||
"label_save");
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_LOAD_ARRAY:
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.load_array.label_loop,
|
||||
i,
|
||||
"label_loop");
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.load_array.label_save,
|
||||
i,
|
||||
"label_save");
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_GET_DENOMINATION:
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.get_denomination.label_source,
|
||||
i,
|
||||
"label_source");
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_GET_RESERVE:
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.get_reserve.label_source,
|
||||
i,
|
||||
"label_source");
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_INSERT_DEPOSIT:
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.insert_deposit.label_dki,
|
||||
i,
|
||||
"label_dki");
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_GET_DEPOSIT:
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.get_deposit.label_source,
|
||||
i,
|
||||
"label_source");
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_INSERT_WITHDRAW:
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.insert_withdraw.label_dki,
|
||||
i,
|
||||
"label_dki");
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_GET_WITHDRAW:
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.get_withdraw.label_source,
|
||||
i,
|
||||
"label_source");
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
}
|
||||
if (GNUNET_OK == ret)
|
||||
ret = (GNUNET_SYSERR == ret_loc)?GNUNET_SYSERR:GNUNET_OK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -114,9 +114,10 @@
|
||||
* @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 [FIXME: need UNIT]
|
||||
*/
|
||||
#define PERF_TALER_MINTDB_INIT_CMD_GAUGER(_label, _label_start, _label_stop, _description, _divide) \
|
||||
#define PERF_TALER_MINTDB_INIT_CMD_GAUGER(_label, _label_start, _label_stop, _description, _unit, _divide) \
|
||||
{ \
|
||||
.command = PERF_TALER_MINTDB_CMD_GAUGER, \
|
||||
.label = _label, \
|
||||
@ -125,6 +126,7 @@
|
||||
.label_start = _label_start, \
|
||||
.label_stop = _label_stop, \
|
||||
.description = _description, \
|
||||
.unit = _unit \
|
||||
.divide = _divide, \
|
||||
} \
|
||||
}
|
||||
@ -344,6 +346,7 @@ struct PERF_TALER_MINTDB_Data
|
||||
|
||||
/**
|
||||
* Storage for a variety of data type
|
||||
* The data saved should match #type
|
||||
*/
|
||||
union PERF_TALER_MINTDB_Memory
|
||||
{
|
||||
@ -412,7 +415,7 @@ enum PERF_TALER_MINTDB_CMD_Name
|
||||
PERF_TALER_MINTDB_CMD_COMMIT_TRANSACTION,
|
||||
|
||||
/**
|
||||
* Abort a transaction
|
||||
* Abort a transaction started with #PERF_TALER_MINTDB_CMD_START_TRANSACTION
|
||||
*/
|
||||
PERF_TALER_MINTDB_CMD_ABORT_TRANSACTION,
|
||||
|
||||
@ -422,10 +425,17 @@ enum PERF_TALER_MINTDB_CMD_Name
|
||||
PERF_TALER_MINTDB_CMD_SAVE_ARRAY,
|
||||
|
||||
/**
|
||||
* Load deposits saved earlier
|
||||
* 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,
|
||||
|
||||
/**
|
||||
* Insert a deposit into the database
|
||||
*/
|
||||
@ -510,7 +520,7 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
/**
|
||||
* Details about the #PERF_TALER_MINTDB_CMD_GAUGER command
|
||||
*/
|
||||
struct PERF_TALER_MINTDB_CMD_GaugerDetails
|
||||
struct PERF_TALER_MINTDB_CMD_gaugerDetails
|
||||
{
|
||||
/**
|
||||
* Label of the starting timestamp
|
||||
@ -527,6 +537,11 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
*/
|
||||
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
|
||||
@ -585,6 +600,17 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
} 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;
|
||||
} load_random;
|
||||
|
||||
/**
|
||||
* Data used by the #PERF_TALER_MINTDB_CMD_INSERT_DEPOSIT command
|
||||
*/
|
||||
@ -648,6 +674,17 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
*/
|
||||
const char *label_reserve;
|
||||
} insert_withdraw;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
struct PERF_TALER_MINTDB_CMD_getWithdraw
|
||||
{
|
||||
/**
|
||||
* label of the source for the withdra information
|
||||
*/
|
||||
const char *label_source;
|
||||
} get_withdraw;
|
||||
};
|
||||
|
||||
|
||||
@ -706,4 +743,16 @@ 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
|
||||
|
Loading…
Reference in New Issue
Block a user