@luxonis/depthai-viewer-common 2.5.1 → 2.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/benchmark.sh CHANGED
@@ -3,28 +3,246 @@
3
3
  set -euo pipefail
4
4
 
5
5
  SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6
+ source "${SCRIPT_DIR}/benchmark-lib.sh"
7
+ benchmark_init_ui
8
+
6
9
  BENCHMARKS_DIR="${SCRIPT_DIR}/src/utils/benchmarks"
7
10
  INTER_BENCHMARK_DELAY_SECONDS="${BENCHMARK_INTER_BENCHMARK_DELAY_SECONDS:-5}"
8
11
  FINALIZATION_DELAY_SECONDS="${BENCHMARK_FINALIZATION_DELAY_SECONDS:-8}"
9
-
10
- BENCHMARKS=(
11
- "bgr888i-stream|BGR888i Stream"
12
- "encoded-stream|H.264 Stream"
13
- "nv12-stream|NV12 Stream"
14
- "pointcloud|Point Cloud"
15
- )
16
12
  BENCHMARK_RESOLUTION="${BENCHMARK_RESOLUTION:-1920x1080}"
13
+ MAX_DOWNLOAD_ATTEMPTS="${BENCHMARK_DOWNLOAD_RETRIES:-3}"
14
+ BENCHMARK_CURL_PROGRESS="${BENCHMARK_CURL_PROGRESS:-1}"
15
+ BENCHMARK_SKIP_DOWNLOAD="${BENCHMARK_SKIP_DOWNLOAD:-0}"
16
+ BENCHMARK_COMMAND='run'
17
+ BENCHMARK_PROGRESS_EVENT_PREFIX='__BENCHMARK_PROGRESS__'
17
18
 
18
19
  trap 'exit 130' INT
19
20
  trap 'exit 143' TERM
20
21
 
