Skip to content

Commit

Permalink
Merge branch 'master' into add-author-hlaimer
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes99 authored Apr 22, 2023
2 parents 985a0cb + 7b62d59 commit afaca47
Show file tree
Hide file tree
Showing 171 changed files with 4,130 additions and 2,472 deletions.
3 changes: 1 addition & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ task:
freebsd_instance:
cpu: 4
memory: 8G
image_family: freebsd-12-3
image_family: freebsd-12-4

- name: 😈 FreeBSD 13
freebsd_instance:
Expand Down Expand Up @@ -156,7 +156,6 @@ task:
brew tap homebrew/services
brew update # Work around for [Homebrew Services issue 206](https://github.com/Homebrew/homebrew-services/issues/206)
brew postinstall dbus
brew services stop d-bus; brew services start d-bus # Workaround for dbus socket issues on cirrus
# export DBUS_LAUNCHD_SESSION_BUS_SOCKET=$(find /private/tmp/com.apple.launchd*/unix_domain_listener | xargs ls -Art | tail -n1) # workaround for cirrus
# launchctl setenv DBUS_LAUNCHD_SESSION_BUS_SOCKET $DBUS_LAUNCHD_SESSION_BUS_SOCKET
echo $DBUS_LAUNCHD_SESSION_BUS_SOCKET
Expand Down
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

*.sh text eol=lf
*.awk text eol=lf
*.java text eol=lf

*.bat text eol=crlf
*.cmd text eol=crlf
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/macOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ jobs:
brew tap homebrew/services
brew update # Work around for [Homebrew Services issue 206](https://github.com/Homebrew/homebrew-services/issues/206)
brew postinstall dbus
brew services stop d-bus; brew services start d-bus
echo $DBUS_LAUNCHD_SESSION_BUS_SOCKET
launchctl getenv DBUS_LAUNCHD_SESSION_BUS_SOCKET
cmake -E make_directory ${{runner.workspace}}/libelektra/build
Expand Down
5 changes: 5 additions & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ do_benchmark (cmp)
do_benchmark (createkeys)
do_benchmark (memoryleak)
do_benchmark (deepdup)
do_benchmark (diff)
do_benchmark (changetracking)

# exclude storage and KDB benchmark from mingw
if (NOT WIN32)
Expand Down Expand Up @@ -54,3 +56,6 @@ endif (ENABLE_OPTIMIZATIONS AND NOT WIN32)

add_executable (benchmark_plugingetset plugingetset.c)
target_link_elektra (benchmark_plugingetset elektra-core elektra-kdb)

target_link_elektra (benchmark_diff elektra-kdb)
target_link_elektra (benchmark_changetracking elektra-kdb)
27 changes: 27 additions & 0 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,33 @@ which will run the `callgrind` tool of Valgrind on it.
The old STATISTICS file is no longer used and will be
removed with this commit.

# changetracking

The changetracking benchmark evaluates the performance with changetracking enabled in KDB.
For it to work, you first have to load at least one plugin that utilizes changetracking.

A very simple case would be the `dbus` plugin:

```sh
kdb set system:/hook/notification/send/plugins/#0 dbus
```

You can then watch its output with

```sh
dbus-monitor --session "interface='org.libelektra'"
```

The output of a single benchmark is a single semicolon seperated line `time it took kdbSet to insert all keys;time it took kdbSet to update the keys`.
The time is measured in microseconds.

This benchmark has several command-line options:

- `--key-count <keys>`: how many keys should be generated (default 5000)
- `--harmonize-names`: all key-values and -names have the same length
- `--verbose`: print how many keys have been generated and modified
- `--binary-tree`: build a binary tree of keys instead of a linear list

## OPMPHM

The OPMPHM benchmarks need an external seed source. Use the `generate-seeds` script
Expand Down
201 changes: 201 additions & 0 deletions benchmarks/changetracking.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
#include <benchmarks.h>
#include <getopt.h>
#include <stdbool.h>

size_t keys = 5000;
char * keyNameFormat = "user:/test/sw/org/myapp/#0/current/section/subsection/key%zu";
char * keyValueFormat = "value%zu";
char * keyValueModifiedFormat = "value-modified%zu";

KeySet * (*keySetBuilder) (void) = NULL;

bool verbose = false;
bool harmonizeKeys = false;

/**
* @brief Power function.
*
* @param p basis
* @param q exponent
*
* @retval size_t p^q
*/
static size_t getPower (size_t p, size_t q)
{
size_t result = 1;
for (size_t t = 0; t < q; ++t)
{
result *= p;
}
return result;
}

/**
* binary tree
*/
static void shapefBinaryBranch (const size_t initSize, size_t size ELEKTRA_UNUSED, size_t level, int32_t * seed ELEKTRA_UNUSED,
KsShapeFunctionReturn * ret, void * data ELEKTRA_UNUSED)
{
size_t subKeys = 2;
ret->label = 0;
if (getPower (subKeys, level) > initSize)
{
ret->subKeys = 0;
}
else
{
ret->subKeys = subKeys;
}
}

static KeySet * buildBinaryTree (void)
{
KeySetShape shape;
shape.minWordLength = 1;
shape.maxWordLength = 1;
shape.special = 0;
shape.parent = 7;
shape.shapeInit = NULL;
shape.shapef = shapefBinaryBranch;
shape.shapeDel = NULL;

int32_t seed = 0xBEEF;
KeySet * generated = generateKeySet (keys, &seed, &shape);
KeySet * ks = ksNew (ksGetSize (generated), KS_END);

char buffer[2048] = "";
for (elektraCursor i = 0; i < ksGetSize (generated); i++)
{
Key * k = keyDup (ksAtCursor (generated, i), KEY_CP_ALL);
snprintf (buffer, 2047, "user:/test%s", keyName (k));
keySetName (k, buffer);
ksAppendKey (ks, k);
}

ksDel (generated);

return ks;
}

