Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/measure ram cpu #1

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,21 @@ install(TARGETS ${PROJECT_NAME}
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
COMPONENT sdl_atf)

install(DIRECTORY "${CMAKE_SOURCE_DIR}/remote_atf_docker"
"${CMAKE_SOURCE_DIR}/data"
DESTINATION "${CMAKE_INSTALL_PREFIX}"
USE_SOURCE_PERMISSIONS
COMPONENT sdl_atf)

install(DIRECTORY "${CMAKE_SOURCE_DIR}/modules"
"${CMAKE_SOURCE_DIR}/data"
DESTINATION "${CMAKE_INSTALL_PREFIX}"
FILE_PERMISSIONS OWNER_WRITE OWNER_READ
USE_SOURCE_PERMISSIONS
COMPONENT sdl_atf)

install(DIRECTORY "${CMAKE_SOURCE_DIR}/tools"
DESTINATION "${CMAKE_INSTALL_PREFIX}"
FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
USE_SOURCE_PERMISSIONS
COMPONENT sdl_atf)

install(FILES "${CMAKE_SOURCE_DIR}/start.sh"
Expand Down
29 changes: 29 additions & 0 deletions remote_atf_docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM ubuntu:18.04

ENV TZ=Europe/Minsk
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN apt-get update && apt-get -q -y install locales sudo

RUN apt-get update && apt-get -q -y install libssl1.0.0 libusb-1.0-0 libbluetooth3 \
libssl-doc- libusb-1.0-doc- manpages- manpages-dev-

RUN apt-get update && apt-get -q -y install openssl liblua5.2-0 psmisc \
autotools-dev- binutils- build-essential- bzip2- cpp- cpp-5- dpkg-dev- fakeroot- \
manpages- manpages-dev-

RUN apt-get update && apt-get -q -y install sqlite3 libqt5websockets5 net-tools iproute2 \
qttranslations5-l10n- xdg-user-dirs- xml-core- dbus-

RUN apt-get update && apt install -y netcat cpipe gnuplot sysstat python3-pip docker.io
RUN apt-get update && apt install -y python3-numpy python3-scipy python3-matplotlib

RUN locale-gen en_US.UTF-8 && update-locale LANG=en_US.UTF-8

ENV LC_ALL en_US.UTF-8

RUN chmod u+s /sbin/ifconfig /sbin/ip && mkdir /home/developer

COPY entrypoint.sh /usr/bin/

ENTRYPOINT ["/bin/bash", "-e", "/usr/bin/entrypoint.sh"]
1 change: 1 addition & 0 deletions remote_atf_docker/build_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker build . -t remote_atf_server

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LuxoftAKutsan I would propose to add next line to script

#!/bin/bash

37 changes: 37 additions & 0 deletions remote_atf_docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# Add local user
# Either use the LOCAL_USER_ID if passed in at runtime or
# fallback

USER_ID=${LOCAL_USER_ID:-9001}

useradd --shell /bin/bash -u $USER_ID -o -c "" developer
usermod -aG docker developer
sudo chmod 666 /var/run/docker.sock
echo "developer ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

chown developer /home/developer
chgrp developer /home/developer

export HOME=/home/developer
export LANG=en_US.UTF-8

echo "Remote adapter server available by following ip adresses : "
ip addr | grep -E "inet " | tr -s " " | cut -d ' ' -f 3| cut -d '/' -f 1

echo " ls /home/developer "
ls /home/developer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LuxoftAKutsan What is purpose to display this list of files on start?


echo "SDL bin dir : /home/developer/sdlbin"; ls -la /home/developer/sdlbin
echo "ATF bin dir : /home/developer/atfbin"; ls -la /home/developer/atfbin
echo "Third party /home/developer/thirdparty"; ls -la /home/developer/thirdparty

cd /home/developer/atfbin/RemoteTestingAdapterServer

echo "Third party contents"
LIB="/home/developer/thirdparty/lib/"
LIB64="/home/developer/thirdparty/x86_64/lib/"

sudo LD_LIBRARY_PATH="$LIB:$LIB64:." -u developer "./RemoteTestingAdapterServer"

37 changes: 37 additions & 0 deletions remote_atf_docker/start_remote_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
PATH_TO_SDLBIN=$1
PATH_TO_ATFBIN=$2
PATH_TO_THIRDPARTY=$3

if [ -z "$PATH_TO_SDLBIN" ]; then
echo "Path to SDL binaries is not defined as 1st argument"
exit 1;
fi

if [ -z "$PATH_TO_ATFBIN" ]; then
echo "Path to ATF binaries is not defined as 2nd argument"
exit 1;
fi

if [ -z "$PATH_TO_THIRDPARTY" ]; then
echo "Path to 3rd party libraries is not defined as 3rd argument"
exit 1;
fi

CONTAINER_NAME=remote_sdl
IMAGE_NAME=remote_atf_server
MEMORY_CONSTRAINS=4G
CPUS=2
docker rm $CONTAINER_NAME

echo $1 $2 $3

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LuxoftAKutsan I would propose to add some description to these variables or do not display them at all.

docker run -e LOCAL_USER_ID=$UID \
-e CONTAINER_NAME=$CONTAINER_NAME\
-e LOCAL_USER_ID=$(id -u)\
--net=host\
--name=$CONTAINER_NAME\
-v /var/run/docker.sock:/var/run/docker.sock\
-v $PATH_TO_SDLBIN:/home/developer/sdlbin\
-v $PATH_TO_ATFBIN:/home/developer/atfbin\
-v $PATH_TO_THIRDPARTY:/home/developer/thirdparty\
-m=$MEMORY_CONSTRAINS\
-it $IMAGE_NAME
6 changes: 3 additions & 3 deletions src/remote_adapter/remote_adapter_server/BOOST.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if(QNXNTO)
set(CMAKE_FIND_ROOT_PATH "${CMAKE_FIND_ROOT_PATH}" "${BOOST_ROOT}")
endif()

find_package(Boost 1.68.0 COMPONENTS system filesystem)
find_package(Boost 1.68.0 COMPONENTS filesystem system)

if (NOT ${Boost_FOUND})
message(STATUS "Did not find boost. Downloading and installing boost 1.68")
Expand Down Expand Up @@ -70,8 +70,8 @@ if (NOT ${Boost_FOUND})
endif()

set(BOOST_LIBRARIES
"${BOOST_LIBRARY_DIRS}/libboost_system.a"
"${BOOST_LIBRARY_DIRS}/libboost_filesystem.a")
"${BOOST_LIBRARY_DIRS}/libboost_filesystem.a"
"${BOOST_LIBRARY_DIRS}/libboost_system.a")