21
22
  log() {
22
- printf '[benchmark] %s\n' "$1"
23
+ benchmark_log info "$1"
24
+ }
25
+
26
+ emit_progress_event() {
27
+ if [[ "${BENCHMARK_CURL_PROGRESS}" != '0' ]]; then
28
+ return
29
+ fi
30
+
31
+ printf '%s|%s|%s|%s|%s|%s\n' \
32
+ "${BENCHMARK_PROGRESS_EVENT_PREFIX}" \
33
+ "$1" \
34
+ "$2" \
35
+ "$3" \
36
+ "$4" \
37
+ "$5"
38
+ }
39
+
40
+ print_usage() {
41
+ cat <<EOF
42
+ Usage:
43
+ ./benchmark.sh run [options]
44
+ ./benchmark.sh download [options]
45
+ ./benchmark.sh list
46
+
47
+ Commands:
48
+ run Download the selected benchmarks and run them.
49
+ download Download the selected benchmarks only.
50
+ list Show available benchmark ids.
51
+
52
+ Options:
53
+ --benchmark ID Select a single benchmark id. Can be repeated.
54
+ --benchmarks ID1,ID2 Select a comma-separated list of benchmark ids.
55
+ --resolution WIDTHxHEIGHT Resize image benchmarks before publishing when running.
56
+ -h, --help Show this help message.
57
+
58
+ Examples:
59
+ ./benchmark.sh run
60
+ ./benchmark.sh run --benchmark encoded-stream
61
+ ./benchmark.sh run --benchmarks bgr888i-stream,nv12-stream
62
+ ./benchmark.sh download --benchmark pointcloud
63
+ EOF
64
+ }
65
+
66
+ file_size() {
67
+ local file_path=$1
68
+ stat -f%z "${file_path}" 2>/dev/null || stat -c%s "${file_path}"
69
+ }
70
+
71
+ install_requirements() {
72
+ local requirements_file="${BENCHMARKS_DIR}/requirements.txt"
73
+ benchmark_run_with_spinner \
74
+ "Installing Python dependencies from ${requirements_file}" \
75
+ python3 -m pip install --quiet -r "${requirements_file}"
76
+ }
77
+
78
+ get_remote_file_size() {
79
+ local url=$1
80
+ curl --head --silent --show-error --location --fail "${url}" |
81
+ awk 'BEGIN { IGNORECASE = 1 } /^content-length:/ { gsub("\r", "", $2); print $2; exit }'
82
+ }
83
+
84
+ download_asset() {
85
+ local benchmark_id=$1
86
+ local file_name=$2
87
+ local url=$3
88
+ local benchmark_dir="${BENCHMARKS_DIR}/${benchmark_id}"
89
+ local output_path="${benchmark_dir}/${file_name}"
90
+ local partial_path="${output_path}.part"
91
+ local expected_size=""
92
+ local final_size=""
93
+ local partial_size=""
94
+ local download_mode='download'
95
+ local attempt=1
96
+ local curl_args=(--fail --location --output "${partial_path}" "${url}")
97
+
98
+ if [[ "${BENCHMARK_CURL_PROGRESS}" == '1' ]]; then
99
+ curl_args=(--progress-bar "${curl_args[@]}")
100
+ else
101
+ curl_args=(--silent --show-error "${curl_args[@]}")
102
+ fi
103
+
104
+ mkdir -p "${benchmark_dir}"
105
+ expected_size="$(get_remote_file_size "${url}" || true)"
106
+
107
+ if [[ -f "${output_path}" ]]; then
108
+ if [[ -n "${expected_size}" ]]; then
109
+ final_size="$(file_size "${output_path}")"
110
+ if [[ "${final_size}" == "${expected_size}" ]]; then
111
+ log "Using existing asset ${file_name} for ${benchmark_id}"
112
+ return
113
+ fi
114
+
115
+ log "Existing file size mismatch for ${file_name}: found ${final_size} bytes, expected ${expected_size} bytes. Preparing to resume..."
116
+ else
117
+ log "Using existing asset ${file_name} for ${benchmark_id}"
118
+ return
119
+ fi
120
+
121
+ if [[ -f "${partial_path}" ]]; then
122
+ partial_size="$(file_size "${partial_path}")"
123
+ if [[ "${partial_size}" -lt "${final_size}" ]]; then
124
+ rm -f "${partial_path}"
125
+ mv "${output_path}" "${partial_path}"
126
+ else
127
+ rm -f "${output_path}"
128
+ fi
129
+ else
130
+ mv "${output_path}" "${partial_path}"
131
+ fi
132
+ fi
133
+
134
+ if [[ -f "${partial_path}" ]]; then
135
+ if [[ -n "${expected_size}" ]]; then
136
+ partial_size="$(file_size "${partial_path}")"
137
+ if [[ "${partial_size}" == "${expected_size}" ]]; then
138
+ mv "${partial_path}" "${output_path}"
139
+ log "Recovered completed asset ${file_name} for ${benchmark_id}"
140
+ return
141
+ fi
142
+
143
+ if [[ "${partial_size}" -gt "${expected_size}" ]]; then
144
+ log "Partial download for ${file_name} is larger than expected. Restarting download..."
145
+ rm -f "${partial_path}"
146
+ else
147
+ log "Resuming ${file_name} for ${benchmark_id} from ${partial_size} of ${expected_size} bytes"
148
+ download_mode='resume'
149
+ fi
150
+ else
151
+ log "Resuming ${file_name} for ${benchmark_id} from existing partial file"
152
+ download_mode='resume'
153
+ fi
154
+
155
+ curl_args=(--continue-at - "${curl_args[@]}")
156
+ else
157
+ log "Downloading ${file_name} for ${benchmark_id}"
158
+ fi
159
+
160
+ emit_progress_event "start" "${benchmark_id}" "${file_name}" "${partial_path}" "${expected_size}" "${download_mode}"
161
+
162
+ while (( attempt <= MAX_DOWNLOAD_ATTEMPTS )); do
163
+ if curl "${curl_args[@]}"; then
164
+ if [[ -n "${expected_size}" ]]; then
165
+ partial_size="$(file_size "${partial_path}")"
166
+ if [[ "${partial_size}" != "${expected_size}" ]]; then
167
+ log "Downloaded size mismatch for ${file_name}: expected ${expected_size} bytes, got ${partial_size} bytes"
168
+ else
169
+ mv "${partial_path}" "${output_path}"
170
+ emit_progress_event "finish" "${benchmark_id}" "${file_name}" "${output_path}" "${expected_size}" "success"
171
+ log "Download completed: ${file_name}"
172
+ return
173
+ fi
174
+ else
175
+ mv "${partial_path}" "${output_path}"
176
+ emit_progress_event "finish" "${benchmark_id}" "${file_name}" "${output_path}" "" "success"
177
+ log "Download completed: ${file_name}"
178
+ return
179
+ fi
180
+ fi
181
+
182
+ if (( attempt == MAX_DOWNLOAD_ATTEMPTS )); then
183
+ emit_progress_event "finish" "${benchmark_id}" "${file_name}" "${partial_path}" "${expected_size}" "failed"
184
+ log "Download failed for ${file_name} after ${MAX_DOWNLOAD_ATTEMPTS} attempts"
185
+ return 1
186
+ fi
187
+
188
+ log "Retrying ${file_name} (${attempt}/${MAX_DOWNLOAD_ATTEMPTS})..."
189
+ attempt=$((attempt + 1))
190
+ done
191
+ }
192
+
193
+ download_selected_assets() {
194
+ local benchmark_id benchmark_asset asset_benchmark_id file_name url
195
+
196
+ if (( ${#BENCHMARK_SELECTED_IDS[@]} == 0 )); then
197
+ return
198
+ fi
199
+
200
+ for benchmark_id in "${BENCHMARK_SELECTED_IDS[@]}"; do
201
+ while IFS= read -r benchmark_asset; do
202
+ if [[ -z "${benchmark_asset}" ]]; then
203
+ continue
204
+ fi
205
+
206
+ IFS='|' read -r asset_benchmark_id file_name url <<<"${benchmark_asset}"
207
+ download_asset "${asset_benchmark_id}" "${file_name}" "${url}"
208
+ done < <(benchmark_print_assets_for_id "${benchmark_id}")
209
+ done
23
210
  }
24
211
 
25
212
  parse_args() {
213
+ if [[ $# -gt 0 ]]; then
214
+ case "$1" in
215
+ run|download|list)
216
+ BENCHMARK_COMMAND="$1"
217
+ shift
218
+ ;;
219
+ -h|--help|help)
220
+ print_usage
221
+ exit 0
222
+ ;;
223
+ esac
224
+ fi
225
+
226
+ BENCHMARK_SELECTED_IDS=()
227
+
26
228
  while [[ $# -gt 0 ]]; do
27
229
  case "$1" in
230
+ --benchmark)
231
+ if [[ $# -lt 2 ]]; then
232
+ log 'Missing value for --benchmark'
233
+ exit 1
234
+ fi
235
+ benchmark_add_selected_id "$2" || exit 1
236
+ shift 2
237
+ ;;
238
+ --benchmarks)
239
+ if [[ $# -lt 2 ]]; then
240
+ log 'Missing value for --benchmarks'
241
+ exit 1
242
+ fi
243
+ benchmark_add_selected_csv "$2" || exit 1
244
+ shift 2
245
+ ;;
28
246
  --resolution)
29
247
  if [[ $# -lt 2 ]]; then
30
248
  log 'Missing value for --resolution'
@@ -51,13 +269,12 @@ parse_args() {
51
269
  BENCHMARK_RESOLUTION="$2"
52
270
  shift 2
53
271
  ;;
272
+ list)
273
+ BENCHMARK_COMMAND='list'
274
+ shift
275
+ ;;
54
276
  -h|--help)
55
- cat <<EOF
56
- Usage: ./benchmark.sh [--resolution WIDTHxHEIGHT]
57
-
58
- Options:
59
- --resolution WIDTHxHEIGHT Resize image benchmarks before publishing.
60
- EOF
277
+ print_usage
61
278
  exit 0
62
279
  ;;
63
280
  *)
@@ -66,6 +283,8 @@ EOF
66
283
  ;;
67
284
  esac
68
285
  done
286
+
287
+ benchmark_select_all_if_empty
69
288
  }
70
289
 
71
290
  run_benchmark() {
@@ -93,12 +312,38 @@ run_benchmark() {
93
312
 
94
313
  parse_args "$@"
95
314
 
96
- for benchmark_index in "${!BENCHMARKS[@]}"; do
97
- benchmark_config="${BENCHMARKS[benchmark_index]}"
98
- IFS='|' read -r benchmark_id _topic_name <<<"${benchmark_config}"
315
+ if [[ "${BENCHMARK_COMMAND}" == 'list' ]]; then
316
+ benchmark_print_available
317
+ exit 0
318
+ fi
319
+
320
+ if [[ "${BENCHMARK_COMMAND}" == 'run' ]]; then
321
+ benchmark_print_selection_summary "${BENCHMARK_COMMAND}" "${BENCHMARK_RESOLUTION}"
322
+ else
323
+ benchmark_print_selection_summary "${BENCHMARK_COMMAND}"
324
+ fi
325
+ if [[ "${BENCHMARK_COMMAND}" == 'download' ]]; then
326
+ benchmark_run_with_spinner 'Upgrading pip' python3 -m pip install --quiet --upgrade pip
327
+ install_requirements
328
+ download_selected_assets
329
+ benchmark_log success 'Benchmark assets are ready'
330
+ exit 0
331
+ fi
332
+
333
+ if [[ "${BENCHMARK_SKIP_DOWNLOAD}" != '1' ]]; then
334
+ benchmark_run_with_spinner 'Upgrading pip' python3 -m pip install --quiet --upgrade pip
335
+ install_requirements
336
+ download_selected_assets
337
+ benchmark_log success 'Benchmark assets are ready'
338
+ else
339
+ benchmark_log info 'Skipping benchmark asset preparation'
340
+ fi
341
+
342
+ for benchmark_index in "${!BENCHMARK_SELECTED_IDS[@]}"; do
343
+ benchmark_id="${BENCHMARK_SELECTED_IDS[benchmark_index]}"
99
344
  run_benchmark "${benchmark_id}"
100
345
 
101
- if (( benchmark_index < ${#BENCHMARKS[@]} - 1 )); then
346
+ if (( benchmark_index < ${#BENCHMARK_SELECTED_IDS[@]} - 1 )); then
102
347
  log "Waiting ${INTER_BENCHMARK_DELAY_SECONDS}s before starting the next benchmark"
103
348
  sleep "${INTER_BENCHMARK_DELAY_SECONDS}"
104
349
  fi
@@ -107,4 +352,4 @@ done
107
352
  log "Waiting ${FINALIZATION_DELAY_SECONDS}s for CSV download finalization"
108
353
  sleep "${FINALIZATION_DELAY_SECONDS}"
109
354
 
110
- log 'Benchmark run complete'
355
+ benchmark_log success 'Benchmark run complete'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luxonis/depthai-viewer-common",
3
- "version": "2.5.1",
3
+ "version": "2.5.3",
4
4
  "description": "Common utilities and components for building a frontend application for DepthAI projects",
5
5
  "license": "ISC",
6
6
  "author": "Luxonis Holding Corporation",
@@ -21,8 +21,8 @@
21
21
  "build:clean:win": "if exist ..\\..\\node_modules\\.tmp\\tsconfig-common.tsbuildinfo del /Q ..\\..\\node_modules\\.tmp\\tsconfig-common.tsbuildinfo & if exist dist rmdir /S /Q dist & npm run build:win",
22
22
  "check-deps": "npm run deps:check -w @luxonis/depthai-web-viewer",
23
23
  "prepublishOnly": "npm run check-deps && npm run build:clean",
24
- "benchmark": "./benchmark-download.sh && ./benchmark.sh",
25
- "benchmark:download": "./benchmark-download.sh"
24
+ "benchmark:raw": "./benchmark.sh run",
25
+ "benchmark:download:raw": "./benchmark.sh download"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public"