-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb2topasutil.h
475 lines (408 loc) · 19.2 KB
/
db2topasutil.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
#ifndef DB2TOPASUTIL_H
#define DB2TOPASUTIL_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/param.h>
#include <time.h>
#include <syslog.h>
#include <pthread.h>
#include <signal.h>
#include <sqlenv.h>
#include <sqlda.h>
#include <sqlca.h>
#include <sqlmon.h>
#include <sqlcli1.h>
#include <sqlutil.h>
#include <db2ApiDf.h>
#include "stack.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef max
#define max(A, B) ((A) > (B) ? (A) : (B))
#endif
#ifndef min
#define min(A, B) ((A) > (B) ? (B) : (A))
#endif
#ifndef delta
#define delta(A,B) ((A) > (B) ? ((A) - (B)) : 0)
#endif
#ifndef SQL_DIAGPATH_SZ
#define SQL_DIAGPATH_SZ 512
#endif
#ifndef UTIL_DESC_SZ
#define UTIL_DESC_SZ 1024
#endif
#ifndef TABSCHEMA_SZ
#define TABSCHEMA_SZ 128
#endif
#ifndef TABNAME_SZ
#define TABNAME_SZ 128
#endif
/* Boolean data type */
#ifndef Boolean
typedef int Boolean;
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#endif
#define PAGER "${PAGER:-more}"
#define USERID_SZ 128
#define STMT_SZ 256
#define MAX_STMTS 100
#define PSWD_SZ 14
#define MAXLINE 1024
#if (defined(DB2NT))
#define PATH_SEP "\\"
#else /* UNIX */
#define PATH_SEP "/"
#endif
/**************************************************************/
/* macro for printing error mesg */
/**************************************************************/
#define ERR_MSG(MSG_STR) \
do { \
db2AdminMsgWriteStruct msg; \
struct sqlca msg_sqlca; \
\
msg.iMsgType = STRING_MSG ; \
msg.iComponent = 0; \
msg.iFunction = 0; \
msg.iProbeID = __LINE__; \
msg.piData_title = __FILE__; \
msg.piData = MSG_STR; \
msg.iError_type = DB2LOG_ERROR; \
db2AdminMsgWrite(SQLM_CURRENT_VERSION, &msg, &msg_sqlca); \
return -1; \
} while (0)
/**************************************************************/
/* macro for printing warning mesg */
/**************************************************************/
#define WARN_MSG(MSG_STR) \
do { \
db2AdminMsgWriteStruct msg; \
struct sqlca msg_sqlca; \
\
msg.iMsgType = STRING_MSG ; \
msg.iComponent = 0; \
msg.iFunction = 0; \
msg.iProbeID = __LINE__; \
msg.piData_title = __FILE__; \
msg.piData = MSG_STR; \
msg.iError_type = DB2LOG_WARNING; \
db2AdminMsgWrite(SQLM_CURRENT_VERSION, &msg, &msg_sqlca); \
} while (0)
/**************************************************************/
/* macro for printing informational mesg */
/**************************************************************/
#define INFO_MSG(MSG_STR) \
do { \
db2AdminMsgWriteStruct msg; \
struct sqlca msg_sqlca; \
\
msg.iMsgType = STRING_MSG ; \
msg.iComponent = 0; \
msg.iFunction = 0; \
msg.iProbeID = __LINE__; \
msg.piData_title = __FILE__; \
msg.piData = MSG_STR; \
msg.iError_type = DB2LOG_INFORMATION; \
db2AdminMsgWrite(SQLM_CURRENT_VERSION, &msg, &msg_sqlca); \
} while (0)
/**************************************************************/
/* macro for DB2_API checking */
/**************************************************************/
#define DB2_API_CHECK(MSG_STR) \
do { \
SqlInfoPrint(MSG_STR, &sqlca, __LINE__, __FILE__); \
if (sqlca.sqlcode < 0) \
{ \
return 1; \
} \
} while (0)
/**************************************************************/
/* macro for environment handle checking */
/**************************************************************/
#define ENV_HANDLE_CHECK(henv, cliRC) \
do { \
if (cliRC != SQL_SUCCESS) \
{ \
rc = HandleInfoPrint(SQL_HANDLE_ENV, henv, \
cliRC, __LINE__, __FILE__); \
if (rc != 0) return rc; \
} \
} while (0)
/**************************************************************/
/* macro for connection handle checking */
/**************************************************************/
#define DBC_HANDLE_CHECK(hdbc, cliRC) \
do { \
if (cliRC != SQL_SUCCESS) \
{ \
rc = HandleInfoPrint(SQL_HANDLE_DBC, hdbc, \
cliRC, __LINE__, __FILE__); \
if (rc != 0) return rc; \
} \
} while (0)
/**************************************************************/
/* macro for statement handle checking */
/**************************************************************/
#define STMT_HANDLE_CHECK(hstmt, hdbc, cliRC) \
do { \
if (cliRC != SQL_SUCCESS) \
{ \
rc = HandleInfoPrint(SQL_HANDLE_STMT, hstmt, \
cliRC, __LINE__, __FILE__); \
if (rc == 2) StmtResourcesFree(hstmt); \
if (rc != 0) TransRollback(hdbc); \
if (rc != 0) return rc; \
} \
} while (0)
/**************************************************************/
/* functions used in ..._CHECK macros */
/**************************************************************/
void SqlInfoPrint(char *, struct sqlca *, int, char *);
int HandleInfoPrint(SQLSMALLINT, SQLHANDLE, SQLRETURN, int, char *);
/**************************************************************/
/* lock used to snychronize threads */
/**************************************************************/
typedef struct {
pthread_mutexattr_t lock_attr;
pthread_mutex_t lock;
pthread_cond_t cond;
int free;
int wanted;
} long_lock_t;
/**************************************************************/
/* snapshot screen where key up and key down should work */
/**************************************************************/
typedef enum SnapScr_ {
wstmt_list
,wlock_list
} SnapScr;
/**************************************************************/
/* Type of snapshot requested */
/**************************************************************/
typedef enum SnapReqType_ {
appls
,stmts
,locklist
,agent_id
,agent_id_detl
,agent_id_cmdline
,utils
,utils_id
,tbspace
,tbspace_id
,unknown } SnapReqType;
/**************************************************************/
/* Column used to order rows */
/**************************************************************/
typedef enum OrderByCol_ { cpu
, tqr
, tqw
, rr
, rw
, sel
, ins
, upd
, del
, memusg
, bppgin
, logusg
, node
, nagents
, rolledback } OrderByCol;
/**************************************************************/
/* How rows are ordered */
/**************************************************************/
typedef enum Order_ { asc
, desc } Order;
/**************************************************************/
/* Struct to hold snapshot request */
/**************************************************************/
typedef struct SnapReq_ {
SnapReqType type;
sqluint32 agent_id; /* show this specific appl handle only */
sqluint32 util_id;
sqluint32 tbspace_id;
sqluint32 tbspace_pg_sz;
sqluint8 tbspace_content_type;
char tbspace [SQLUH_TABLESPACENAME_SZ+1] ;
char exec_id[USERID_SZ + 1]; /* show appl with this exec_id only */
char auth_id[USERID_SZ + 1]; /* show appl with this auth_id only */
char prog_nm[USERID_SZ + 1]; /* show appl with this prog_nm only */
char client_nm[USERID_SZ + 1]; /* show appl with this client_nm */
char dbname[SQL_DBNAME_SZ + 1]; /* db being monitored; if NULL then
monitor all db under the instance */
int node; /* take app snapshot from this node
-2 means global
-1 means current node
+n means node n */
sqluint16 stmt_node_number;
sqluint32 stmt_section_number;
char sequence_no [SQLM_SEQ_SZ + 1];
char stmt_text[STMT_SZ + 1];
OrderByCol order_by_col;
Order order;
} SnapReq;
/**************************************************************/
/* Type of data displayed in col1 of the curses screen */
/**************************************************************/
typedef enum Col1_opt_ { prog_nm
,client_nm
,util_id
,coord_node_num
,coord_pid
,client_pid
,appl_handle } Col1_opt;
/**************************************************************/
/* Type of data displayed in col3 of the curses screen */
/**************************************************************/
typedef enum Col3_opt_ { exec_id, auth_id} Col3_opt;
/**************************************************************/
/* Type of data displayed in col4 of the curses screen */
/**************************************************************/
typedef enum Col4_opt_ { stmt_op, appl_status} Col4_opt;
/**************************************************************/
/* Type of data displayed in col8 of the curses screen */
/**************************************************************/
typedef enum Col8_opt_ { bp, mem_usg, num_agents} Col8_opt;
/**************************************************************/
/* Type of data displayed in col12 of the curses screen */
/**************************************************************/
typedef enum Col12_opt_ { rb, log_usg,locks} Col12_opt;
/**************************************************************/
/* -header that's displayed constantly on the curses screen
-use to store cmdline options or input from curses screen
*/
/**************************************************************/
typedef struct Header_ {
SnapScr snapScr;
Stack snap_req_stack; /* Stack to hold type snapshot req */
char myname[256] ; /* program name */
int spin;
char user_id[USERID_SZ+1]; /* user_id used to attach to instance */
char instance[SQL_INSTNAME_SZ + 1]; /* instance being monitored */
char pswd[PSWD_SZ + 1];
char hostname[MAXHOSTNAMELEN + 1]; /* hostname where the prog started */
char db2node[5];
unsigned int interval; /* snapshot or refresh interval */
Col1_opt col1_opt;
Col3_opt col3_opt;
Col4_opt col4_opt;
Col8_opt col8_opt;
Col12_opt col12_opt;
Boolean reinit_DB2SnapReq; /* reinitialize DB2 snapshot request */
/*******************************************************************************/
/* variables used to summarize information about DBASE or APPL
in the header
*/
/*******************************************************************************/
sqlm_timestamp t1_snapshot_timestamp;
sqlm_timestamp t2_snapshot_timestamp;
double snapshot_timestamp_delta;
sqluint32 appls_connected;
sqluint32 appls_executing;
sqluint32 db_assoc_agents; /* -number of agents associated to applications
-summed up from APPL snapshots
-used to calculate cpu % */
sqluint64 db_memusg;
sqluint64 db_genheap;
sqluint32 db_sortheap;
sqluint64 db_lockheap;
sqluint64 db_utilheap;
sqluint64 db_ucpu_used_delta ;
sqluint64 db_scpu_used_delta ;
sqluint64 t1_db_bpr_tm;
sqluint64 t2_db_bpr_tm;
sqluint64 t1_db_bpw_tm;
sqluint64 t2_db_bpw_tm;
sqluint64 t1_db_buffered_rio;
sqluint64 t1_db_buffered_wio;
sqluint64 t2_db_buffered_rio;
sqluint64 t2_db_buffered_wio;
sqluint64 t1_db_direct_io ;
sqluint64 t2_db_direct_io;
sqluint64 t1_db_direct_io_reqs ;
sqluint64 t2_db_direct_io_reqs;
sqluint64 t1_db_io_type_read;
sqluint64 t2_db_io_type_read;
sqluint64 t1_db_io_type_write;
sqluint64 t2_db_io_type_write;
sqluint64 t1_db_io_type_data;
sqluint64 t2_db_io_type_data;
sqluint64 t1_db_io_type_idx;
sqluint64 t2_db_io_type_idx;
sqluint64 t1_db_io_type_temp;
sqluint64 t2_db_io_type_temp;
sqluint64 t1_db_io_type_xml;
sqluint64 t2_db_io_type_xml;
sqluint64 t1_db_io_type_dio;
sqluint64 t2_db_io_type_dio;
sqluint64 t1_db_log_reads;
sqluint64 t2_db_log_reads;
sqluint64 t1_db_log_writes;
sqluint64 t2_db_log_writes;
sqluint64 db_log_avail;
sqluint64 db_log_used;
sqluint16 smallest_log_avail_node;
sqluint32 agent_id_oldest_xact;
Boolean mark; /* toggle the currently highlighted row if true */
Boolean dump; /* dump monitor stream in a file */
int dbase_scrn_row; /* number of rows used by database screen */
Boolean sequence_no_found;
Boolean section_number_found;
Boolean node_number_found;
char *pStmtStart;
Boolean show_dbase_list; /* turn on/off database screen at the top */
Boolean show_appl_list; /* turn on/off appl list */
Boolean show_lock_list; /* turn on/off lock list */
Boolean show_stmt_list; /* turn on/off stmt list */
} Header;
/**************************************************************/
/* Public utility functions */
/**************************************************************/
int CLIAppInit(char dbAlias[],
char user[],
char pswd[],
SQLHANDLE *pHenv,
SQLHANDLE *pHdbc,
SQLPOINTER autocommitValue);
int CLIAppTerm(SQLHANDLE * pHenv, SQLHANDLE * pHdbc, char dbAlias[]);
int StmtResourcesFree(SQLHANDLE);
void TransRollback(SQLHANDLE);
int InstanceAttach(char * , char *, char *);
int InstanceDetach(char *);
Header *init_header();
void free_header(Header *);
const SnapReq *peek_snapReq(Header *);
int push_snapReq(Header *, const SnapReq *);
int pop_snapReq(Header *);
int num_snapReq(Header *);
char *strrtrim(char *);
char *strltrim(char *);
char *strtrim(char *);
char *strrev(char *);
char *basename(const char*);
void chomp(char *);
/*
void long_lock_init(long_lock_t *);
void long_lock_destroy(long_lock_t *);
void long_lock(long_lock_t *);
int long_trylock(long_lock_t *);
void long_unlock(long_lock_t *);
*/
char *time_STRING(sqlm_timestamp timestamp, char *timeString);
sqluint32 timediff(sqlm_time, sqlm_time);
sqluint32 timestampdiff(sqlm_timestamp, sqlm_timestamp);
#ifdef __cplusplus
}
#endif
#endif /* DB2TOPASUTIL_H */