Skip to content

Commit 4ac8a2e

Browse files
authored
Merge pull request #1521 from tbkka/tbkka-performance-harness
Get the performance harness running again...
2 parents 0f3e371 + c5d7d2c commit 4ac8a2e

File tree

7 files changed

+114
-50
lines changed

7 files changed

+114
-50
lines changed

Performance/Harness.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class Harness {
9494
* from the main results.
9595
*/
9696
template <typename Function>
97-
typename std::result_of<Function()>::type measure_subtask(
97+
typename std::invoke_result<Function>::type measure_subtask(
9898
const std::string& name, Function&& func);
9999

100100
/**
@@ -171,7 +171,7 @@ void Harness::measure(const Function& func) {
171171
}
172172

173173
template <typename Function>
174-
typename std::result_of<Function()>::type Harness::measure_subtask(
174+
typename std::invoke_result<Function>::type Harness::measure_subtask(
175175
const std::string& name, Function&& func) {
176176
subtask_names.push_back(name);
177177
using std::chrono::steady_clock;

Performance/Harness.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class Harness: GeneratedHarnessMembers {
106106

107107
for name in taskNames {
108108
let time = currentSubtasks[name] ?? 0
109-
print(String(format: "%9.3f", name, time), terminator: "")
109+
print(String(format: "%9.3f", time), terminator: "")
110110
subtaskTimings[name] = (subtaskTimings[name] ?? []) + [time]
111111
}
112112
print()

Performance/generators/cpp.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ using google::protobuf::util::BinaryToJsonString;
9898
using google::protobuf::util::JsonToBinaryString;
9999
using google::protobuf::util::MessageDifferencer;
100100
using google::protobuf::util::NewTypeResolverForDescriptorPool;
101-
using google::protobuf::util::Status;
102101
using google::protobuf::util::TypeResolver;
103102
using std::cerr;
104103
using std::endl;
@@ -148,12 +147,14 @@ void Harness::run() {
148147
// Exercise JSON serialization.
149148
auto json = measure_subtask("Encode JSON", [&]() {
150149
string out_json;
151-
BinaryToJsonString(type_resolver, *type_url, data, &out_json);
150+
auto r = BinaryToJsonString(type_resolver, *type_url, data, &out_json);
151+
(void)r; // UNUSED
152152
return out_json;
153153
});
154154
auto decoded_binary = measure_subtask("Decode JSON", [&]() {
155155
string out_binary;
156-
JsonToBinaryString(type_resolver, *type_url, json, &out_binary);
156+
auto r = JsonToBinaryString(type_resolver, *type_url, json, &out_binary);
157+
(void)r; // UNUSED
157158
return out_binary;
158159
});
159160

Performance/generators/swift.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,20 @@ extension Harness {
106106
populateFields(of: &message)
107107
}
108108
109-
message = measureSubtask("Populate fields with with") {
109+
message = measureSubtask("Populate (with)") {
110110
return populateFieldsWithWith()
111111
}
112112
113113
// Exercise binary serialization.
114-
let data = try measureSubtask("Encode binary") {
115-
return try message.serializedBytes()
114+
let data = try measureSubtask("Encode binary") { () -> Data in
115+
try message.serializedBytes()
116116
}
117117
let message2 = try measureSubtask("Decode binary") {
118118
return try PerfMessage(serializedData: data)
119119
}
120120
121121
// Exercise JSON serialization.
122-
let json = try measureSubtask("Encode JSON") {
122+
let json = try measureSubtask("Encode JSON") { () -> Data in
123123
return try message.jsonUTF8Bytes()
124124
}
125125
_ = try measureSubtask("Decode JSON") {

Performance/perf_runner.sh

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ else
4141
fi
4242

4343
# Directory containing this script
44-
readonly script_dir="."
44+
readonly script_dir=`pwd`
4545

4646
# Change this if your checkout of github.com/protocolbuffers/protobuf is in a
4747
# different location.
4848
readonly GOOGLE_PROTOBUF_CHECKOUT=${GOOGLE_PROTOBUF_CHECKOUT:-"$script_dir/../../protobuf"}
49-
readonly PROTOC=${PROTOC:-"${GOOGLE_PROTOBUF_CHECKOUT}/src/protoc"}
49+
readonly PROTOC=${PROTOC:-"${GOOGLE_PROTOBUF_CHECKOUT}/protoc"}
5050

5151
function usage() {
5252
cat >&2 <<EOF
@@ -123,7 +123,7 @@ EOF
123123

124124
echo "Running $language test harness alone..."
125125
sleep 3
126-
DYLD_LIBRARY_PATH="$script_dir/_generated" "$harness" "$partial_results"
126+
DYLD_LIBRARY_PATH=`dirname $harness` "$harness" "$partial_results"
127127
sleep 3
128128

129129
cp "$harness" "${harness}_stripped"
@@ -151,8 +151,10 @@ function profile_harness() {
151151
perf_dir="$3"
152152

153153
echo "Running $description test harness in Instruments..."
154-
instruments -t "$script_dir/Protobuf" -D "$results_trace" \
155-
"$harness" -e DYLD_LIBRARY_PATH "$perf_dir/_generated"
154+
mkdir -p "$results_trace"
155+
xctrace record --template 'Time Profiler' --output "$results_trace" \
156+
--env DYLD_LIBRARY_PATH="$perf_dir/_generated" \
157+
--launch -- "$harness"
156158
}
157159

158160
# Inserts the partial visualization results from all the languages tested into
@@ -236,10 +238,14 @@ fi
236238
# Set up a hook to cleanup revision comparison checkouts when the script
237239
# completes.
238240
declare -a CLEANUP_WHEN_DONE
241+
GIT_WORKTREE=""
239242
function cleanup_revision_checkouts() {
240243
if [[ "${#CLEANUP_WHEN_DONE[@]}" -ne 0 ]]; then
241244
rm -rf "${CLEANUP_WHEN_DONE[@]}"
242245
fi
246+
if [ "$GIT_WORKTREE" != "" ]; then
247+
git worktree remove "$GIT_WORKTREE"
248+
fi
243249
}
244250
trap cleanup_revision_checkouts EXIT HUP INT QUIT TERM
245251

@@ -297,7 +303,9 @@ for comparison in "${comparisons[@]}"; do
297303
echo "==== Building/running C++ harness ===================="
298304
echo
299305

300-
${PROTOC} --cpp_out="$script_dir" "$gen_message_path"
306+
${PROTOC} --cpp_out="$script_dir/_generated" \
307+
--proto_path=`dirname $gen_message_path` \
308+
"$gen_message_path"
301309

302310
harness_cpp="$script_dir/_generated/harness_cpp"
303311
run_cpp_harness "$harness_cpp"
@@ -314,19 +322,20 @@ for comparison in "${comparisons[@]}"; do
314322

315323
# Check out the commit to a temporary directory and create its _generated
316324
# directory. (Results will still go in the working tree.)
317-
tmp_checkout="$(mktemp -d -t swiftprotoperf)"
318-
CLEANUP_WHEN_DONE+=("$tmp_checkout")
319-
git --work-tree="$tmp_checkout" checkout "$comparison" -- .
320-
mkdir "$tmp_checkout/Performance/_generated"
321-
322-
build_swift_packages "$tmp_checkout" "ForRev"
323-
${PROTOC} --plugin="$tmp_checkout/.build/release/protoc-gen-swiftForRev" \
324-
--swiftForRev_out=FileNaming=DropPath:"$tmp_checkout/Performance/_generated" \
325-
"$gen_message_path"
326-
327-
harness_swift="$tmp_checkout/Performance/_generated/harness_swift"
325+
GIT_WORKTREE="$(mktemp -d `pwd`/_generated/swiftprotoperf.XXXXXX)"
326+
CLEANUP_WHEN_DONE+=("$GIT_WORKTREE")
327+
git worktree add "$GIT_WORKTREE" "$comparison"
328+
mkdir "$GIT_WORKTREE/Performance/_generated"
329+
330+
build_swift_packages "$GIT_WORKTREE" "ForRev"
331+
${PROTOC} --plugin="$GIT_WORKTREE/.build/release/protoc-gen-swiftForRev" \
332+
--swiftForRev_out=FileNaming=DropPath:"$GIT_WORKTREE/Performance/_generated" \
333+
--proto_path=`dirname $gen_message_path` \
334+
"$gen_message_path"
335+
336+
harness_swift="$GIT_WORKTREE/Performance/_generated/harness_swift"
328337
results_trace="$script_dir/_results/$report_type (swift)"
329-
run_swift_harness "$tmp_checkout" "$comparison" "$commit_results"
338+
run_swift_harness "$GIT_WORKTREE" "$comparison" "$commit_results"
330339
else
331340
echo
332341
echo "==== Found cached results for Swift ($comparison) ===================="
@@ -341,10 +350,11 @@ echo "==== Building/running Swift harness (working tree) ===================="
341350
echo
342351

343352
build_swift_packages "$script_dir/.." "ForWorkTree"
344-
${PROTOC} --plugin="$script_dir/../.build/release/protoc-gen-swiftForWorkTree" \
345-
--swiftForWorkTree_out=FileNaming=DropPath:"$script_dir/_generated" \
346-
--cpp_out="$script_dir" \
347-
"$gen_message_path"
353+
354+
${PROTOC} --plugin="$script_dir/../.build/release/protoc-gen-swift" \
355+
--swift_out=FileNaming=DropPath:`dirname $gen_message_path` \
356+
--proto_path=`dirname $gen_message_path` \
357+
"$gen_message_path"
348358

349359
harness_swift="$script_dir/_generated/harness_swift"
350360
results_trace="$script_dir/_results/$report_type (swift)"
@@ -359,6 +369,5 @@ EOF
359369

360370
insert_visualization_results "$partial_results" "$results_js"
361371

362-
# Open the Instruments trace and HTML report at the end.
363-
open -g "$display_results_trace.trace"
372+
# Open the HTML report at the end.
364373
open -g "$script_dir/harness-visualization.html"

Performance/runners/CMakeLists.txt

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#
2+
# cmake configuration file for building the C++ test harness
3+
#
4+
# This assumes you have a protobuf source checkout handy,
5+
# and have used `git submodule update` to obtain all the
6+
# related source repos.
7+
#
8+
# This script uses the protobuf sources to build libprotobuf and
9+
# statically links it into the test harness executable.
10+
# (This is probably not necessary; updates to this file to
11+
# use a better strategy would be appreciated.)
12+
#
13+
# Also assumes that you have abseil_cpp and googletest installed
14+
# locally via e.g.,
15+
# brew install googletest
16+
# brew install abseil
17+
#
18+
19+
cmake_minimum_required(VERSION 3.10...3.26)
20+
set(CMAKE_CXX_STANDARD 17)
21+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
22+
set(CMAKE_BUILD_TYPE RelWithDebInfo)
23+
24+
project(swiftprotobuf-perf C CXX)
25+
26+
# Update this with the appropriate path to the protobuf source
27+
# checkout, starting from the directory holding this file.
28+
# Default here assumes that `protobuf` is checked out beside
29+
# `swift-protobuf`
30+
set(protobuf_SOURCE_DIR ${CMAKE_SOURCE_DIR}/../../../protobuf)
31+
set(protobuf_VERSION "999.999")
32+
33+
# Use protobuf cmake scripts to locate suitable abseil package:
34+
set(protobuf_ABSL_PROVIDER "package")
35+
include(${protobuf_SOURCE_DIR}/cmake/abseil-cpp.cmake)
36+
37+
# Use protobuf cmake scripts for building libprotobuf
38+
include(${protobuf_SOURCE_DIR}/cmake/libprotobuf.cmake)
39+
40+
# Use utf8_range from protobuf checkout
41+
set(utf8_range_SOURCE_DIR ${protobuf_SOURCE_DIR}/third_party/utf8_range)
42+
add_subdirectory(${utf8_range_SOURCE_DIR} third_party/utf8_range)
43+
44+
include_directories(
45+
${protobuf_SOURCE_DIR}/src
46+
${utf8_range_SOURCE_DIR}
47+
)
48+
49+
add_executable(harness_cpp
50+
../main.cc
51+
../Harness.cc
52+
../_generated/Harness+Generated.cc
53+
../_generated/message.pb.cc
54+
)
55+
56+
target_include_directories(harness_cpp PRIVATE
57+
${CMAKE_SOURCE_DIR}
58+
${CMAKE_SOURCE_DIR}/..
59+
${ABSL_ROOT_DIR}
60+
${utf8_range_SOURCE_DIR}
61+
)
62+
63+
target_link_libraries(harness_cpp PRIVATE libprotobuf)

Performance/runners/cpp.sh

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,16 @@ function run_cpp_harness() {
2626
gen_harness_path="$script_dir/_generated/Harness+Generated.cc"
2727
generate_cpp_harness
2828

29-
echo "Building C++ test harness..."
30-
time ( g++ --std=c++11 -O \
31-
-o "$harness" \
32-
-I "$script_dir" \
33-
-I "$GOOGLE_PROTOBUF_CHECKOUT/src" \
34-
-L "$GOOGLE_PROTOBUF_CHECKOUT/src/.libs" \
35-
-lprotobuf \
36-
"$gen_harness_path" \
37-
"$script_dir/Harness.cc" \
38-
"$script_dir/_generated/message.pb.cc" \
39-
"$script_dir/main.cc" \
40-
)
29+
echo
30+
echo "Building C++ libprotobuf and performance test harness..."
4131
echo
4232

43-
# Make sure the dylib is loadable from the harness if the user hasn't
44-
# actually installed them.
45-
cp "$GOOGLE_PROTOBUF_CHECKOUT"/src/.libs/libprotobuf.*.dylib \
46-
"$script_dir/_generated"
33+
pushd $script_dir/runners
34+
cmake -B ../_generated -S .
35+
cmake --build ../_generated
36+
popd
4737

4838
run_harness_and_concatenate_results "C++" "$harness" "$partial_results"
39+
echo
4940
)
5041
}

0 commit comments

Comments
 (0)