8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-25 00:03:03 +01:00
firebird-mirror/src/utilities/print_event.cpp

301 lines
8.2 KiB
C++
Raw Normal View History

2001-05-23 15:26:42 +02:00
/*
* PROGRAM: Event manager
2004-05-09 07:48:33 +02:00
* MODULE: print_event.cpp
2001-05-23 15:26:42 +02:00
* DESCRIPTION: Global region print utility
*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "firebird.h"
#include "fb_types.h"
#include "../common/common.h"
2001-05-23 15:26:42 +02:00
#include "../jrd/event.h"
#include "../jrd/event_proto.h"
2010-10-12 10:02:57 +02:00
#include "../yvalve/gds_proto.h"
#include "../common/utils_proto.h"
2001-05-23 15:26:42 +02:00
#define isc_print_status gds__print_status
static void prt_que(const char*, const srq*);
static void event_list();
static void event_dump_list();
static void event_table_dump();
2001-05-23 15:26:42 +02:00
static EVH EVENT_header = NULL;
2009-01-03 10:14:29 +01:00
#define SRQ_BASE ((UCHAR*) EVENT_header)
2001-05-23 15:26:42 +02:00
int main(int argc, char *argv[])
{
/**************************************
*
* m a i n
*
**************************************
*
* Functional description
* This is a simple utility program to print out the current
* contents of the Firebird event table file.
2001-05-23 15:26:42 +02:00
*
**************************************/
2003-04-16 12:18:51 +02:00
ISC_STATUS_ARRAY status_vector;
2001-05-23 15:26:42 +02:00
2009-07-03 12:44:55 +02:00
if (!(EVENT_header = EVENT_init(status_vector)))
{
2004-04-29 00:36:29 +02:00
fprintf(stderr, "Can't access global event region\n");
2001-05-23 15:26:42 +02:00
isc_print_status(status_vector);
return 1;
}
if ((argc == 2) && fb_utils::strnicmp(argv[1], "-dump", MAX(strlen(argv[1]), 2)) == 0)
2009-01-03 10:14:29 +01:00
event_table_dump();
2001-05-23 15:26:42 +02:00
else if (argc == 1)
event_list();
else
fprintf(stderr, "usage: fb_event_print [-dump]\n");
2001-05-23 15:26:42 +02:00
return 0;
}
2009-01-14 12:10:48 +01:00
static void event_list()
2001-05-23 15:26:42 +02:00
{
/**************************************
*
2008-12-05 02:20:14 +01:00
* e v e n t _ l i s t
2001-05-23 15:26:42 +02:00
*
**************************************
*
* Functional description
* List active events in the event table.
* This format is more readable for humans.
*
**************************************/
2009-05-24 07:24:59 +02:00
const srq* database_que;
2001-05-23 15:26:42 +02:00
2009-01-03 10:14:29 +01:00
SRQ_LOOP(EVENT_header->evh_events, database_que)
{
2009-05-24 07:24:59 +02:00
const evnt* database_event = (evnt*) ((UCHAR*) database_que - OFFSET(evnt*, evnt_events));
2001-05-23 15:26:42 +02:00
2009-05-17 13:20:43 +02:00
// Skip non-database entries
2001-05-23 15:26:42 +02:00
if (database_event->evnt_parent)
continue;
2009-05-17 13:20:43 +02:00
// Print out the magic name for the database, this name
// comes from the lock key_id for the database, on Unix
// this is comprised of the device number and inode
2001-05-23 15:26:42 +02:00
2004-04-29 00:36:29 +02:00
printf("Database: ");
const UCHAR* p = (UCHAR *) database_event->evnt_name;
for (ULONG l = database_event->evnt_length; l; --l)
2004-04-29 00:36:29 +02:00
printf("%02x", *p++);
2008-12-05 02:20:14 +01:00
2004-04-29 00:36:29 +02:00
printf(" count: %6ld\n", database_event->evnt_count);
2001-05-23 15:26:42 +02:00
{ // scope
2009-05-24 07:24:59 +02:00
const srq* interest_que;
2009-05-17 13:20:43 +02:00
// Print out the interest list for this event
2001-05-23 15:26:42 +02:00
2009-01-18 12:29:24 +01:00
SRQ_LOOP(database_event->evnt_interests, interest_que)
{
2009-05-24 07:24:59 +02:00
const req_int* interest = (req_int*) ((UCHAR*) interest_que - OFFSET(req_int*, rint_interests));
2001-05-23 15:26:42 +02:00
if (!interest->rint_request)
2004-04-29 00:36:29 +02:00
printf("(0)");
2009-07-03 12:44:55 +02:00
else
{
2009-05-24 07:24:59 +02:00
const evt_req* request = (evt_req*) SRQ_ABS_PTR(interest->rint_request);
const prb* process = (prb*) SRQ_ABS_PTR(request->req_process);
2004-04-29 00:36:29 +02:00
printf("%6d ", process->prb_process_id);
2001-05-23 15:26:42 +02:00
}
}
} // scope
2001-05-23 15:26:42 +02:00
2009-05-17 13:20:43 +02:00
// Print out each event belonging to this database
2001-05-23 15:26:42 +02:00
2009-05-24 07:24:59 +02:00
const srq* que_inst;
2009-01-03 10:14:29 +01:00
SRQ_LOOP(EVENT_header->evh_events, que_inst)
{
2001-05-23 15:26:42 +02:00
2009-05-24 07:24:59 +02:00
const evnt* event = (evnt*) ((UCHAR *) que_inst - OFFSET(evnt*, evnt_events));
2003-11-04 00:59:24 +01:00
fb_assert(event->evnt_header.hdr_type == type_evnt);
if (event->evnt_parent != SRQ_REL_PTR(database_event))
2001-05-23 15:26:42 +02:00
continue;
2009-01-03 10:14:29 +01:00
printf(" \"%-15s\" count: %6ld Interest", event->evnt_name, event->evnt_count);
2001-05-23 15:26:42 +02:00
2004-05-09 07:48:33 +02:00
{ // scope
2009-05-24 07:24:59 +02:00
const srq* interest_que;
2009-05-17 13:20:43 +02:00
// Print out the interest list for this event
2001-05-23 15:26:42 +02:00
2009-01-18 12:29:24 +01:00
SRQ_LOOP(event->evnt_interests, interest_que)
{
2009-05-24 07:24:59 +02:00
const req_int* interest = (req_int*) ((UCHAR*) interest_que - OFFSET(req_int*, rint_interests));
2001-05-23 15:26:42 +02:00
if (!interest->rint_request)
2004-04-29 00:36:29 +02:00
printf("(0)");
2009-07-03 12:44:55 +02:00
else
{
2009-05-24 07:24:59 +02:00
const evt_req* request = (evt_req*) SRQ_ABS_PTR(interest->rint_request);
const prb* process = (prb*) SRQ_ABS_PTR(request->req_process);
2004-04-29 00:36:29 +02:00
printf("%6d ", process->prb_process_id);
2001-05-23 15:26:42 +02:00
}
}
2004-05-09 07:48:33 +02:00
} // scope
2004-04-29 00:36:29 +02:00
printf("\n");
2001-05-23 15:26:42 +02:00
}
}
}
2009-01-14 12:10:48 +01:00
static void event_table_dump()
2001-05-23 15:26:42 +02:00
{
/**************************************
*
* e v e n t _ t a b l e _ d u m p
*
**************************************
*
* Functional description
* Dump the contents of the event table.
* This format exactly matches what's in the event table and
* is not very readable by humans.
*
**************************************/
2004-04-29 00:36:29 +02:00
printf("%.5d GLOBAL REGION HEADER\n", 0);
2009-01-03 10:14:29 +01:00
printf("\tLength: %ld, version: %d, free: %ld, current: %ld, request_id: %ld\n",
2001-05-23 15:26:42 +02:00
EVENT_header->evh_length, EVENT_header->evh_version,
EVENT_header->evh_free, EVENT_header->evh_current_process,
EVENT_header->evh_request_id);
prt_que("\tProcesses", &EVENT_header->evh_processes);
prt_que("\tEvents", &EVENT_header->evh_events);
2009-01-03 10:14:29 +01:00
for (SLONG offset = sizeof(evh); offset < EVENT_header->evh_length; offset += block->hdr_length)
{
2004-04-29 00:36:29 +02:00
printf("\n%.5ld ", offset);
2009-05-24 07:24:59 +02:00
const event_hdr* block = (event_hdr*) SRQ_ABS_PTR(offset);
2009-01-18 12:29:24 +01:00
switch (block->hdr_type)
{
2001-05-23 15:26:42 +02:00
case type_prb:
{
printf("PROCESS_BLOCK (%ld)\n", block->hdr_length);
2009-05-24 07:24:59 +02:00
const prb* process = (prb*) block;
2009-01-03 10:14:29 +01:00
printf("\tFlags: %d, pid: %d\n", process->prb_flags, process->prb_process_id);
prt_que("\tProcesses", &process->prb_processes);
prt_que("\tSessions", &process->prb_sessions);
}
2001-05-23 15:26:42 +02:00
break;
case type_frb:
{
printf("FREE BLOCK (%ld)\n", block->hdr_length);
2009-05-24 07:24:59 +02:00
const frb* free = (frb*) block;
printf("\tNext: %ld\n", free->frb_next);
}
2001-05-23 15:26:42 +02:00
break;
case type_reqb:
{
printf("REQUEST BLOCK (%ld)\n", block->hdr_length);
2009-05-24 07:24:59 +02:00
const evt_req* request = (evt_req*) block;
printf("\tProcess: %ld, interests: %ld, ast: %lx, arg: %lx\n",
request->req_process, request->req_interests,
request->req_ast, request->req_ast_arg);
printf("\tRequest id: %ld\n", request->req_request_id);
prt_que("\tRequests", &request->req_requests);
}
2001-05-23 15:26:42 +02:00
break;
case type_evnt:
{
printf("EVENT (%ld)\n", block->hdr_length);
2009-05-24 07:24:59 +02:00
const evnt* event = (evnt*) block;
printf("\t\"%s\", count: %ld, parent: %ld\n",
2009-01-18 12:29:24 +01:00
event->evnt_name, event->evnt_count, event->evnt_parent);
prt_que("\tInterests", &event->evnt_interests);
prt_que("\tEvents", &event->evnt_events);
}
2001-05-23 15:26:42 +02:00
break;
case type_ses:
{
printf("SESSION (%ld)\n", block->hdr_length);
2009-05-24 07:24:59 +02:00
const ses* session = (ses*) block;
2008-01-16 08:40:12 +01:00
printf("\tInterests: %ld\n", session->ses_interests);
prt_que("\tSessions", &session->ses_sessions);
prt_que("\tRequests", &session->ses_requests);
}
2001-05-23 15:26:42 +02:00
break;
case type_rint:
{
printf("INTEREST (%ld)\n", block->hdr_length);
2009-05-24 07:24:59 +02:00
const req_int* interest = (req_int*) block;
2009-01-18 12:29:24 +01:00
if (interest->rint_event)
{
2009-05-24 07:24:59 +02:00
const evnt* event = (evnt*) SRQ_ABS_PTR(interest->rint_event);
2009-07-03 12:44:55 +02:00
if (event->evnt_parent)
{
2009-05-24 07:24:59 +02:00
const evnt* parent = (evnt*) SRQ_ABS_PTR(event->evnt_parent);
2009-01-03 10:14:29 +01:00
printf("\t\"%s\".\"%s\"\n", parent->evnt_name, event->evnt_name);
}
else
printf("\t\"%s\"\n", event->evnt_name);
2001-05-23 15:26:42 +02:00
}
printf("\tEvent: %ld, request: %ld, next: %ld, count: %ld\n",
interest->rint_event, interest->rint_request,
interest->rint_next, interest->rint_count);
prt_que("\tInterests", &interest->rint_interests);
2001-05-23 15:26:42 +02:00
}
break;
default:
2004-04-29 00:36:29 +02:00
printf("*** UNKNOWN *** (%ld)\n", block->hdr_length);
2001-05-23 15:26:42 +02:00
break;
}
if (!block->hdr_length)
break;
}
}
static void prt_que(const char* string, const srq* que_inst)
2001-05-23 15:26:42 +02:00
{
/**************************************
*
* p r t _ q u e
*
**************************************
*
* Functional description
* Print the contents of a self-relative que.
*
**************************************/
SLONG offset = SRQ_REL_PTR(que_inst);
2001-05-23 15:26:42 +02:00
if (offset == que_inst->srq_forward && offset == que_inst->srq_backward)
2004-04-29 00:36:29 +02:00
printf("%s: *empty*\n", string);
2001-05-23 15:26:42 +02:00
else
2004-04-29 00:36:29 +02:00
printf("%s: forward: %d, backward: %d\n",
2009-01-03 10:14:29 +01:00
string, que_inst->srq_forward, que_inst->srq_backward);
2001-05-23 15:26:42 +02:00
}