Skip to content

Commit 8a228eb

Browse files
committed
Add script to record process metrics
1 parent 0bed566 commit 8a228eb

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tools/ci/circle/process_metrics

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bash
2+
#
3+
# @license Apache-2.0
4+
#
5+
# Copyright (c) 2018 The Stdlib Authors.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
# Build script to log metrics in order to monitor process resource usage over time.
20+
21+
# VARIABLES #
22+
23+
# Define an output file to store metrics:
24+
log_file="${CIRCLE_ARTIFACTS}/process_metrics.txt"
25+
26+
# Define an interval for logging metrics:
27+
interval='1s'
28+
29+
30+
# FUNCTIONS #
31+
32+
# Defines an error handler.
33+
on_error() {
34+
echo 'ERROR: An error was encountered during execution.' >&2
35+
exit 1
36+
}
37+
38+
# Polls the system for process metrics.
39+
#
40+
# $1 - poll interval
41+
# $2 - output log file
42+
poll() {
43+
while true; do
44+
ps -u ubuntu -eo pid,%cpu,%mem,rss,args,uname -w -w --sort=-%mem >> "$2";
45+
echo '----------' >> "$2";
46+
sleep "$1";
47+
done
48+
}
49+
50+
# Main execution sequence.
51+
main() {
52+
poll "${interval}" "${log_file}"
53+
}
54+
55+
# Set an error handler:
56+
trap 'on_error' ERR
57+
58+
# Run main:
59+
main

0 commit comments

Comments
 (0)