2
* PROGRAM: JRD Access Method
4
* DESCRIPTION: Performance monitoring routines
6
* The contents of this file are subject to the Interbase Public
7
* License Version 1.0 (the "License"); you may not use this file
8
* except in compliance with the License. You may obtain a copy
9
* of the License at http://www.Inprise.com/IPL.html
11
* Software distributed under the License is distributed on an
12
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
13
* or implied. See the License for the specific language governing
14
* rights and limitations under the License.
16
* The Original Code was created by Inprise Corporation
17
* and its predecessors. Portions created by Inprise Corporation are
18
* Copyright (C) Inprise Corporation.
20
* All Rights Reserved.
21
* Contributor(s): ______________________________________.
23
* 2002.02.15 Sean Leyne - Code Cleanup, removed obsolete "DELTA" port
24
* 2002.02.15 Sean Leyne - Code Cleanup, removed obsolete "IMP" port
26
* 2002.10.30 Sean Leyne - Removed support for obsolete "PC_PLATFORM" define
33
#include "../common/classes/timestamp.h"
34
#include "../jrd/common.h"
35
#include "../jrd/ibase.h"
36
#include "../jrd/perf.h"
37
#include "../jrd/gds_proto.h"
38
#include "../jrd/perf_proto.h"
39
#include "../jrd/gdsassert.h"
41
#ifdef HAVE_SYS_TIMES_H
42
#include <sys/times.h>
44
#ifdef HAVE_SYS_TIMEB_H
45
# include <sys/timeb.h>
49
static SLONG get_parameter(const SCHAR**);
51
static void times(struct tms*);
54
static const SCHAR items[] = {
59
isc_info_page_size, isc_info_num_buffers,
60
isc_info_current_memory, isc_info_max_memory
63
static const SCHAR* report =
64
"elapsed = !e cpu = !u reads = !r writes = !w fetches = !f marks = !m$";
71
#if defined(WIN_NT) && !defined(CLOCKS_PER_SEC)
75
/* EKU: TICK (sys/param.h) and CLOCKS_PER_SEC (time.h) may both be defined */
76
#if !defined(TICK) && defined(CLOCKS_PER_SEC)
77
#define TICK ((SLONG)CLOCKS_PER_SEC)
81
#define TICK ((SLONG)CLK_TCK)
85
int API_ROUTINE perf_format(
88
const SCHAR* string, SCHAR* buffer, SSHORT* buf_len)
90
/**************************************
92
* P E R F _ f o r m a t
94
**************************************
96
* Functional description
97
* Format a buffer with statistical stuff under control of formatting
98
* string. Substitute in appropriate stuff. Return the length of the
101
**************************************/
104
SLONG buffer_length = (buf_len) ? *buf_len : 0;
107
while ((c = *string++) && c != '$') {
112
switch (c = *string++) {
114
delta = after->perf_reads - before->perf_reads;
117
delta = after->perf_writes - before->perf_writes;
120
delta = after->perf_fetches - before->perf_fetches;
123
delta = after->perf_marks - before->perf_marks;
127
after->perf_current_memory - before->perf_current_memory;
130
delta = after->perf_page_size;
133
delta = after->perf_buffers;
136
delta = after->perf_current_memory;
139
delta = after->perf_max_memory;
142
delta = after->perf_elapsed - before->perf_elapsed;
145
delta = after->perf_times.tms_utime -
146
before->perf_times.tms_utime;
149
delta = after->perf_times.tms_stime -
150
before->perf_times.tms_stime;
153
sprintf(p, "?%c?", c);
168
sprintf(p, "%"SLONGFORMAT, delta);
176
sprintf(p, "%"SLONGFORMAT".%.2"SLONGFORMAT, delta / 100, (delta % 100));
178
sprintf(p, "%"SLONGFORMAT".%.2"SLONGFORMAT, delta / TICK,
179
(delta % TICK) * 100 / TICK);
186
sprintf(p, "%"SLONGFORMAT".%.2"SLONGFORMAT, delta / 100, delta % 100);
195
const int length = p - buffer;
196
if (buffer_length && (buffer_length -= length) >= 0) {
197
memset(p, ' ', buffer_length);
204
void API_ROUTINE perf_get_info(FB_API_HANDLE* handle, PERF* perf)
206
/**************************************
208
* P E R F _ g e t _ i n f o
210
**************************************
212
* Functional description
213
* Acquire timing and performance information. Some info comes
214
* from the system and some from the database.
216
**************************************/
217
SSHORT buffer_length, item_length;
218
ISC_STATUS_ARRAY jrd_status;
219
#ifdef HAVE_GETTIMEOFDAY
222
struct timeb time_buffer;
223
#define LARGE_NUMBER 696600000 /* to avoid overflow, get rid of decades) */
226
/* If there isn't a database, zero everything out */
229
memset(perf, 0, sizeof(PERF));
232
/* Get system times */
234
times(&perf->perf_times);
236
#ifdef HAVE_GETTIMEOFDAY
238
perf->perf_elapsed = tp.tv_sec * 100 + tp.tv_usec / 10000;
242
(time_buffer.time - LARGE_NUMBER) * 100 + (time_buffer.millitm / 10);
249
buffer_length = sizeof(buffer);
250
item_length = sizeof(items);
251
isc_database_info(jrd_status,
253
item_length, items, buffer_length, buffer);
255
const char* p = buffer;
260
perf->perf_reads = get_parameter(&p);
263
case isc_info_writes:
264
perf->perf_writes = get_parameter(&p);
268
perf->perf_marks = get_parameter(&p);
271
case isc_info_fetches:
272
perf->perf_fetches = get_parameter(&p);
275
case isc_info_num_buffers:
276
perf->perf_buffers = get_parameter(&p);
279
case isc_info_page_size:
280
perf->perf_page_size = get_parameter(&p);
283
case isc_info_current_memory:
284
perf->perf_current_memory = get_parameter(&p);
287
case isc_info_max_memory:
288
perf->perf_max_memory = get_parameter(&p);
295
if (p[2] == isc_info_marks)
296
perf->perf_marks = 0;
297
else if (p[2] == isc_info_current_memory)
298
perf->perf_current_memory = 0;
299
else if (p[2] == isc_info_max_memory)
300
perf->perf_max_memory = 0;
302
const SLONG temp = isc_vax_integer(p, 2);
303
fb_assert(temp <= MAX_SSHORT);
306
perf->perf_marks = 0;
315
void API_ROUTINE perf_report(
317
const PERF* after, SCHAR* buffer, SSHORT* buf_len)
319
/**************************************
321
* p e r f _ r e p o r t
323
**************************************
325
* Functional description
326
* Report a common set of parameters.
328
**************************************/
330
perf_format(before, after, report, buffer, buf_len);
334
static SLONG get_parameter(const SCHAR** ptr)
336
/**************************************
338
* g e t _ p a r a m e t e r
340
**************************************
342
* Functional description
343
* Get a parameter (length is encoded), convert to internal form,
346
**************************************/
347
SSHORT l = *(*ptr)++;
348
l += (*(*ptr)++) << 8;
349
const SLONG parameter = isc_vax_integer(*ptr, l);
357
static void times(struct tms* buffer)
359
/**************************************
363
**************************************
365
* Functional description
366
* Emulate the good old unix call "times". Only both with user time.
368
**************************************/
370
buffer->tms_utime = clock();