* - variable-size query
*/
-#include "system.h"
-
#ifdef WIN32
#undef strerror
#undef main
#endif
-#include <getopt.h>
-#include <event.h>
-#include <libpq-fe.h>
-
-static void log_error(const char *, ...);
-static void log_debug(const char *, ...);
-static void fatal(const char *fmt, ...);
-static void fatal_noexit(const char *fmt, ...);
+#include <usual/event.h>
+#include <usual/logging.h>
+#include <usual/getopt.h>
+#include <usual/logging.h>
+#include <usual/list.h>
+#include <usual/statlist.h>
+#include <usual/time.h>
+#include <usual/string.h>
-#include "list.h"
+#include <libpq-fe.h>
static char *simple_query = "select 1";
typedef void (*libev_cb_f)(int sock, short flags, void *arg);
typedef struct DbConn {
- List head;
+ struct List head;
const char *connstr;
struct event ev;
PGconn *con;
static STATLIST(idle_list);
static STATLIST(active_list);
-static usec_t _time_cache = 0;
-
/*
* utility functions
*/
-static usec_t get_time_usec(void)
-{
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return (usec_t)tv.tv_sec * USEC + tv.tv_usec;
-}
-
-static usec_t get_cached_time(void)
-{
- if (!_time_cache)
- _time_cache = get_time_usec();
- return _time_cache;
-}
-static void reset_time_cache(void)
-{
- _time_cache = 0;
-}
-
/* fill mem with random junk */
static void init_bulk_data(void)
{
static void set_idle(DbConn *db)
{
Assert(item_in_list(&db->head, &active_list.head));
- statlist_remove(&db->head, &active_list);
- statlist_append(&db->head, &idle_list);
+ statlist_remove(&active_list, &db->head);
+ statlist_append(&idle_list, &db->head);
log_debug("%p: set_idle", db);
}
static void set_active(DbConn *db)
{
Assert(item_in_list(&db->head, &idle_list.head));
- statlist_remove(&db->head, &idle_list);
- statlist_append(&db->head, &active_list);
+ statlist_remove(&idle_list, &db->head);
+ statlist_append(&active_list, &db->head);
log_debug("%p: set_active", db);
}
-static void fatal_perror(const char *err)
-{
- log_error("%s: %s", err, strerror(errno));
- exit(1);
-}
-
-static void fatal_noexit(const char *fmt, ...)
-{
- va_list ap;
- char buf[1024];
- va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- printf("FATAL: %s\n", buf);
-}
-
-static void fatal(const char *fmt, ...)
-{
- va_list ap;
- char buf[1024];
- va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- printf("FATAL: %s\n", buf);
- exit(1);
-}
-
-static void log_debug(const char *fmt, ...)
-{
- va_list ap;
- char buf[1024];
- if (verbose == 0)
- return;
- va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- printf("dbg: %s\n", buf);
-}
-
-static void log_error(const char *fmt, ...)
-{
- va_list ap;
- char buf[1024];
- va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- printf("ERR: %s\n", buf);
-}
-
static void wait_event(DbConn *db, short ev, libev_cb_f fn)
{
event_set(&db->ev, PQsocket(db->con), ev, fn, db);
static void handle_idle(void)
{
DbConn *db;
- List *item, *tmp;
+ struct List *item, *tmp;
int allow_connects = 100000;
int allow_queries = 100000;
static usec_t startup_time = 0;
for (i = 0; i < numcon; i++) {
db = new_db(cstr);
- statlist_append(&db->head, &idle_list);
+ statlist_append(&idle_list, &db->head);
}
event_init();