1ffe3c632Sopenharmony_ci#!/bin/bash
2ffe3c632Sopenharmony_ci#
3ffe3c632Sopenharmony_ci# Change to repo root
4ffe3c632Sopenharmony_cicd $(dirname $0)/../../..
5ffe3c632Sopenharmony_ci
6ffe3c632Sopenharmony_ciexport OUTPUT_DIR=testoutput
7ffe3c632Sopenharmony_cioldpwd=`pwd`
8ffe3c632Sopenharmony_ci
9ffe3c632Sopenharmony_ci# tcmalloc
10ffe3c632Sopenharmony_ciif [ ! -f gperftools/.libs/libtcmalloc.so ]; then
11ffe3c632Sopenharmony_ci  git clone https://github.com/gperftools/gperftools.git
12ffe3c632Sopenharmony_ci  cd gperftools
13ffe3c632Sopenharmony_ci  ./autogen.sh
14ffe3c632Sopenharmony_ci  ./configure
15ffe3c632Sopenharmony_ci  make -j8
16ffe3c632Sopenharmony_ci  cd ..
17ffe3c632Sopenharmony_cifi
18ffe3c632Sopenharmony_ci
19ffe3c632Sopenharmony_ci# download datasets for benchmark
20ffe3c632Sopenharmony_cicd benchmarks
21ffe3c632Sopenharmony_ci./download_data.sh
22ffe3c632Sopenharmony_cidatasets=$(for file in $(find . -type f -name "dataset.*.pb" -not -path "./tmp/*"); do echo "$(pwd)/$file"; done | xargs)
23ffe3c632Sopenharmony_ciecho $datasets
24ffe3c632Sopenharmony_cicd $oldpwd
25ffe3c632Sopenharmony_ci
26ffe3c632Sopenharmony_ci# build Python protobuf
27ffe3c632Sopenharmony_ci./autogen.sh
28ffe3c632Sopenharmony_ci./configure CXXFLAGS="-fPIC -O2"
29ffe3c632Sopenharmony_cimake -j8
30ffe3c632Sopenharmony_cicd python
31ffe3c632Sopenharmony_cipython setup.py build --cpp_implementation
32ffe3c632Sopenharmony_cipip install . --user
33ffe3c632Sopenharmony_ci
34ffe3c632Sopenharmony_ci
35ffe3c632Sopenharmony_ci# build and run Python benchmark
36ffe3c632Sopenharmony_cicd ../benchmarks
37ffe3c632Sopenharmony_cimake python-pure-python-benchmark
38ffe3c632Sopenharmony_cimake python-cpp-reflection-benchmark
39ffe3c632Sopenharmony_cimake -j8 python-cpp-generated-code-benchmark
40ffe3c632Sopenharmony_ciecho "[" > tmp/python_result.json
41ffe3c632Sopenharmony_ciecho "benchmarking pure python..."
42ffe3c632Sopenharmony_ci./python-pure-python-benchmark --json --behavior_prefix="pure-python-benchmark" $datasets  >> tmp/python_result.json
43ffe3c632Sopenharmony_ciecho "," >> "tmp/python_result.json"
44ffe3c632Sopenharmony_ciecho "benchmarking python cpp reflection..."
45ffe3c632Sopenharmony_cienv LD_PRELOAD="$oldpwd/gperftools/.libs/libtcmalloc.so" LD_LIBRARY_PATH="$oldpwd/src/.libs" ./python-cpp-reflection-benchmark --json --behavior_prefix="cpp-reflection-benchmark" $datasets  >> tmp/python_result.json
46ffe3c632Sopenharmony_ciecho "," >> "tmp/python_result.json"
47ffe3c632Sopenharmony_ciecho "benchmarking python cpp generated code..."
48ffe3c632Sopenharmony_cienv LD_PRELOAD="$oldpwd/gperftools/.libs/libtcmalloc.so" LD_LIBRARY_PATH="$oldpwd/src/.libs" ./python-cpp-generated-code-benchmark --json --behavior_prefix="cpp-generated-code-benchmark" $datasets >> tmp/python_result.json
49ffe3c632Sopenharmony_ciecho "]" >> "tmp/python_result.json"
50ffe3c632Sopenharmony_cicd $oldpwd
51ffe3c632Sopenharmony_ci
52ffe3c632Sopenharmony_ci# build CPP protobuf
53ffe3c632Sopenharmony_ci./configure
54ffe3c632Sopenharmony_cimake clean && make -j8
55ffe3c632Sopenharmony_ci
56ffe3c632Sopenharmony_ci# build Java protobuf
57ffe3c632Sopenharmony_cicd java
58ffe3c632Sopenharmony_cimvn package
59ffe3c632Sopenharmony_cicd ..
60ffe3c632Sopenharmony_ci
61ffe3c632Sopenharmony_ci# build CPP benchmark
62ffe3c632Sopenharmony_cicd benchmarks
63ffe3c632Sopenharmony_cimv tmp/python_result.json . && make clean && make -j8 cpp-benchmark && mv python_result.json tmp
64ffe3c632Sopenharmony_ciecho "benchmarking cpp..."
65ffe3c632Sopenharmony_cienv LD_PRELOAD="$oldpwd/gperftools/.libs/libtcmalloc.so" ./cpp-benchmark --benchmark_min_time=5.0 --benchmark_out_format=json --benchmark_out="tmp/cpp_result.json" $datasets
66ffe3c632Sopenharmony_cicd $oldpwd
67ffe3c632Sopenharmony_ci
68ffe3c632Sopenharmony_ci# build go protobuf
69ffe3c632Sopenharmony_ciexport PATH="`pwd`/src:$PATH"
70ffe3c632Sopenharmony_ciexport GOPATH="$HOME/gocode"
71ffe3c632Sopenharmony_cimkdir -p "$GOPATH/src/github.com/google"
72ffe3c632Sopenharmony_cirm -f "$GOPATH/src/github.com/protocolbuffers/protobuf"
73ffe3c632Sopenharmony_ciln -s "`pwd`" "$GOPATH/src/github.com/protocolbuffers/protobuf"
74ffe3c632Sopenharmony_ciexport PATH="$GOPATH/bin:$PATH"
75ffe3c632Sopenharmony_cigo get github.com/golang/protobuf/protoc-gen-go
76ffe3c632Sopenharmony_ci
77ffe3c632Sopenharmony_ci# build go benchmark
78ffe3c632Sopenharmony_cicd benchmarks
79ffe3c632Sopenharmony_cimake go-benchmark
80ffe3c632Sopenharmony_ciecho "benchmarking go..."
81ffe3c632Sopenharmony_ci./go-benchmark $datasets > tmp/go_result.txt
82ffe3c632Sopenharmony_ci
83ffe3c632Sopenharmony_ci# build java benchmark
84ffe3c632Sopenharmony_cimake java-benchmark
85ffe3c632Sopenharmony_ciecho "benchmarking java..."
86ffe3c632Sopenharmony_ci./java-benchmark -Cresults.file.options.file="tmp/java_result.json" $datasets
87ffe3c632Sopenharmony_ci
88ffe3c632Sopenharmony_cimake js-benchmark
89ffe3c632Sopenharmony_ciecho "benchmarking js..."
90ffe3c632Sopenharmony_ci./js-benchmark $datasets  --json_output=$(pwd)/tmp/node_result.json
91ffe3c632Sopenharmony_ci
92ffe3c632Sopenharmony_cimake -j8 generate_proto3_data
93ffe3c632Sopenharmony_ciproto3_datasets=$(for file in $datasets; do echo $(pwd)/tmp/proto3_data/${file#$(pwd)}; done | xargs)
94ffe3c632Sopenharmony_ciecho $proto3_datasets
95ffe3c632Sopenharmony_ci
96ffe3c632Sopenharmony_ci# build php benchmark
97ffe3c632Sopenharmony_cimake -j8 php-c-benchmark
98ffe3c632Sopenharmony_ciecho "benchmarking php_c..."
99ffe3c632Sopenharmony_ci./php-c-benchmark $proto3_datasets --json --behavior_prefix="php_c" > tmp/php_c_result.json
100ffe3c632Sopenharmony_ci
101ffe3c632Sopenharmony_ci# upload result to bq
102ffe3c632Sopenharmony_cimake python_add_init
103ffe3c632Sopenharmony_cienv LD_LIBRARY_PATH="$oldpwd/src/.libs" python -m util.result_uploader -php_c="../tmp/php_c_result.json"  \
104ffe3c632Sopenharmony_ci	-cpp="../tmp/cpp_result.json" -java="../tmp/java_result.json" -go="../tmp/go_result.txt" -python="../tmp/python_result.json" -node="../tmp/node_result.json"
105ffe3c632Sopenharmony_cicd $oldpwd
106