~ubuntu-branches/debian/jessie/sysbench/jessie

« back to all changes in this revision

Viewing changes to sysbench/sb_logger.h

  • Committer: Bazaar Package Importer
  • Author(s): Hendrik Frenzel
  • Date: 2009-02-23 00:32:52 UTC
  • Revision ID: james.westby@ubuntu.com-20090223003252-u6psmnqbivepsj0n
Tags: upstream-0.4.10
ImportĀ upstreamĀ versionĀ 0.4.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2004 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; either version 2 of the License, or
 
6
   (at your option) any later version.
 
7
 
 
8
   This program is distributed in the hope that it will be useful,
 
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
   GNU General Public License for more details.
 
12
 
 
13
   You should have received a copy of the GNU General Public License
 
14
   along with this program; if not, write to the Free Software
 
15
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
*/
 
17
 
 
18
#ifndef SB_LOGGER_H
 
19
#define SB_LOGGER_H
 
20
 
 
21
#ifdef HAVE_CONFIG_H
 
22
# include "config.h"
 
23
#endif
 
24
 
 
25
#include "sb_options.h"
 
26
#include "sb_timer.h"
 
27
 
 
28
/* Macros to log per-request execution statistics */
 
29
 
 
30
#define LOG_EVENT_START(msg, thread_id) \
 
31
  do \
 
32
  { \
 
33
    sb_timer_start(&sb_globals.op_timers[thread_id]); \
 
34
    ((log_msg_oper_t *)(msg).data)->action = LOG_MSG_OPER_START; \
 
35
    log_msg(&(msg)); \
 
36
  } while (0);
 
37
 
 
38
#define LOG_EVENT_STOP(msg, thread_id) \
 
39
  do \
 
40
  { \
 
41
    ((log_msg_oper_t *)(msg).data)->action = LOG_MSG_OPER_STOP; \
 
42
    log_msg(&(msg)); \
 
43
    sb_timer_stop(&sb_globals.op_timers[thread_id]); \
 
44
  } while (0);
 
45
 
 
46
/* Message types definition */
 
47
 
 
48
typedef enum {
 
49
  LOG_MSG_TYPE_MIN,           /* used for internal purposes */
 
50
  LOG_MSG_TYPE_TEXT,          /* arbitrary text messages */
 
51
  LOG_MSG_TYPE_OPER,          /* operation start/stop messages */
 
52
  LOG_MSG_TYPE_MAX            /* used for internal purposes */
 
53
} log_msg_type_t;
 
54
 
 
55
/* Message priorities definition */
 
56
 
 
57
typedef enum {
 
58
  LOG_FATAL,     /* system is unusable */
 
59
  LOG_ALERT,     /* user actions must be taken */
 
60
  LOG_WARNING,   /* warnings */
 
61
  LOG_NOTICE,    /* normal but significant messages */
 
62
  LOG_INFO,      /* informational messages */   
 
63
  LOG_DEBUG,     /* debug-level messages */
 
64
  LOG_MAX        /* used for internal purposes */
 
65
} log_msg_priority_t;
 
66
 
 
67
/* Text message definition */
 
68
 
 
69
typedef struct {
 
70
  log_msg_priority_t priority;
 
71
  char              *text;
 
72
} log_msg_text_t;
 
73
 
 
74
/* Operation start/stop message definition */
 
75
 
 
76
typedef enum {
 
77
  LOG_MSG_OPER_START,
 
78
  LOG_MSG_OPER_STOP
 
79
} log_msg_oper_action_t;
 
80
 
 
81
typedef struct {
 
82
  log_msg_oper_action_t action;
 
83
  sb_timer_t            timer;
 
84
} log_msg_oper_t;
 
85
 
 
86
/* General log message definition */
 
87
 
 
88
typedef struct {
 
89
  log_msg_type_t type;
 
90
  void           *data;
 
91
} log_msg_t;
 
92
 
 
93
/* Log handler operations definition */
 
94
 
 
95
typedef int log_op_register(void);          /* register handler options */
 
96
typedef int log_op_init(void);              /* initialize log handler */
 
97
typedef int log_op_process(log_msg_t *msg); /* process message */
 
98
typedef int log_op_done(void);              /* uninitialize log handler */
 
99
 
 
100
/* Log handler operations structure */
 
101
 
 
102
typedef struct {
 
103
  log_op_init     *init;
 
104
  log_op_process  *process;
 
105
  log_op_done     *done;
 
106
} log_handler_ops_t;
 
107
 
 
108
/* Log handler definition */
 
109
 
 
110
typedef struct {
 
111
  log_handler_ops_t ops;          /* handler operations */
 
112
  sb_arg_t             *args;     /* handler arguments */
 
113
  
 
114
  sb_list_item_t       listitem;  /* can be linked in a list */
 
115
} log_handler_t;
 
116
 
 
117
/* Register logger */
 
118
 
 
119
int log_register(void);
 
120
 
 
121
/* Initialize logger */
 
122
 
 
123
int log_init(void);
 
124
 
 
125
/* Add handler for a specified type of messages */
 
126
 
 
127
int log_add_handler(log_msg_type_t type, log_handler_t *handler);
 
128
 
 
129
/* Main function to dispatch log messages */
 
130
 
 
131
void log_msg(log_msg_t *);
 
132
 
 
133
/* printf-like wrapper to log text messages */
 
134
 
 
135
void log_text(log_msg_priority_t priority, const char *fmt, ...);
 
136
 
 
137
/* printf-like wrapper to log system error messages */
 
138
 
 
139
void log_errno(log_msg_priority_t priority, const char *fmt, ...);
 
140
 
 
141
/* Uninitialize logger */
 
142
 
 
143
void log_done(void);
 
144
 
 
145
#endif /* SB_LOGGER_H */