kezhenxu94 commented on a change in pull request #4416: Provide profile 
exporter tool
URL: https://github.com/apache/skywalking/pull/4416#discussion_r384370058
 
 

 ##########
 File path: tools/profile/profile_exporter.sh
 ##########
 @@ -0,0 +1,107 @@
+#!/usr/bin/env bash
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# This script relies on few environment variables to determine source code 
package
+# behavior, those variables are:
+#   RELEASE_VERSION -- The version of this source package.
+# For example: RELEASE_VERSION=5.0.0-alpha
+
+bin_path=$0
+exporter_dir=$(cd $(dirname $0); pwd)
+
+while [[ $# -gt 0 ]]; do
+  case "$1" in
+    --taskid=*)
+      task_id=${1#*=}
+      ;;
+    --traceid=*)
+      trace_id=${1#*=}
+      ;;
+    *)
+      dist=$1
+  esac
+  shift
+done
+
+echo "${task_id}, ${trace_id}, ${dist}, ${workdir}, ${bin_path}"
+
+[[ ! ${task_id} || ! ${trace_id} || ! ${dist} ]] \
+  && echo 'Usage: sh tools/profile_exporter.sh [--taskid] [--traceid] 
export_path' \
+  && exit 1
+
+[[ ! -d ${dist} ]] \
+  && echo "Cannot found export dist path: ${dist}" \
+  && exit 1
+
+# prepare paths
+config_file="${exporter_dir}/../../config/application.yml"
+oap_libs_dir="${exporter_dir}/../../oap-libs"
+exporter_log_file="${exporter_dir}/profile_exporter_log4j2.xml"
+awk_change_file="${exporter_dir}/persist_core_and_storage.awk"
+[[ ! -f ${config_file} ]] \
+  && echo "Cannot found oap application.yml" \
+  && exit 1
+[[ ! -d ${oap_libs_dir} ]] \
+  && echo "Cannot found oap libs path" \
+  && exit 1
+
+# create current trace tempory path
+work_dir="${dist}/${trace_id}"
+mkdir -p ${work_dir}
+
+# prepare exporter files
+mkdir -p "${work_dir}/config"
+mkdir -p "${work_dir}/work"
+cp ${exporter_log_file} ${work_dir}/config/log4j2.xml
+# only persist core and storage module in application.yml config
+awk -f ${awk_change_file} ${config_file} > ${work_dir}/config/application.yml
+
+# start export
+echo "Exporting task: ${task_id}, trace: ${trace_id}, dist: ${work_dir}"
+JAVA_OPTS=" -Xms256M -Xmx512M"
+_RUNJAVA=${JAVA_HOME}/bin/java
+[ -z "$JAVA_HOME" ] && _RUNJAVA=java
+
+CLASSPATH="${work_dir}/config:$CLASSPATH"
+for i in "${oap_libs_dir}"/*.jar
+do
+    CLASSPATH="$i:$CLASSPATH"
+done
+
+exec $_RUNJAVA ${JAVA_OPTS} -classpath $CLASSPATH 
org.apache.skywalking.oap.server.tool.profile.exporter.ProfileSnapshotExporter \
+  ${task_id} ${trace_id} ${work_dir}/work &
+wait
+
+if [ `ls -l ${work_dir}/work | wc -l` -lt 2 ]; then
+       echo "Export failure!"
+       exit 1
+fi
+
+# compress files(only compress work data, no config)
+echo "Compressing exported directory: ${work_dir}"
+CURRENT_DIR="$(cd "$(dirname $0)"; pwd)"
 
 Review comment:
   `CURRENT_DIR` should be simply `$(pwd)`, you want to go back where the user 
run the command, not where the script locates, right?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to