Skip to content

Commit

Permalink
Added log for shared memory (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-stefanovic authored Apr 12, 2022
1 parent 92ea5f8 commit 59106a4
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 2 deletions.
52 changes: 52 additions & 0 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,58 @@ blocks:
commands:
- make check.static

- name: SHM Test Bionic
dependencies:
- 'Build local CLIs'
task:
prologue:
commands:
- checkout
- artifact pull workflow bin/linux/cache -d cache-cli/bin/linux/cache
- artifact pull workflow bin/darwin/cache -d cache-cli/bin/darwin/cache
- bash release/create.sh
- source release/install_in_tests.sh
- git submodule init && git submodule update
- sudo ./tests/support/bats-core/install.sh /usr/local

jobs:
- name: SHM Test Bionic
commands:
- sed -i "s/\/tmp\/system-metrics/\/tmp\/system-metrics2/g" ~/.toolbox/system-metrics-collector
- . ~/.toolbox/system-metrics-collector &
- sleep 2
- bats tests/shm/shm_ubuntu.bats
- cat /tmp/system-metrics2

- name: SHM Test Docker
dependencies:
- 'Build local CLIs'
task:
agent:
machine:
type: e1-standard-2
containers:
- name: main
image: 'registry.semaphoreci.com/ubuntu:18.04'
prologue:
commands:
- checkout
- artifact pull workflow bin/linux/cache -d cache-cli/bin/linux/cache
- artifact pull workflow bin/darwin/cache -d cache-cli/bin/darwin/cache
- bash release/create.sh
- source release/install_in_tests.sh
- git submodule init && git submodule update
- sudo ./tests/support/bats-core/install.sh /usr/local

jobs:
- name: SHM Test Docker
commands:
- sed -i "s/\/tmp\/system-metrics/\/tmp\/system-metrics2/g" ~/.toolbox/system-metrics-collector
- . ~/.toolbox/system-metrics-collector &
- sleep 2
- bats tests/shm/shm_docker.bats
- cat /tmp/system-metrics2

after_pipeline:
task:
jobs:
Expand Down
4 changes: 2 additions & 2 deletions system-metrics-collector
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ OUTPUT="/tmp/system-metrics"

while true; do
MEMORY=$(free | grep Mem | awk '{ printf("%6.2f%%\n", ($3/$2 * 100.0)) }')
SHARED_MEMORY=$(free -m | grep Mem | awk '{ print $5 }')
SYSTEM_DISK=$(df "$SYSTEM_DISK_LOCATION" | sed 1d | awk '{ printf("%6.2f%%\n", ($3/$2 * 100.0)) }')
DOCKER_DISK=$(df "$DOCKER_DISK_LOCATION" | sed 1d | awk '{ printf("%6.2f%%\n", ($3/$2 * 100.0)) }')
echo "$(date) | mem: $MEMORY, system_disk: $SYSTEM_DISK, docker_disk: $DOCKER_DISK" >> $OUTPUT

echo "$(date) | mem:$MEMORY, system_disk:$SYSTEM_DISK, docker_disk:$DOCKER_DISK, shared_memory: $SHARED_MEMORY M" >> $OUTPUT
sleep 1
done
Binary file added tests/shm/shm_1024mb
Binary file not shown.
Binary file added tests/shm/shm_512mb
Binary file not shown.
20 changes: 20 additions & 0 deletions tests/shm/shm_docker.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bats

load "../support/bats-support/load"
load "../support/bats-assert/load"

@test "shm: write 512MB to shared memory" {
run ~/toolbox/tests/shm/shm_512mb
assert_line --partial "Writing Process: Shared Memory Write: Wrote 536870911 bytes"
assert_line --partial "Writing Process: Complete"
[ $(cat /tmp/system-metrics2 | awk -F "," '{print $4}' | grep -o '[0-9]\+' | sort -n | tail -n 1) -ge 510 ]
run sleep 2
}

@test "shm: write 1024MB to shared memory" {
run ~/toolbox/tests/shm/shm_1024mb
assert_line --partial "Writing Process: Shared Memory Write: Wrote 1073741823 bytes"
assert_line --partial "Writing Process: Complete"
[ $(cat /tmp/system-metrics2 | awk -F "," '{print $4}' | grep -o '[0-9]\+' | sort -n | tail -n 1) -ge 1020 ]
run sleep 2
}
20 changes: 20 additions & 0 deletions tests/shm/shm_ubuntu.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bats

load "../support/bats-support/load"
load "../support/bats-assert/load"

@test "shm: write 512MB to shared memory" {
run ~/toolbox/tests/shm/shm_512mb
assert_line --partial "Writing Process: Shared Memory Write: Wrote 536870911 bytes"
assert_line --partial "Writing Process: Complete"
[ $(cat /tmp/system-metrics2 | awk -F "," '{print $4}' | grep -o '[0-9]\+' | sort -n | tail -n 1) -ge 510 ]
run sleep 2
}

@test "shm: write 1024MB to shared memory" {
run ~/toolbox/tests/shm/shm_1024mb
assert_line --partial "Writing Process: Shared Memory Write: Wrote 1073741823 bytes"
assert_line --partial "Writing Process: Complete"
[ $(cat /tmp/system-metrics2 | awk -F "," '{print $4}' | grep -o '[0-9]\+' | sort -n | tail -n 1) -ge 1020 ]
run sleep 2
}

0 comments on commit 59106a4

Please sign in to comment.