1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 *
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V.
7 */
8
9/* (c) M Kersten
10 * The easiest calling method is something like:
11 * tomograph -d demo --atlast=10
12 * which connects to the demo database server and
13 * will collect the tomograph pages for at most 10 SQL queries
14 * For each page a gnuplot file, a data file, and the event trace
15 * are collected for more focussed analysis.
16 *
17*/
18
19#ifndef _EVENT_PARSER_
20#define _EVENT_PARSER_
21
22#include "mapi.h"
23#include "stream.h"
24#include <string.h>
25#include <sys/stat.h>
26#include <signal.h>
27#include <unistd.h>
28#include <time.h>
29
30#define TME_US 1
31#define TME_MS 2
32#define TME_SS 4
33#define TME_MM 8
34#define TME_HH 16
35#define TME_DD 32
36
37#define US_MS ((int64_t) 1000)
38#define US_SS (US_MS * 1000)
39#define US_MM (US_SS * 60)
40#define US_HH (US_MM * 60)
41#define US_DD (US_HH * 24)
42
43#define MDB_START 1
44#define MDB_DONE 2
45#define MDB_PING 3
46#define MDB_WAIT 4
47#define MDB_SYSTEM 5
48
49extern char *statenames[];
50
51#define MAXMALARGS 2048
52
53// the break down of a profiler event message
54typedef struct {
55 // system state
56 char *version;
57 char *release;
58 char *threads;
59 char *memory;
60 char *host;
61 int oid;
62 char *package;
63
64 // event state
65 int index; // return/arg index
66 int state;
67 char *function; // name of MAL block
68 char *user;
69 int pc; // instruction counter in block
70 int tag; // unique MAL block invocation tag
71 int64_t eventnr;// serial event number
72 int thread; // worker thread involved
73 int64_t usec; // usec since start of session
74 char *time; // string rep of clock
75 int64_t clkticks;
76 int64_t ticks;
77 int64_t rss;
78 int64_t size; // size of temporary produced
79 int64_t inblock;
80 int64_t oublock;
81 int64_t majflt;
82 int64_t swaps;
83 int64_t csw;
84 char *stmt; // MAL statement, cpu loads or commentary
85 char *beauty;// MAL statement compressed
86 char *fcn; // MAL operator
87 char *numa;
88 char *prereq; // pre-requisite statements
89} EventRecord;
90
91extern char *maltypes[MAXMALARGS];
92extern char *malvariables[MAXMALARGS];
93extern char *malvalues[MAXMALARGS];
94extern int malsize;
95extern int debug;
96extern char *currentquery;
97
98extern void resetEventRecord(EventRecord *ev);
99extern void eventdump(void);
100extern int keyvalueparser(char *txt, EventRecord *ev);
101extern int lineparser(char *row, EventRecord *ev);
102extern void renderJSONevent(FILE *fd, EventRecord *ev, int notfirst);
103extern char *stripQuotes(char *currentquery);
104#endif /*_EVENT_PARSER_*/
105