#!/bin/bash

if [ "$#" -ne 2 ]; then
	echo "Usage: ${0} /path/to/pdf /path/to/input"
	echo "WARNING: For now, parameters are passed unchecked to perf record"
	exit 1
fi

PDFPATH=$1
INPUTPATH=$2

EVENTS='{'\
'probe_pdf:init_parser,'\
'probe_pdf:init_runlengthdecode_parser,'\
'probe_pdf:kstream,'\
'probe_pdf:kxstream,'\
'probe_pdf:ASCIIHexDecode,'\
'probe_pdf:ASCII85Decode,'\
'probe_pdf:LZWDecode,'\
'probe_pdf:FlateDecode,'\
'probe_pdf:RunLengthDecode,'\
'probe_libhammer:h_do_parse,'\
'probe_libhammer:perform_lowlevel_parse,'\
'probe_libhammer:h_packrat_parse,'\
'probe_libhammer:h_arena_malloc_raw,'\
'probe_libhammer:parse_choice,'\
'probe_libhammer:parse_action,'\
'probe_libhammer:parse_sequence,'\
'probe_libhammer:parse_difference,'\
'probe_libhammer:parse_many,'\
'probe_libhammer:parse_and,'\
'probe_libhammer:parse_attr_bool,'\
'probe_libhammer:parse_bind,'\
'probe_libhammer:parse_bits,'\
'probe_libhammer:parse_butnot,'\
'probe_libhammer:parse_charset,'\
'probe_libhammer:parse_ch,'\
'probe_libhammer:parse_end,'\
'probe_libhammer:parse_endianness,'\
'probe_libhammer:parse_epsilon,'\
'probe_libhammer:parse_ignore,'\
'probe_libhammer:parse_ignoreseq,'\
'probe_libhammer:parse_indirect,'\
'probe_libhammer:parse_int_range,'\
'probe_libhammer:parse_not,'\
'probe_libhammer:parse_nothing,'\
'probe_libhammer:parse_optional,'\
'probe_libhammer:parse_permutation,'\
'probe_libhammer:parse_skip,'\
'probe_libhammer:parse_seek,'\
'probe_libhammer:parse_tell,'\
'probe_libhammer:parse_token,'\
'probe_libhammer:parse_unimplemented,'\
'probe_libhammer:parse_put,'\
'probe_libhammer:parse_get,'\
'probe_libhammer:parse_whitespace,'\
'probe_libhammer:parse_xor,'\
'probe_libhammer:perform_lowlevel_parse__return,'\
'probe_libhammer:h_packrat_parse__return'\
'}'

echo "Running perf record with the following events:"
echo $EVENTS

perf record -m 8192 -a -e $EVENTS $PDFPATH $INPUTPATH
