mirror of
https://github.com/pi-hole/pi-hole
synced 2024-12-22 14:58:08 +00:00
Add new option allowing timing the individual parts of gravity
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
73301da68f
commit
111dfc63ff
65
gravity.sh
65
gravity.sh
@ -428,7 +428,7 @@ gravity_DownloadBlocklists() {
|
|||||||
if [[ "${check_url}" =~ ${regex} ]]; then
|
if [[ "${check_url}" =~ ${regex} ]]; then
|
||||||
echo -e " ${CROSS} Invalid Target"
|
echo -e " ${CROSS} Invalid Target"
|
||||||
else
|
else
|
||||||
gravity_DownloadBlocklistFromUrl "${url}" "${sourceIDs[$i]}" "${saveLocation}" "${target}" "${compression}" "${adlist_type}" "${domain}"
|
timeit gravity_DownloadBlocklistFromUrl "${url}" "${sourceIDs[$i]}" "${saveLocation}" "${target}" "${compression}" "${adlist_type}" "${domain}"
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
done
|
done
|
||||||
@ -855,12 +855,58 @@ gravity_optimize() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function: timeit
|
||||||
|
# Description: Measures the execution time of a given command.
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# timeit <command>
|
||||||
|
#
|
||||||
|
# Parameters:
|
||||||
|
# <command> - The command to be executed and timed.
|
||||||
|
#
|
||||||
|
# Returns:
|
||||||
|
# The exit status of the executed command.
|
||||||
|
#
|
||||||
|
# Output:
|
||||||
|
# If the 'timed' variable is set to true, prints the elapsed time in seconds
|
||||||
|
# with millisecond precision.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# timeit ls -l
|
||||||
|
#
|
||||||
|
timeit(){
|
||||||
|
local start_time end_time elapsed_time ret
|
||||||
|
|
||||||
|
# Capture the start time
|
||||||
|
start_time=$(date +%s%3N)
|
||||||
|
|
||||||
|
# Execute the command passed as arguments
|
||||||
|
"$@"
|
||||||
|
ret=$?
|
||||||
|
|
||||||
|
if [[ "${timed:-}" != true ]]; then
|
||||||
|
return $ret
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Capture the end time
|
||||||
|
end_time=$(date +%s%3N)
|
||||||
|
|
||||||
|
# Calculate the elapsed time
|
||||||
|
elapsed_time=$((end_time - start_time))
|
||||||
|
|
||||||
|
# Display the elapsed time
|
||||||
|
printf " --> took %d.%03d seconds\n" $((elapsed_time / 1000)) $((elapsed_time % 1000))
|
||||||
|
|
||||||
|
return $ret
|
||||||
|
}
|
||||||
|
|
||||||
helpFunc() {
|
helpFunc() {
|
||||||
echo "Usage: pihole -g
|
echo "Usage: pihole -g
|
||||||
Update domains from blocklists specified in adlists.list
|
Update domains from blocklists specified in adlists.list
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-f, --force Force the download of all specified blocklists
|
-f, --force Force the download of all specified blocklists
|
||||||
|
-t, --timeit Time the gravity update process
|
||||||
-h, --help Show this help dialog"
|
-h, --help Show this help dialog"
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
@ -897,6 +943,7 @@ Available options:
|
|||||||
for var in "$@"; do
|
for var in "$@"; do
|
||||||
case "${var}" in
|
case "${var}" in
|
||||||
"-f" | "--force") forceDelete=true ;;
|
"-f" | "--force") forceDelete=true ;;
|
||||||
|
"-t" | "--timeit") timed=true ;;
|
||||||
"-r" | "--repair") repairSelector "$3" ;;
|
"-r" | "--repair") repairSelector "$3" ;;
|
||||||
"-u" | "--upgrade")
|
"-u" | "--upgrade")
|
||||||
upgrade_gravityDB "${gravityDBfile}" "${piholeDir}"
|
upgrade_gravityDB "${gravityDBfile}" "${piholeDir}"
|
||||||
@ -925,11 +972,11 @@ if [[ "${recreate_database:-}" == true ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${recover_database:-}" == true ]]; then
|
if [[ "${recover_database:-}" == true ]]; then
|
||||||
database_recovery "$4"
|
timeit database_recovery "$4"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Move possibly existing legacy files to the gravity database
|
# Move possibly existing legacy files to the gravity database
|
||||||
if ! migrate_to_database; then
|
if ! timeit migrate_to_database; then
|
||||||
echo -e " ${CROSS} Unable to migrate to database. Please contact support."
|
echo -e " ${CROSS} Unable to migrate to database. Please contact support."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -943,7 +990,7 @@ if [[ "${forceDelete:-}" == true ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Gravity downloads blocklists next
|
# Gravity downloads blocklists next
|
||||||
if ! gravity_CheckDNSResolutionAvailable; then
|
if ! timeit gravity_CheckDNSResolutionAvailable; then
|
||||||
echo -e " ${CROSS} Can not complete gravity update, no DNS is available. Please contact support."
|
echo -e " ${CROSS} Can not complete gravity update, no DNS is available. Please contact support."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -961,23 +1008,23 @@ chown pihole:pihole "${gravityTEMPfile}"
|
|||||||
chmod g+w "${piholeDir}" "${gravityTEMPfile}"
|
chmod g+w "${piholeDir}" "${gravityTEMPfile}"
|
||||||
|
|
||||||
# Build the tree
|
# Build the tree
|
||||||
gravity_build_tree
|
timeit gravity_build_tree
|
||||||
|
|
||||||
# Compute numbers to be displayed (do this after building the tree to get the
|
# Compute numbers to be displayed (do this after building the tree to get the
|
||||||
# numbers quickly from the tree instead of having to scan the whole database)
|
# numbers quickly from the tree instead of having to scan the whole database)
|
||||||
gravity_ShowCount
|
timeit gravity_ShowCount
|
||||||
|
|
||||||
# Optimize the database
|
# Optimize the database
|
||||||
gravity_optimize
|
timeit gravity_optimize
|
||||||
|
|
||||||
# Migrate rest of the data from old to new database
|
# Migrate rest of the data from old to new database
|
||||||
# IMPORTANT: Swapping the databases must be the last step before the cleanup
|
# IMPORTANT: Swapping the databases must be the last step before the cleanup
|
||||||
if ! gravity_swap_databases; then
|
if ! timeit gravity_swap_databases; then
|
||||||
echo -e " ${CROSS} Unable to create database. Please contact support."
|
echo -e " ${CROSS} Unable to create database. Please contact support."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
gravity_Cleanup
|
timeit gravity_Cleanup
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
echo " ${TICK} Done."
|
echo " ${TICK} Done."
|
||||||
|
Loading…
Reference in New Issue
Block a user