3 # Copyright (C) 2019 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
5 # SPDX-License-Identifier: LGPL-2.1-only
7 function get_env_value_ctf1
()
14 result
=$
(grep "$key" < "$env_file")
16 if [ $ret -eq 1 ]; then
17 echo "invalid_value_extraction"
20 # Strip the key using bash substring removal.
21 # This remove all leading chars until the actual value.
24 # Remove the trailing ';'
27 # Remove enclosing '"' if present
28 if [ "${result:0:1}" == '"' ]; then
37 # Expects a json representing the environment of a trace_class fragment.
38 function get_env_value_ctf2
()
45 if [[ "$key" == "vpid =" ]]; then
46 # The "vpid =" key value is only because the ctf1 extractor uses
47 # grep. jq use the complete key.
52 result
=$
(jq
-r ".${key}" < "$env_file")
54 if [ $ret -eq 1 ]; then
55 echo "invalid_value_extraction"
63 function get_env_value
()
65 if [ "$TRACE_FORMAT_OUTPUT" == "ctf1" ]; then
66 get_env_value_ctf1
"$@"
67 elif [ "$TRACE_FORMAT_OUTPUT" == "ctf2" ]; then
68 get_env_value_ctf2
"$@"
74 function extract_env_to_file_ctf1
()
80 env
=$
($BABELTRACE_BIN --output-format=ctf-metadata
"${source_dir}")
83 awk '/env {/,/};/' <<< "$env" > "$destination"
86 function extract_env_to_file_ctf2
()
88 local source_file
="$1/metadata"
90 local query
="select(.type == \"trace-class\").environment"
91 jq
"$query" "$source_file" > "$destination"
94 function extract_env_to_file
()
96 if [ "$TRACE_FORMAT_OUTPUT" == "ctf1" ]; then
97 extract_env_to_file_ctf1
"$@"
99 elif [ "$TRACE_FORMAT_OUTPUT" == "ctf2" ]; then
100 extract_env_to_file_ctf2
"$@"
107 function iso8601_to_lttng_dir_datetime
()
113 # Remove trailing timezone information including the '-'.
114 result
=${result:0:-5}