Add script to generate dump info file
This commit introduces the gendumpinfo script which generates the
info.yaml file containing metadata about the dump. It also updates
the meson.build files to include this script in the build process
and ensures it gets installed correctly.
Change-Id: Idcd550ceac912ff42ce2df2bfcb333b4c8b8644b
Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
diff --git a/.shellcheck-ignore b/.shellcheck-ignore
index e5c4d18..6f5e42c 100644
--- a/.shellcheck-ignore
+++ b/.shellcheck-ignore
@@ -1,2 +1,3 @@
dump/tools/common/include/gendumpheader
dump/tools/opdump/opdreport
+dump/tools/common/include/gendumpinfo
diff --git a/dump/meson.build b/dump/meson.build
index a826197..25017e4 100644
--- a/dump/meson.build
+++ b/dump/meson.build
@@ -29,8 +29,10 @@
)
bindir = get_option('bindir')
+dreport_include_dir = join_paths(get_option('datadir'), 'dreport.d/include.d')
-scripts_to_install = []
+scripts_to_install = []
+include_scripts = []
subdir('tools')
# Install collected files if any
@@ -41,3 +43,12 @@
)
endif
+# Install collected include scripts if any
+if include_scripts.length() > 0
+ install_data(include_scripts,
+ install_dir: dreport_include_dir,
+ install_mode: 'rwxr-xr-x'
+ )
+endif
+
+
diff --git a/dump/tools/common/include/gendumpinfo b/dump/tools/common/include/gendumpinfo
new file mode 100644
index 0000000..5067ccf
--- /dev/null
+++ b/dump/tools/common/include/gendumpinfo
@@ -0,0 +1,73 @@
+#!/bin/bash
+# shellcheck disable=SC2154
+
+# Constants
+declare -rx DUMP_MANAGER='xyz.openbmc_project.Dump.Manager'
+declare -rx DUMP_PATH='/xyz/openbmc_project/dump/opdump/entry'
+declare -rx DUMP_PROP='xyz.openbmc_project.Common.Progress'
+
+# Variables
+declare -x DRIVER=""
+declare -x YAML_FILE=""
+declare -x ADDL_DATA_PATH=""
+declare -x START_TIME=0
+declare -x END_TIME=0
+
+# Initialize variables
+function initialize_variables() {
+ DRIVER=$(awk -F '[=()]' '/VERSION_ID/ {print $2}' /etc/os-release)
+ YAML_FILE="$content_path/info.yaml"
+ ADDL_DATA_PATH="$content_path/plat_dump/additional_data/"
+}
+
+# Function to get the dump start and completed time
+function dump_time_details() {
+ START_TIME=$(busctl get-property "$DUMP_MANAGER" "$DUMP_PATH/$dump_id" \
+ "$DUMP_PROP" StartTime | awk '{print $2}')
+ END_TIME=$(busctl get-property "$DUMP_MANAGER" "$DUMP_PATH/$dump_id" \
+ "$DUMP_PROP" CompletedTime | awk '{print $2}')
+
+ if [ -z "$START_TIME" ] || [ "$START_TIME" -eq 0 ]; then
+ echo "Could not fetch start time for $dump_id. Setting manually"
+ START_TIME=$(date +%s)
+ fi
+
+ start=$(date -d @"$START_TIME" +'%Y-%m-%d %H:%M:%S')
+ if [ -z "$END_TIME" ] || [ "$END_TIME" -eq 0 ]; then
+ echo "Could not fetch end time for $dump_id. Setting manually"
+ END_TIME=$(date +%s)
+ fi
+ end=$(date -d @"$END_TIME" +'%Y-%m-%d %H:%M:%S')
+
+ printf "dump-start-time: %s\n" "$start" >> "$YAML_FILE"
+ printf "dump-end-time: %s\n" "$end" >> "$YAML_FILE"
+}
+
+# Function to fetch additional details
+function get_addl_data() {
+ if [ -d "$ADDL_DATA_PATH" ]; then
+ for entry in "$ADDL_DATA_PATH"/*; do
+ while IFS= read -r line; do
+ echo "$line" >> "$YAML_FILE"
+ done < "$entry"
+ done
+ fi
+}
+
+# Function to write data to info.yaml file
+function write_to_info_file() {
+ {
+ printf "%s\n" "# SPDX-License-Identifier: GPL-2.0"
+ printf "%s\n" "%YAML 1.2"
+ printf "%s\n\n" "---"
+ printf "generation: p10\n"
+ printf "driver: %s\n" "$DRIVER"
+ } >> "$YAML_FILE"
+ dump_time_details
+ get_addl_data
+}
+
+# Run main
+initialize_variables
+write_to_info_file
+
diff --git a/dump/tools/common/include/meson.build b/dump/tools/common/include/meson.build
index 449a172..baac424 100644
--- a/dump/tools/common/include/meson.build
+++ b/dump/tools/common/include/meson.build
@@ -1 +1,2 @@
-include_scripts += meson.current_source_dir() / 'gendumpheader'
\ No newline at end of file
+include_scripts += meson.current_source_dir() / 'gendumpheader'
+include_scripts += meson.current_source_dir() / 'gendumpinfo'
diff --git a/dump/tools/common/meson.build b/dump/tools/common/meson.build
new file mode 100644
index 0000000..1e82fd3
--- /dev/null
+++ b/dump/tools/common/meson.build
@@ -0,0 +1 @@
+subdir('include')
\ No newline at end of file
diff --git a/dump/tools/meson.build b/dump/tools/meson.build
index af9c6b0..fed2cca 100644
--- a/dump/tools/meson.build
+++ b/dump/tools/meson.build
@@ -1 +1,2 @@
-subdir('opdump')
\ No newline at end of file
+subdir('opdump')
+subdir('common')
\ No newline at end of file