Initial commit for mintdb performance analysis
This commit is contained in:
parent
55568e682b
commit
d5f6b064f5
42
src/mintdb/perf/perf_taler_mintdb.c
Normal file
42
src/mintdb/perf/perf_taler_mintdb.c
Normal file
@ -0,0 +1,42 @@
|
||||
#include "perf_taler_mintdb_interpreter.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char ** argv)
|
||||
{
|
||||
|
||||
struct PERF_TALER_MINTDB_CMD test[] =
|
||||
{
|
||||
INIT_CMD_LOOP("loop_db_init_deposit",100000),
|
||||
INIT_CMD_START_TRANSACTION("start_transaction_init"),
|
||||
INIT_CMD_INSERT_DEPOSIT("init_deposit_insert"),
|
||||
INIT_CMD_COMMIT_TRANSACTION("commit_transaction_init"),
|
||||
INIT_CMD_END_LOOP("endloop_init_deposit","loop_db_init_deposit"),
|
||||
|
||||
|
||||
INIT_CMD_END("end")
|
||||
};
|
||||
|
||||
struct GNUNET_CONFIGURATION_Handle *config = GNUNET_CONFIGURATION_create();
|
||||
|
||||
// FIXME Add data to the config handler to be able to connect to the database
|
||||
|
||||
struct TALER_MINTDB_Plugin *plugin = TALER_MINTDB_plugin_load(config);
|
||||
struct TALER_MINTDB_Session *session = plugin->get_session(plugin->cls, GNUNET_YES);
|
||||
|
||||
plugin->create_tables(plugin->cls, GNUNET_YES);
|
||||
|
||||
|
||||
PERF_TALER_MINTDB_interprete(plugin, session, test);
|
||||
|
||||
|
||||
plugin->drop_temporary(plugin->cls, session);
|
||||
|
||||
// Free the session ??
|
||||
|
||||
TALER_MINTDB_plugin_unload(plugin);
|
||||
return GNUNET_OK;
|
||||
}
|
258
src/mintdb/perf/perf_taler_mintdb_init.c
Normal file
258
src/mintdb/perf/perf_taler_mintdb_init.c
Normal file
@ -0,0 +1,258 @@
|
||||
#include <gnunet/platform.h>
|
||||
#include <gnunet/gnunet_crypto_lib.h>
|
||||
#include <gnunet/gnunet_signatures.h>
|
||||
|
||||
#include <taler/taler_mintdb_plugin.h>
|
||||
#include <taler/taler_signatures.h>
|
||||
#include <taler/taler_amount_lib.h>
|
||||
|
||||
|
||||
#define CURRENCY "EUR\0\0\0\0\0\0\0\0"
|
||||
|
||||
struct TALER_MINTDB_CollectableBlindcoin *
|
||||
init_CollectableBlindcoin(){
|
||||
struct TALER_MINTDB_CollectableBlindcoin *coin = GNUNET_malloc(sizeof(*coin));
|
||||
|
||||
struct GNUNET_CRYPTO_EddsaPrivateKey *reserve_sig_key = GNUNET_CRYPTO_eddsa_key_create();
|
||||
struct GNUNET_CRYPTO_rsa_PrivateKey *denomination_key = GNUNET_CRYPTO_rsa_private_key_create(512);
|
||||
|
||||
|
||||
coin->denom_pub.rsa_public_key = GNUNET_CRYPTO_rsa_private_key_get_public(denomination_key);
|
||||
GNUNET_CRYPTO_eddsa_key_get_public(reserve_sig_key, &(coin->reserve_pub.eddsa_pub));
|
||||
|
||||
|
||||
//TODO Randomise the amount that is deposited and apply a fee subsequently
|
||||
|
||||
coin->amount_with_fee = (struct TALER_Amount) {1, 1, CURRENCY};
|
||||
coin->withdraw_fee = (struct TALER_Amount) {0, 1, CURRENCY};
|
||||
|
||||
|
||||
int random_int = rand();
|
||||
coin->sig.rsa_signature = GNUNET_CRYPTO_rsa_sign(denomination_key, &random_int, sizeof(random_int));
|
||||
GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK , &(coin->h_coin_envelope));
|
||||
|
||||
void *purpose = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + sizeof(int));
|
||||
((struct GNUNET_CRYPTO_EccSignaturePurpose *)purpose)->size = sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + sizeof(int);
|
||||
((struct GNUNET_CRYPTO_EccSignaturePurpose *)purpose)->purpose = GNUNET_SIGNATURE_PURPOSE_TEST;
|
||||
*((int *)(purpose + sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose))) = random_int;
|
||||
|
||||
GNUNET_CRYPTO_eddsa_sign(reserve_sig_key, purpose, &coin->reserve_sig.eddsa_signature);
|
||||
|
||||
|
||||
|
||||
GNUNET_free(reserve_sig_key);
|
||||
GNUNET_CRYPTO_rsa_private_key_free(denomination_key);
|
||||
return coin;
|
||||
}
|
||||
|
||||
|
||||
struct TALER_MINTDB_Reserve *
|
||||
init_Reserve(){
|
||||
struct TALER_MINTDB_Reserve *reserve = GNUNET_malloc(sizeof(*reserve));
|
||||
struct GNUNET_CRYPTO_EddsaPrivateKey *reserve_priv = GNUNET_CRYPTO_eddsa_key_create();
|
||||
|
||||
GNUNET_CRYPTO_eddsa_key_get_public(reserve_priv , &(reserve->pub.eddsa_pub));
|
||||
|
||||
|
||||
reserve->balance = (struct TALER_Amount){1, 1, CURRENCY};
|
||||
reserve->expiry = GNUNET_TIME_absolute_get_forever_();
|
||||
|
||||
GNUNET_free(reserve_priv);
|
||||
return reserve;
|
||||
}
|
||||
|
||||
|
||||
struct TALER_MINTDB_RefreshSession *
|
||||
init_Refresh_session(){
|
||||
struct TALER_MINTDB_RefreshSession *refresh_session = GNUNET_malloc(sizeof(*refresh_session));
|
||||
|
||||
refresh_session->noreveal_index = 1;
|
||||
refresh_session->num_oldcoins = 1;
|
||||
refresh_session->num_newcoins = 1;
|
||||
|
||||
return refresh_session;
|
||||
}
|
||||
|
||||
|
||||
struct TALER_MINTDB_Deposit *
|
||||
init_Deposit(){
|
||||
static int transaction_id = 0;
|
||||
|
||||
struct TALER_MINTDB_Deposit *deposit = GNUNET_malloc(sizeof(*deposit));
|
||||
|
||||
deposit-> transaction_id = transaction_id;
|
||||
transaction_id++;
|
||||
|
||||
|
||||
//TODO Randomize the amount that is deposited
|
||||
|
||||
deposit->amount_with_fee = (struct TALER_Amount) {1, 1, CURRENCY};
|
||||
deposit->deposit_fee = (struct TALER_Amount) {0, 1, CURRENCY};
|
||||
|
||||
deposit->timestamp = GNUNET_TIME_absolute_get();
|
||||
deposit->refund_deadline = GNUNET_TIME_absolute_get();
|
||||
|
||||
GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &deposit->h_contract);
|
||||
GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &deposit->h_wire);
|
||||
|
||||
// Coin Spend Signature
|
||||
{
|
||||
struct GNUNET_CRYPTO_EddsaSignature sig;
|
||||
|
||||
struct GNUNET_CRYPTO_EddsaPrivateKey *p_eddsa_prvt = GNUNET_CRYPTO_eddsa_key_create();
|
||||
void *prp = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)+sizeof(int));
|
||||
*((struct GNUNET_CRYPTO_EccSignaturePurpose *)prp) =(struct GNUNET_CRYPTO_EccSignaturePurpose) {sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)+sizeof(int), GNUNET_SIGNATURE_PURPOSE_TEST};
|
||||
|
||||
|
||||
GNUNET_CRYPTO_eddsa_sign(p_eddsa_prvt, (struct GNUNET_CRYPTO_EccSignaturePurpose *) prp, &sig);
|
||||
|
||||
deposit->csig.eddsa_signature = sig;
|
||||
|
||||
GNUNET_free(p_eddsa_prvt);
|
||||
}
|
||||
|
||||
// Merchant Key
|
||||
{
|
||||
struct GNUNET_CRYPTO_EddsaPublicKey eddsa_pub;
|
||||
struct GNUNET_CRYPTO_EddsaPrivateKey *p_eddsa_prv = GNUNET_CRYPTO_eddsa_key_create();
|
||||
|
||||
GNUNET_CRYPTO_eddsa_key_get_public(p_eddsa_prv, &eddsa_pub);
|
||||
|
||||
deposit->merchant_pub.eddsa_pub = eddsa_pub;
|
||||
|
||||
GNUNET_free(p_eddsa_prv);
|
||||
}
|
||||
|
||||
// Coin
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
struct GNUNET_CRYPTO_EddsaPublicKey eddsa_pub;
|
||||
struct GNUNET_CRYPTO_EddsaPrivateKey *p_eddsa_prvt = GNUNET_CRYPTO_eddsa_key_create();
|
||||
|
||||
GNUNET_CRYPTO_eddsa_key_get_public(p_eddsa_prvt, &eddsa_pub);
|
||||
|
||||
deposit->coin.coin_pub.eddsa_pub = eddsa_pub;
|
||||
|
||||
GNUNET_free(p_eddsa_prvt);
|
||||
}
|
||||
|
||||
{
|
||||
struct GNUNET_CRYPTO_rsa_PrivateKey *p_rsa_prv = GNUNET_CRYPTO_rsa_private_key_create(128);
|
||||
struct GNUNET_CRYPTO_rsa_PublicKey *p_rsa_pub = GNUNET_CRYPTO_rsa_private_key_get_public(p_rsa_prv);
|
||||
|
||||
deposit->coin.denom_pub.rsa_public_key = p_rsa_pub;
|
||||
|
||||
|
||||
|
||||
deposit->coin.denom_sig.rsa_signature = GNUNET_CRYPTO_rsa_sign(p_rsa_prv,
|
||||
(void *) &(deposit->coin.coin_pub.eddsa_pub),
|
||||
sizeof(&(deposit->coin.coin_pub.eddsa_pub)));
|
||||
|
||||
GNUNET_CRYPTO_rsa_private_key_free(p_rsa_prv);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return deposit;
|
||||
}
|
||||
|
||||
|
||||
struct TALER_MINTDB_DenominationKeyIssueInformation *
|
||||
init_denomination(){
|
||||
struct TALER_MINTDB_DenominationKeyIssueInformation *dki = GNUNET_malloc(sizeof(&dki));
|
||||
|
||||
|
||||
dki->denom_priv.rsa_private_key
|
||||
= GNUNET_CRYPTO_rsa_private_key_create (128);
|
||||
GNUNET_assert (NULL != dki->denom_priv.rsa_private_key);
|
||||
dki->denom_pub.rsa_public_key
|
||||
= GNUNET_CRYPTO_rsa_private_key_get_public (dki->denom_priv.rsa_private_key);
|
||||
GNUNET_CRYPTO_rsa_public_key_hash (dki->denom_pub.rsa_public_key,
|
||||
&dki->issue.denom_hash);
|
||||
|
||||
struct GNUNET_CRYPTO_EddsaPrivateKey *master_prvt =
|
||||
GNUNET_CRYPTO_eddsa_key_create();
|
||||
|
||||
struct GNUNET_CRYPTO_EddsaPublicKey master_pub;
|
||||
|
||||
GNUNET_CRYPTO_eddsa_key_get_public(master_prvt, &master_pub);
|
||||
dki->issue.master.eddsa_pub = master_pub;
|
||||
|
||||
struct GNUNET_TIME_Absolute anchor = GNUNET_TIME_absolute_get();
|
||||
|
||||
dki->issue.start = GNUNET_TIME_absolute_hton (anchor);
|
||||
dki->issue.expire_withdraw =
|
||||
GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_add (anchor,
|
||||
GNUNET_TIME_relative_get_hour_()));
|
||||
dki->issue.expire_spend =
|
||||
GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_add (anchor,
|
||||
GNUNET_TIME_relative_get_hour_()));
|
||||
dki->issue.expire_legal =
|
||||
GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_add (anchor,
|
||||
GNUNET_TIME_relative_get_hour_()));
|
||||
|
||||
struct TALER_Amount amount = {.value = 1, .fraction = 1, .currency = CURRENCY};
|
||||
|
||||
TALER_amount_hton (&dki->issue.value, &amount);
|
||||
TALER_amount_hton (&dki->issue.fee_withdraw, &amount);
|
||||
TALER_amount_hton (&dki->issue.fee_deposit, &amount);
|
||||
TALER_amount_hton (&dki->issue.fee_refresh, &amount);
|
||||
dki->issue.purpose.purpose = htonl (TALER_SIGNATURE_MASTER_DENOMINATION_KEY_VALIDITY);
|
||||
dki->issue.purpose.size = htonl (sizeof (struct TALER_MINTDB_DenominationKeyIssueInformation) -
|
||||
offsetof (struct TALER_MINTDB_DenominationKeyIssueInformation,
|
||||
issue.purpose));
|
||||
GNUNET_assert (GNUNET_OK ==
|
||||
GNUNET_CRYPTO_eddsa_sign (master_prvt,
|
||||
&dki->issue.purpose,
|
||||
&dki->issue.signature.eddsa_signature));
|
||||
|
||||
return dki;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Destructors
|
||||
|
||||
|
||||
int
|
||||
free_deposit(struct TALER_MINTDB_Deposit *deposit){
|
||||
GNUNET_free(deposit->coin.denom_pub.rsa_public_key);
|
||||
GNUNET_free(deposit->coin.denom_sig.rsa_signature);
|
||||
|
||||
GNUNET_free(deposit);
|
||||
|
||||
return GNUNET_OK;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
free_coin(struct TALER_MINTDB_CollectableBlindcoin *coin){
|
||||
GNUNET_free(coin->sig.rsa_signature);
|
||||
GNUNET_free(coin->denom_pub.rsa_public_key);
|
||||
|
||||
GNUNET_free(coin);
|
||||
|
||||
return GNUNET_OK;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
free_denomination(struct TALER_MINTDB_DenominationKeyIssueInformation *dki){
|
||||
GNUNET_free(dki->denom_priv.rsa_private_key);
|
||||
GNUNET_free(dki->denom_pub.rsa_public_key);
|
||||
|
||||
GNUNET_free(dki);
|
||||
|
||||
return GNUNET_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
38
src/mintdb/perf/perf_taler_mintdb_init.h
Normal file
38
src/mintdb/perf/perf_taler_mintdb_init.h
Normal file
@ -0,0 +1,38 @@
|
||||
#ifndef __PERF_TALER_MINTDB_INIT_H___
|
||||
#define __PERF_TALER_MINTDB_INIT_H___
|
||||
|
||||
|
||||
#include <gnunet/platform.h>
|
||||
|
||||
#include <taler/taler_mintdb_lib.h>
|
||||
#include <taler/taler_mintdb_plugin.h>
|
||||
|
||||
|
||||
#define CURRENCY "EUR\0\0\0\0\0\0\0\0"
|
||||
|
||||
|
||||
struct TALER_MINTDB_CollectableBlindcoin *
|
||||
init_collectableBlindcoin();
|
||||
|
||||
struct TALER_MINTDB_RefreshSession *
|
||||
init_refresh_session();
|
||||
|
||||
struct TALER_MINTDB_Deposit *
|
||||
init_deposit(int transaction_id);
|
||||
|
||||
struct TALER_MINTDB_DenominationKeyIssueInformation *
|
||||
init_denomination();
|
||||
|
||||
|
||||
|
||||
int
|
||||
free_deposit(struct TALER_MINTDB_Deposit *deposit);
|
||||
|
||||
int
|
||||
free_collectableBlindcoin(struct TALER_MINTDB_CollectableBlindcoin);
|
||||
|
||||
int
|
||||
free_denomination(struct TALER_MINTDB_DenominationKeyIssueInformation *dki);
|
||||
|
||||
|
||||
#endif
|
317
src/mintdb/perf/perf_taler_mintdb_interpreter.c
Normal file
317
src/mintdb/perf/perf_taler_mintdb_interpreter.c
Normal file
@ -0,0 +1,317 @@
|
||||
#include "perf_taler_mintdb_interpreter.h"
|
||||
|
||||
#include "perf_taler_mintdb_init.h"
|
||||
|
||||
#include <gauger.h>
|
||||
|
||||
|
||||
/**
|
||||
* Finds the first command in cmd with the name search
|
||||
*
|
||||
* \return the index of the first command with name search
|
||||
* GNUNET_SYSERR if none found
|
||||
*/
|
||||
static int
|
||||
cmd_find(const struct PERF_TALER_MINTDB_CMD *cmd, const char *search)
|
||||
{
|
||||
int i = 0;
|
||||
while (0)
|
||||
{
|
||||
if (cmd[i].command == CMD_END)
|
||||
{
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
|
||||
if (0 != strcmp(cmd[i].name, search))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Initialization of a command array
|
||||
static int
|
||||
cmd_init(struct PERF_TALER_MINTDB_CMD cmd[])
|
||||
{
|
||||
int i = 0;
|
||||
while (cmd[i].command != CMD_END)
|
||||
{
|
||||
switch (cmd[i].command)
|
||||
{
|
||||
case CMD_SAVE_ARRAY:
|
||||
|
||||
// Initialization is done differently depending of the type saved
|
||||
switch (cmd[i].details.save_array.saved_type)
|
||||
{
|
||||
case DEPOSIT:
|
||||
cmd[i].details.save_array.saved_data.deposit =
|
||||
GNUNET_malloc(cmd[i].details.save_array.nb*
|
||||
sizeof(*cmd[i].details.save_array.saved_data.deposit));
|
||||
break;
|
||||
case TIME:
|
||||
cmd[i].details.save_array.saved_data.time =
|
||||
GNUNET_malloc(cmd[i].details.save_array.nb*
|
||||
sizeof(*cmd[i].details.save_array.saved_data.time));
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case CMD_LOAD_ARRAY:
|
||||
cmd[i].details.load_array.permutation =
|
||||
GNUNET_CRYPTO_random_permute(
|
||||
GNUNET_CRYPTO_QUALITY_WEAK,
|
||||
cmd[i].details.load_array.nb);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return GNUNET_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Free the memory of the command chain
|
||||
*/
|
||||
static int
|
||||
cmd_clean(struct PERF_TALER_MINTDB_CMD cmd[])
|
||||
{
|
||||
int i = 0;
|
||||
while (cmd[i].command != CMD_END)
|
||||
{
|
||||
switch (cmd[i].command)
|
||||
{
|
||||
case CMD_SAVE_ARRAY:
|
||||
{
|
||||
int j;
|
||||
switch (cmd[i].details.save_array.saved_type)
|
||||
{
|
||||
case DEPOSIT:
|
||||
for (j = 0; j < cmd[i].details.save_array.nb; j++)
|
||||
{
|
||||
free_deposit(cmd[i].details.save_array.saved_data.deposit[j]);
|
||||
cmd[i].details.save_array.saved_data.deposit[j] = NULL;
|
||||
}
|
||||
GNUNET_free(cmd[i].details.save_array.saved_data.deposit);
|
||||
cmd[i].details.save_array.saved_data.deposit = NULL;
|
||||
break;
|
||||
case TIME:
|
||||
GNUNET_free(cmd[i].details.save_array.saved_data.time);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
case CMD_INSERT_DEPOSIT:
|
||||
free_deposit(cmd[i].exposed.deposit);
|
||||
break;
|
||||
|
||||
case CMD_LOAD_ARRAY:
|
||||
GNUNET_free(cmd[i].details.load_array.permutation);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return GNUNET_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
static int
|
||||
interprete(struct TALER_MINTDB_Plugin *db_plugin,
|
||||
struct TALER_MINTDB_Session*session,
|
||||
struct PERF_TALER_MINTDB_CMD cmd[])
|
||||
{
|
||||
int i=0;
|
||||
while (0){
|
||||
switch (cmd[i].command)
|
||||
{
|
||||
case CMD_END:
|
||||
return GNUNET_YES;
|
||||
break;
|
||||
|
||||
case CMD_LOOP:
|
||||
cmd[i].details.loop.curr_iteration++;
|
||||
break;
|
||||
|
||||
case CMD_END_LOOP:
|
||||
{
|
||||
int jump = cmd_find(cmd, cmd[i].details.end_loop.loop_start);
|
||||
zf (cmd[jump].details.loop.max_iterations > cmd[jump].details.loop.curr_iteration)
|
||||
{
|
||||
i = jump -1;
|
||||
}else{
|
||||
int j;
|
||||
// For each command in the loop
|
||||
for (j = 0; j <i; j++){
|
||||
// If the exposed variable has not been copied
|
||||
if (!cmd[j].exposed_used)
|
||||
{
|
||||
cmd[j].exposed_used = 0;
|
||||
// It is freed
|
||||
switch (cmd[j].command){
|
||||
case CMD_INSERT_DEPOSIT:
|
||||
free_deposit(cmd[j].exposed.deposit);
|
||||
cmd[j].exposed.deposit = NULL;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case CMD_GET_TIME:
|
||||
clock_gettime(CLOCK_MONOTONIC, &cmd[i].exposed.time);
|
||||
break;
|
||||
|
||||
|
||||
case CMD_GAUGER:
|
||||
{
|
||||
int start_index = cmd_find(cmd, cmd[i].details.gauger.start_time);
|
||||
int stop_index = cmd_find(cmd, cmd[i].details.gauger.stop_time );
|
||||
struct timespec start= cmd[start_index].exposed.time;
|
||||
struct timespec stop = cmd[stop_index].exposed.time;
|
||||
|
||||
unsigned long elapsed_ms = (start.tv_sec - stop.tv_sec)*1000 + (start.tv_nsec - stop.tv_nsec)/1000000;
|
||||
|
||||
GAUGER("MINTDB", cmd[i].details.gauger.description, elapsed_ms, "milliseconds");
|
||||
}
|
||||
break;
|
||||
|
||||
case CMD_START_TRANSACTION:
|
||||
db_plugin->start(db_plugin->cls, session);
|
||||
break;
|
||||
|
||||
|
||||
case CMD_COMMIT_TRANSACTION:
|
||||
db_plugin->commit(db_plugin->cls, session);
|
||||
break;
|
||||
|
||||
|
||||
case CMD_INSERT_DEPOSIT:
|
||||
{
|
||||
struct TALER_MINTDB_Deposit *deposit = init_deposit(0);
|
||||
db_plugin->insert_deposit(db_plugin->cls, session, deposit);
|
||||
|
||||
cmd[i].exposed.deposit = deposit;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case CMD_GET_DEPOSIT:
|
||||
{
|
||||
int source_index = cmd_find(cmd, cmd[i].details.get_deposit.source); // Find the source location
|
||||
struct TALER_MINTDB_Deposit *deposit = cmd[source_index].exposed.deposit; // Get the deposit from the source
|
||||
db_plugin->have_deposit(db_plugin->cls, session, deposit);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case CMD_SAVE_ARRAY:
|
||||
{
|
||||
// Array initialization on first loop iteration
|
||||
if (cmd[cmd_find(cmd, cmd[i].details.save_array.loop)].details.loop.curr_iteration == 0)
|
||||
{
|
||||
cmd[i].details.save_array.index = 0;
|
||||
}
|
||||
|
||||
int loop_index = cmd_find(cmd, cmd[i].details.save_array.loop);
|
||||
int proba = cmd[loop_index].details.loop.max_iterations / cmd[i].details.save_array.nb;
|
||||
int rnd = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, proba);
|
||||
|
||||
// If there is a lesser or equal number of iteration next than room remain in the array
|
||||
if ((cmd[loop_index].details.loop.max_iterations - cmd[loop_index].details.loop.curr_iteration <=
|
||||
cmd[i].details.save_array.nb - cmd[i].details.save_array.index) ||
|
||||
(rnd == 0 && cmd[i].details.save_array.index < cmd[i].details.save_array.nb))
|
||||
{
|
||||
|
||||
// We automaticly save the whatever we need to
|
||||
switch (cmd[i].details.save_array.saved_type){
|
||||
case DEPOSIT:
|
||||
cmd[i].details.save_array.saved_data.deposit[cmd[i].details.save_array.index] =
|
||||
cmd[cmd_find(cmd, cmd[i].details.save_array.saved)].exposed.deposit;
|
||||
break;
|
||||
case TIME:
|
||||
cmd[i].details.save_array.saved_data.deposit[cmd[i].details.save_array.index] =
|
||||
cmd[cmd_find(cmd, cmd[i].details.save_array.saved)].exposed.deposit;
|
||||
break;
|
||||
}
|
||||
cmd[i].details.save_array.index++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case CMD_LOAD_ARRAY:
|
||||
{
|
||||
|
||||
int loop_index = cmd_find(cmd, cmd[i].details.load_array.loop);
|
||||
int save_index = cmd_find(cmd, cmd[i].details.load_array.saved);
|
||||
switch (cmd[i].details.load_array.loaded_type){
|
||||
case DEPOSIT:
|
||||
cmd[i].exposed.deposit = cmd[save_index].details.save_array.saved_data.deposit[
|
||||
cmd[i].details.load_array.permutation[
|
||||
cmd[loop_index].details.loop.curr_iteration
|
||||
]
|
||||
];
|
||||
break;
|
||||
|
||||
case TIME:
|
||||
cmd[i].exposed.time = cmd[save_index].details.save_array.saved_data.time[
|
||||
cmd[i].details.load_array.permutation[
|
||||
cmd[loop_index].details.loop.curr_iteration
|
||||
]
|
||||
];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return GNUNET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the commands given in cmd, working with
|
||||
* the database referenced by db_plugin
|
||||
*/
|
||||
int
|
||||
PERF_TALER_MINTDB_interprete(struct TALER_MINTDB_Plugin *db_plugin,
|
||||
struct TALER_MINTDB_Session *session,
|
||||
struct PERF_TALER_MINTDB_CMD cmd[])
|
||||
{
|
||||
|
||||
// Initializing commands
|
||||
cmd_init(cmd);
|
||||
|
||||
// Running the interpreter
|
||||
interprete(db_plugin, session, cmd);
|
||||
|
||||
// Cleaning the memory
|
||||
cmd_clean(cmd);
|
||||
|
||||
return GNUNET_YES;
|
||||
|
||||
}
|
147
src/mintdb/perf/perf_taler_mintdb_interpreter.h
Normal file
147
src/mintdb/perf/perf_taler_mintdb_interpreter.h
Normal file
@ -0,0 +1,147 @@
|
||||
#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_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_END(label) {.command = CMD_END, .name = label}
|
||||
|
||||
#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;
|
||||
|
||||
char name[40];
|
||||
|
||||
// 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 {
|
||||
int nb; // Number of deposits to save
|
||||
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 {
|
||||
struct TALER_MINTDB_Deposit **deposit;
|
||||
struct timespec *time;
|
||||
} saved_data;
|
||||
} 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 {
|
||||
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,
|
||||
struct PERF_TALER_MINTDB_CMD cmd[]);
|
||||
|
||||
|
||||
#endif
|
17
src/mintdb/perf/perf_taler_mintdb_values.h
Normal file
17
src/mintdb/perf/perf_taler_mintdb_values.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef __PERF_TALER_MINTDB__VALUES_H__
|
||||
#define __PERF_TALER_MINTDB__VALUES_H__
|
||||
|
||||
|
||||
|
||||
#define NB_DEPOSIT_INIT 100000
|
||||
#define NB_DEPOSIT_GET 1000
|
||||
#define NB_DEPOSIT_MARGIN 10000
|
||||
|
||||
#define NB_BLINDCOIN_INIT 100000
|
||||
|
||||
|
||||
// Temporary macro to compile
|
||||
#define GAUGER(a,b,c,d)
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user