static KeySet * buildLinearTree (void)
{
KeySet * ks = ksNew (0, KS_END);

char nameBuffer[1024] = "";
char valueBuffer[1024] = "";

for (size_t i = 0; i < keys; i++)
{
snprintf (nameBuffer, 1023, keyNameFormat, i);
snprintf (valueBuffer, 1023, keyValueFormat, i);
ksAppendKey (ks, keyNew (nameBuffer, KEY_VALUE, valueBuffer, KEY_END));
}

return ks;
}

static void processCommandLineArguments (int argc, char ** argv)
{
struct option long_options[] = { { "key-count", required_argument, 0, 'c' },
{ "harmonize-names", no_argument, 0, 'h' },
{ "verbose", no_argument, 0, 'v' },
{ "binary-tree", no_argument, 0, 'b' },
{ 0, 0, 0, 0 } };

keySetBuilder = buildLinearTree;

while (1)
{
int option_index = 0;
int c = getopt_long (argc, argv, "", long_options, &option_index);

if (c == -1)
{
break;
}

switch (c)
{
case 'c':
keys = atoi (optarg);
break;
case 'v':
verbose = true;
break;
case 'h':
harmonizeKeys = true;
keyNameFormat = "user:/test/key%08zu";
keyValueFormat = "value%08zu";
keyValueModifiedFormat = "value-modified%08zu";
break;
case 'b':
keySetBuilder = buildBinaryTree;
break;
default:
break;
}
}
}

int main (int argc, char ** argv)
{
processCommandLineArguments (argc, argv);

if (verbose)
{
printf ("Number of keys: %zu\n", keys);
printf ("Harmonize key names: %s\n", harmonizeKeys ? "true" : "false");
}

Key * parentKey = keyNew ("user:/test", KEY_END);
KeySet * contract = ksNew (0, KS_END);
KDB * kdb = kdbOpen (contract, parentKey);

KeySet * ks = ksNew (0, KS_END);
kdbGet (kdb, ks, parentKey);

KeySet * generated = keySetBuilder ();
ksAppend (ks, generated);
ksDel (generated);

timeInit ();
kdbSet (kdb, ks, parentKey);
int insertingTime = timeGetDiffMicroseconds ();

kdbClose (kdb, parentKey);
ksDel (ks);

ks = ksNew (0, KS_END);
kdb = kdbOpen (contract, parentKey);
kdbGet (kdb, ks, parentKey);

size_t modified = 0;
for (size_t i = keys / 2; i < keys; i++)
{
char valueBuffer[1024] = "";
Key * key = ksAtCursor (ks, i);
snprintf (valueBuffer, 1023, keyValueModifiedFormat, i);
keySetString (key, valueBuffer);
modified++;
}

timeInit ();
kdbSet (kdb, ks, parentKey);
int modifyTime = timeGetDiffMicroseconds ();

if (verbose)
{
printf ("Modified keys: %zu\n", modified);
printf ("\n");
printf ("Insert Time (us); Modification Time (us)\n");
}

printf ("%d;%d\n", insertingTime, modifyTime);

kdbClose (kdb, parentKey);
ksDel (contract);
ksDel (ks);
keyDel (parentKey);

return 0;
}
80 changes: 80 additions & 0 deletions benchmarks/diff.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include <benchmarks.h>
#include <kdb.h>
#include <kdbdiff.h>

int main (void)
{
int runs = 100;
int numKeys = 1000;

KeySet * new = ksNew (0, KS_END);
KeySet * old = ksNew (0, KS_END);

char nameBuffer[100] = "";
char valueBuffer[50] = "";

for (int i = 0; i < numKeys; i++)
{
snprintf (nameBuffer, 99, "system:/a/%d", i * 2);
snprintf (valueBuffer, 49, "%d", i);

Key * k = keyNew (nameBuffer, KEY_VALUE, valueBuffer, KEY_END);

ksAppendKey (new, k);
ksAppendKey (old, k);
}

for (int i = 0; i < numKeys; i++)
{
snprintf (nameBuffer, 99, "system:/a/%d", i * 2 + 1);

snprintf (valueBuffer, 49, "%d", i);
ksAppendKey (new, keyNew (nameBuffer, KEY_VALUE, valueBuffer, KEY_END));

snprintf (valueBuffer, 49, "%d modified", i);
ksAppendKey (old, keyNew (nameBuffer, KEY_VALUE, valueBuffer, KEY_END));
}

for (int i = 0; i < numKeys; i++)
{
snprintf (nameBuffer, 99, "system:/b/%d", i * 2);
snprintf (valueBuffer, 49, "%d", i);

Key * k = keyNew (nameBuffer, KEY_VALUE, valueBuffer, KEY_END);

ksAppendKey (new, k);
}

for (int i = 0; i < numKeys; i++)
{
snprintf (nameBuffer, 99, "system:/c/%d", i * 2);
snprintf (valueBuffer, 49, "%d", i);

Key * k = keyNew (nameBuffer, KEY_VALUE, valueBuffer, KEY_END);

ksAppendKey (old, k);
}

int sum = 0;

for (int i = 0; i < runs; i++)
{
timeInit ();

ElektraDiff * diff = elektraDiffCalculate (new, old, NULL);

int us = timeGetDiffMicroseconds ();
sum += us;

printf ("%d us\n", us);

elektraDiffDel (diff);
}

printf ("Average: %.2f", (double) sum / runs);

ksDel (new);
ksDel (old);

return 0;
}
Loading

0 comments on commit afaca47

Please sign in to comment.