include_directories("${BOOST_INCLUDE_DIRS}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>

#include "../../common/constants.h"
#include "../../common/custom_types.h"
Expand Down Expand Up @@ -394,11 +395,11 @@ void UtilsManager::Bind(rpc::server &server) {
LOG_ERROR("{0}: {1}", __func__, error_msg::kBadTypeValue);
return response_type(error_msg::kBadTypeValue, error_codes::FAILED);
}
auto receive_result = UtilsManager::ExecuteCommand(bash_command);

return receive_result;
return ('&' == bash_command.back()) ? UtilsManager::ExecuteCommandBg(bash_command):
UtilsManager::ExecuteCommand(bash_command);
});
}

std::string UtilsManager::PluginName() { return "RemoteUtilsManager"; }
int UtilsManager::StartApp(const std::string &app_path,
const std::string &app_name) {
Expand Down Expand Up @@ -685,6 +686,13 @@ UtilsManager::ExecuteCommand(const std::string &bash_command) {
return std::make_pair(command_output, term_status);
}

std::pair<std::string, int>
UtilsManager::ExecuteCommandBg(const std::string &bash_command) {
LOG_INFO("{0}: {1}", __func__, bash_command);
system(bash_command.c_str());
return std::make_pair("Background process", error_codes::SUCCESS);
}

std::vector<int> UtilsManager::GetAppPids(const std::string &app_name) {

struct dirent *dirent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ class UtilsManager : public remote_adapter::UtilsPlugin {
static std::pair<std::string, int>
ExecuteCommand(const std::string &bash_command);

static
std::pair<std::string, int>
ExecuteCommandBg(const std::string &bash_command);


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LuxoftAKutsan Please remove the redundant empty line.

private:
static std::vector<int> GetAppPids(const std::string &app_name);
static std::string GetAppStatus(int pid, int *num_threads = 0);
Expand Down
63 changes: 63 additions & 0 deletions tools/measure_sdl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash

# apt-get install sysstat linux-tools-common

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LuxoftAKutsan Could this commented instruction be removed from the script?


SDL_PID=$(pidof smartDeviceLinkCore)
REMOTE=false
OUTPUT_DIR="measure"/$1
OUTPUT_PIDSTAT_FILE=$OUTPUT_DIR/pidstat.log
OUTPUT_PS_FILE=$OUTPUT_DIR/ps.log
OUTPUT_DOCKER_FILE=$OUTPUT_DIR/docker.log
CONTAINTER_NAME=$(docker inspect --format='{{.Name}}' $HOSTNAME | cut -c2-)

STEP=1

if [ -n $2 ] && [ "$2" = "--remote" ]; then REMOTE=true; fi

rm -rf $OUTPUT_DIR
mkdir -p $OUTPUT_DIR
pwd
echo $OUTPUT_DIR
function ps_formated() {
ps --no-headers --format "start %cpu cp cputime %mem sz thcount " -p $SDL_PID
}

function measure_ps() {
PS_OUTPUT=$(ps_formated)
TIME=$(date +'%T:%N')
echo $TIME $PS_OUTPUT >> $OUTPUT_PS_FILE
}

function measure_pid_stat() {
export S_TIME_FORMAT=ISO
STAT_OUTPUT=$(pidstat -urdlv -h -p $SDL_PID | grep $SDL_PID)
echo $STAT_OUTPUT >> $OUTPUT_PIDSTAT_FILE
}

function measure_docker() {
RECORD=$(docker stats --format "{{.Name}} {{.CPUPerc}} {{.MemUsage}} {{.PIDs}}" --no-stream | grep $CONTAINTER_NAME)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LuxoftAKutsan This line too long and contains redundant whitespaces. Could it be fixed?

echo $RECORD
TIME=$(date +'%T:%N')
echo $TIME $RECORD >> $OUTPUT_DOCKER_FILE
}

echo "Wait for SDL start"
until SDL_PID=$(pidof smartDeviceLinkCore)
do
sleep $STEP
printf "."
done

while SDL_PID=$(pidof smartDeviceLinkCore)
do
measure_pid_stat
measure_ps
if [ $REMOTE = true ]; then measure_docker; fi
sleep $STEP
done

PARAMS="--pidstat_file=$OUTPUT_PIDSTAT_FILE --ps_file=$OUTPUT_PS_FILE --output_dir=$OUTPUT_DIR --title=$1"
if [ $REMOTE = true ]; then PARAMS="$PARAMS --docker_file=$OUTPUT_DOCKER_FILE"; fi

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
python3 $DIR/sdl_graphs.py $PARAMS
Loading