Added with merge
This commit is contained in:
@ -83,6 +83,7 @@ DCB *rval;
|
||||
rval->next = NULL;
|
||||
rval->data = NULL;
|
||||
rval->protocol = NULL;
|
||||
rval->session = NULL;
|
||||
memset(&rval->stats, 0, sizeof(DCBSTATS)); // Zero the statistics
|
||||
|
||||
spinlock_acquire(dcbspin);
|
||||
|
||||
@ -399,36 +399,46 @@ config.o: config.c /usr/include/stdio.h /usr/include/features.h \
|
||||
/usr/include/bits/setjmp.h ../include/dcb.h ../include/buffer.h \
|
||||
../include/server.h ../include/users.h ../include/hashtable.h \
|
||||
../include/atomic.h
|
||||
users.o: users.c /usr/include/stdlib.h /usr/include/features.h \
|
||||
users.o: users.c /usr/include/stdio.h /usr/include/features.h \
|
||||
/usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \
|
||||
/usr/include/gnu/stubs.h /usr/include/gnu/stubs-64.h \
|
||||
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/include/stddef.h \
|
||||
/usr/include/bits/waitflags.h /usr/include/bits/waitstatus.h \
|
||||
/usr/include/endian.h /usr/include/bits/endian.h \
|
||||
/usr/include/bits/byteswap.h /usr/include/sys/types.h \
|
||||
/usr/include/bits/types.h /usr/include/bits/typesizes.h \
|
||||
/usr/include/time.h /usr/include/sys/select.h /usr/include/bits/select.h \
|
||||
/usr/include/bits/sigset.h /usr/include/bits/time.h \
|
||||
/usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \
|
||||
/usr/include/alloca.h /usr/include/string.h /usr/include/xlocale.h \
|
||||
../include/users.h ../include/hashtable.h ../include/spinlock.h \
|
||||
../include/thread.h /usr/include/pthread.h /usr/include/sched.h \
|
||||
/usr/include/bits/sched.h /usr/include/bits/setjmp.h ../include/atomic.h
|
||||
hashtable.o: hashtable.c /usr/include/stdlib.h /usr/include/features.h \
|
||||
/usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \
|
||||
/usr/include/gnu/stubs.h /usr/include/gnu/stubs-64.h \
|
||||
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/include/stddef.h \
|
||||
/usr/include/bits/waitflags.h /usr/include/bits/waitstatus.h \
|
||||
/usr/include/endian.h /usr/include/bits/endian.h \
|
||||
/usr/include/bits/byteswap.h /usr/include/sys/types.h \
|
||||
/usr/include/bits/types.h /usr/include/bits/typesizes.h \
|
||||
/usr/include/time.h /usr/include/sys/select.h /usr/include/bits/select.h \
|
||||
/usr/include/bits/sigset.h /usr/include/bits/time.h \
|
||||
/usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \
|
||||
/usr/include/alloca.h /usr/include/string.h /usr/include/xlocale.h \
|
||||
/usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \
|
||||
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/include/stdarg.h \
|
||||
/usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \
|
||||
/usr/include/stdlib.h /usr/include/bits/waitflags.h \
|
||||
/usr/include/bits/waitstatus.h /usr/include/endian.h \
|
||||
/usr/include/bits/endian.h /usr/include/bits/byteswap.h \
|
||||
/usr/include/sys/types.h /usr/include/time.h /usr/include/sys/select.h \
|
||||
/usr/include/bits/select.h /usr/include/bits/sigset.h \
|
||||
/usr/include/bits/time.h /usr/include/sys/sysmacros.h \
|
||||
/usr/include/bits/pthreadtypes.h /usr/include/alloca.h \
|
||||
/usr/include/string.h /usr/include/xlocale.h ../include/users.h \
|
||||
../include/hashtable.h ../include/spinlock.h ../include/thread.h \
|
||||
/usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \
|
||||
/usr/include/bits/setjmp.h ../include/atomic.h
|
||||
/usr/include/bits/setjmp.h ../include/atomic.h ../include/dcb.h \
|
||||
../include/buffer.h
|
||||
hashtable.o: hashtable.c /usr/include/stdio.h /usr/include/features.h \
|
||||
/usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \
|
||||
/usr/include/gnu/stubs.h /usr/include/gnu/stubs-64.h \
|
||||
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/include/stddef.h \
|
||||
/usr/include/bits/types.h /usr/include/bits/typesizes.h \
|
||||
/usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \
|
||||
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/include/stdarg.h \
|
||||
/usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \
|
||||
/usr/include/stdlib.h /usr/include/bits/waitflags.h \
|
||||
/usr/include/bits/waitstatus.h /usr/include/endian.h \
|
||||
/usr/include/bits/endian.h /usr/include/bits/byteswap.h \
|
||||
/usr/include/sys/types.h /usr/include/time.h /usr/include/sys/select.h \
|
||||
/usr/include/bits/select.h /usr/include/bits/sigset.h \
|
||||
/usr/include/bits/time.h /usr/include/sys/sysmacros.h \
|
||||
/usr/include/bits/pthreadtypes.h /usr/include/alloca.h \
|
||||
/usr/include/string.h /usr/include/xlocale.h ../include/hashtable.h \
|
||||
../include/spinlock.h ../include/thread.h /usr/include/pthread.h \
|
||||
/usr/include/sched.h /usr/include/bits/sched.h \
|
||||
/usr/include/bits/setjmp.h ../include/atomic.h ../include/dcb.h \
|
||||
../include/buffer.h
|
||||
dbusers.o: dbusers.c /usr/include/stdio.h /usr/include/features.h \
|
||||
/usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \
|
||||
/usr/include/gnu/stubs.h /usr/include/gnu/stubs-64.h \
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
*
|
||||
* Copyright SkySQL Ab 2013
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <hashtable.h>
|
||||
@ -279,6 +280,73 @@ HASHENTRIES *entry;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print hash table statistics to the standard output
|
||||
*
|
||||
* @param table The hash table
|
||||
*/
|
||||
void
|
||||
hashtable_stats(HASHTABLE *table)
|
||||
{
|
||||
int total, longest, i, j;
|
||||
HASHENTRIES *entries;
|
||||
|
||||
printf("Hashtable: %p, size %d\n", table, table->hashsize);
|
||||
total = 0;
|
||||
longest = 0;
|
||||
hashtable_read_lock(table);
|
||||
for (i = 0; i < table->hashsize; i++)
|
||||
{
|
||||
j = 0;
|
||||
entries = table->entries[i];
|
||||
while (entries)
|
||||
{
|
||||
j++;
|
||||
entries = entries->next;
|
||||
}
|
||||
total += j;
|
||||
if (j > longest)
|
||||
longest = j;
|
||||
}
|
||||
hashtable_read_unlock(table);
|
||||
printf("\tNo. of entries: %d\n", total);
|
||||
printf("\tAverage chain length: %.1f\n", (float)total / table->hashsize);
|
||||
printf("\tLongest chain length: %d\n", longest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print hash table statistics to a DCB
|
||||
*
|
||||
* @param table The hash table
|
||||
*/
|
||||
void
|
||||
dcb_hashtable_stats(DCB *dcb, HASHTABLE *table)
|
||||
{
|
||||
int total, longest, i, j;
|
||||
HASHENTRIES *entries;
|
||||
|
||||
dcb_printf(dcb, "Hashtable: %p, size %d\n", table, table->hashsize);
|
||||
total = 0;
|
||||
longest = 0;
|
||||
hashtable_read_lock(table);
|
||||
for (i = 0; i < table->hashsize; i++)
|
||||
{
|
||||
j = 0;
|
||||
entries = table->entries[i];
|
||||
while (entries)
|
||||
{
|
||||
j++;
|
||||
entries = entries->next;
|
||||
}
|
||||
total += j;
|
||||
if (j > longest)
|
||||
longest = j;
|
||||
}
|
||||
hashtable_read_unlock(table);
|
||||
dcb_printf(dcb, "\tNo. of entries: %d\n", total);
|
||||
dcb_printf(dcb, "\tAverage chain length: %.1f\n", (float)total / table->hashsize);
|
||||
dcb_printf(dcb, "\tLongest chain length: %d\n", longest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a read lock on the hashtable.
|
||||
|
||||
@ -364,6 +364,7 @@ SERVER *ptr = service->databases;
|
||||
printf("\t\t%s:%d Protocol: %s\n", ptr->name, ptr->port, ptr->protocol);
|
||||
ptr = ptr->nextdb;
|
||||
}
|
||||
printf("\tUsers data: %p\n", service->users);
|
||||
printf("\tTotal connections: %d\n", service->stats.n_sessions);
|
||||
printf("\tCurrently connected: %d\n", service->stats.n_current);
|
||||
}
|
||||
@ -418,6 +419,7 @@ SERVICE *ptr;
|
||||
server->protocol);
|
||||
server = server->nextdb;
|
||||
}
|
||||
dcb_printf(dcb, "\tUsers data: %p\n", ptr->users);
|
||||
dcb_printf(dcb, "\tTotal connections: %d\n", ptr->stats.n_sessions);
|
||||
dcb_printf(dcb, "\tCurrently connected: %d\n", ptr->stats.n_current);
|
||||
ptr = ptr->next;
|
||||
|
||||
26
core/users.c
26
core/users.c
@ -15,6 +15,7 @@
|
||||
*
|
||||
* Copyright SkySQL Ab 2013
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <users.h>
|
||||
@ -147,3 +148,28 @@ users_update(USERS *users, char *user, char *auth)
|
||||
return 0;
|
||||
return hashtable_add(users->data, user, auth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print details of the users storage mechanism
|
||||
*
|
||||
* @param users The users table
|
||||
*/
|
||||
void
|
||||
usersPrint(USERS *users)
|
||||
{
|
||||
printf("Users table data\n");
|
||||
hashtable_stats(users->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print details of the users storage mechanism to a DCB
|
||||
*
|
||||
* @param dcb DCB to print to
|
||||
* @param users The users table
|
||||
*/
|
||||
void
|
||||
dcb_usersPrint(DCB *dcb, USERS *users)
|
||||
{
|
||||
dcb_printf(dcb, "Users table data\n");
|
||||
dcb_hashtable_stats(dcb, users->data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user