#
# SPDX-License-Identifier: LGPL-2.1-only
-function get_env_value ()
+function get_env_value_ctf1 ()
{
local env_file=$1
local key=$2
fi
}
+# Expects a json representing the environment of a trace_class fragment.
+function get_env_value_ctf2 ()
+{
+ local env_file=$1
+ local key=$2
+ local result
+ local ret
+
+ if [[ "$key" == "vpid =" ]]; then
+ # The "vpid =" key value is only because the ctf1 extractor uses
+ # grep. jq use the complete key.
+ key="vpid"
+ fi
+
+
+ result=$(jq -r ".${key}" < "$env_file")
+ ret=$?
+ if [ $ret -eq 1 ]; then
+ echo "invalid_value_extraction"
+ return 1
+ else
+ echo "$result"
+ return 0
+ fi
+}
+
+function get_env_value ()
+{
+ if [ "$TRACE_FORMAT_OUTPUT" == "ctf1" ]; then
+ get_env_value_ctf1 "$@"
+ elif [ "$TRACE_FORMAT_OUTPUT" == "ctf2" ]; then
+ get_env_value_ctf2 "$@"
+ else
+ return 1
+ fi
+}
+
+function extract_env_to_file_ctf1 ()
+{
+ local source_dir=$1
+ local destination=$2
+ local env
+
+ env=$($BABELTRACE_BIN --output-format=ctf-metadata "${source_dir}")
+
+ # Extract "env" scope
+ awk '/env {/,/};/' <<< "$env" > "$destination"
+}
+
+function extract_env_to_file_ctf2 ()
+{
+ local source_file="$1/metadata"
+ local destination=$2
+ local query="select(.type == \"trace-class\").environment"
+ jq "$query" "$source_file" > "$destination"
+}
+
+function extract_env_to_file ()
+{
+ if [ "$TRACE_FORMAT_OUTPUT" == "ctf1" ]; then
+ extract_env_to_file_ctf1 "$@"
+ return $?
+ elif [ "$TRACE_FORMAT_OUTPUT" == "ctf2" ]; then
+ extract_env_to_file_ctf2 "$@"
+ return $?
+ else
+ return 1
+ fi
+}
+
function iso8601_to_lttng_dir_datetime ()
{
local result=$1