1 /* MDB Tools - A library for reading MS Access database files
2 * Copyright (C) 2000 Brian Bruns
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "mdbtools.h"
21
22 #ifdef DMALLOC
23 #include "dmalloc.h"
24 #endif
25
26 /**
27 * mdb_stats_on:
28 * @mdb: Handle to the (open) MDB file to collect stats on.
29 *
30 * Begins collection of statistics on an MDBHandle.
31 *
32 * Statistics in LibMDB will track the number of reads from the MDB file. The
33 * collection of statistics is started and stopped with the mdb_stats_on and
34 * mdb_stats_off functions. Collected statistics are accessed by reading the
35 * MdbStatistics structure or calling mdb_dump_stats.
36 *
37 */
38 void
mdb_stats_on(MdbHandle * mdb)39 mdb_stats_on(MdbHandle *mdb)
40 {
41 if (!mdb->stats)
42 mdb->stats = g_malloc0(sizeof(MdbStatistics));
43
44 mdb->stats->collect = TRUE;
45 }
46 /**
47 * mdb_stats_off:
48 * @mdb: pointer to handle of MDB file with active stats collection.
49 *
50 * Turns off statistics collection.
51 *
52 * If mdb_stats_off is not called, statistics will be turned off when handle
53 * is freed using mdb_close.
54 **/
55 void
mdb_stats_off(MdbHandle * mdb)56 mdb_stats_off(MdbHandle *mdb)
57 {
58 if (!mdb->stats) return;
59
60 mdb->stats->collect = FALSE;
61 }
62 /**
63 * mdb_dump_stats:
64 * @mdb: pointer to handle of MDB file with active stats collection.
65 *
66 * Dumps current statistics to stdout.
67 **/
68 void
mdb_dump_stats(MdbHandle * mdb)69 mdb_dump_stats(MdbHandle *mdb)
70 {
71 if (!mdb->stats) return;
72
73 fprintf(stdout, "Physical Page Reads: %lu\n", mdb->stats->pg_reads);
74 }
75