blob: 6b7a6ed3d104964d7821bfab9d31f90db6d1420a [file] [log] [blame]
#!/bin/bash
#///////////////////////////////////////////////////////////////////////////////
#// Copyright (c) 2000-2019 Ericsson Telecom AB //
#// //
#// All rights reserved. This program and the accompanying materials //
#// are made available under the terms of the Eclipse Public License v2.0 //
#// which accompanies this distribution, and is available at //
#// https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html //
#///////////////////////////////////////////////////////////////////////////////
echo "prof2ttcn3 version 1.0"
FILESTOPATCH=$*
if [ ! "${FILESTOPATCH}" ]
then
echo "Adds profiler detection to TTCN"
echo "Usage: prof2ttcn3 <fileListToPatch>"
echo ""
echo "For automatic profiler patching:"
echo " Add TTCN3Profiler.grp to the project. Then"
echo " this script is automatically executed in the"
echo " bin directory."
echo ""
echo " The patched code is able to detect the"
echo " number of times a TTCN3 source line is"
echo " called."
echo " The output written to the cov files can"
echo " be used to generate profiler statistics."
echo " For that use the ttcn3cov tool."
#remove the function reference database:
if [ -r TTCN3Profiler.fns ]
then
rm TTCN3Profiler.fns
fi
exit
fi
echo "prof2ttcn3: Patching files with profiler detection..."
FILESUSED=""
for f in ${FILESTOPATCH}
do
#echo "prof2ttcn3: Processing ${f}..."
if [ ! -w $f ]
then
#echo "compiler_ttcn3cov: ${f} is readonly. Ignored..."
continue;
fi
check="$(grep "ttcn3prof.hh" ${f})"
if [ "${check}" ]
then
echo "prof2ttcn3: ${f} already processed. Ignored..."
FILESUSED="${FILESUSED} $f"
continue
fi
gawk -f $(dirname $0)/TTCN3Profiler.awk $f | tee ${f}_ > /dev/null
difference="$(diff ${f}_ $f)"
#echo ${difference}
if [ "${difference}" ]
then
#echo "prof2ttcn3: Profiler detection is added to ${f}."
rm $f
mv ${f}_ $f
FILESUSED="${FILESUSED} $f"
else
echo "prof2ttcn3: No profiler info available in: "$f
rm ${f}_
fi
#break
done
echo "prof2ttcn3: Updating function reference database"
TTCN3PROF_FNS=""
if [ -r "TTCN3Profiler.fns" ]
then
TTCN3PROF_FNS="TTCN3Profiler.fns"
fi
gawk -f $(dirname $0)/ExtractFunctions.awk ${FILESUSED} ${TTCN3PROF_FNS} > TTCN3Profiler.fns_
if [ ! -r TTCN3Profiler.fns ]
then
difference="yes"
else
difference="$(diff TTCN3Profiler.fns_ TTCN3Profiler.fns)"
fi
#echo ${difference}
if [ "${difference}" ]
then
mv TTCN3Profiler.fns_ TTCN3Profiler.fns
echo "prof2ttcn3: Function reference database updated"
else
rm TTCN3Profiler.fns_
echo "prof2ttcn3: Function reference database is up-to-date"
fi