1#!/usr/bin/ksh
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12
13#
14# Copyright (c) 2023 Domagoj Stolfa
15#
16
17bname=`basename $0`
18dtraceout=/tmp/dtrace.$bname
19
20script()
21{
22	$dtrace -o $dtraceout.$1 -x oformat=$1 -s /dev/stdin <<__EOF__
23syscall:::entry
24{
25        self->ts = timestamp;
26}
27
28syscall:::return
29/self->ts/
30{
31        @[probefunc] = lquantize(timestamp - self->ts, 0, 1000000, 100);
32        self->ts = 0;
33}
34
35tick-5s
36{
37        exit(0);
38}
39
40END
41{
42        printa(@);
43}
44__EOF__
45}
46
47if [ $# != 1 ]; then
48	echo expected one argument: '<'dtrace-path'>'
49	exit 2
50fi
51
52dtrace=$1
53
54script json
55jq . $dtraceout.json
56
57if [ $? != 0 ]; then
58	echo $bname: failed to produce valid JSON. see $dtraceout.json
59	exit 1
60fi
61
62script xml
63xmllint $dtraceout.xml
64
65if [ $? != 0 ]; then
66	echo $bname: failed to produce valid XML. see $dtraceout.xml
67	exit 1
68fi
69
70rm $dtraceout.json
71rm $dtraceout.xml
72
73exit 0
74