Skip to content
This repository has been archived by the owner on Sep 4, 2022. It is now read-only.

Commit

Permalink
Add profiler (#15)
Browse files Browse the repository at this point in the history
* build formatters

* update asphr-load-2

* update with airbnb version of rules_foreign_cc

* update where rules is called

* reset where the toolchains are

* reorder commands

* remove airbnb shit

* perf works atleast

* remove airbnb

* trunk fmt

Co-authored-by: Sualeh Asif <[email protected]>
Co-authored-by: Ubuntu <[email protected]>
  • Loading branch information
3 people authored Jun 22, 2022
1 parent d222508 commit ca33434
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 25 deletions.
26 changes: 16 additions & 10 deletions asphr/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# SPDX-License-Identifier: GPL-3.0-only
#

load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")

cc_library(
name = "asphr_lib",
srcs = [
Expand All @@ -12,8 +14,8 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
":assert",
":utils",
":log",
":utils",
"//third_party/json",
"@com_google_absl//absl/hash",
"@com_google_absl//absl/random",
Expand Down Expand Up @@ -71,22 +73,22 @@ cc_binary(
cc_library(
name = "log",
hdrs = [
"foreach.hpp",
"log.hpp",
"foreach.hpp"
],
linkstatic = True,
defines = select({
"//conditions:default": [],
":log_level_dbg": ["ASPHR_LOGLEVEL_DBG"],
":log_level_info": ["ASPHR_LOGLEVEL_INFO"],
":log_level_warn": ["ASPHR_LOGLEVEL_WARN"],
":log_level_err": ["ASPHR_LOGLEVEL_ERR"],
":log_level_info": ["ASPHR_LOGLEVEL_INFO"],
":log_level_none": ["ASPHR_LOGLEVEL_NONE"],
":log_level_warn": ["ASPHR_LOGLEVEL_WARN"],
"//conditions:default": [],
}),
linkstatic = True,
deps = [
"@com_google_absl//absl/strings",
"@com_google_absl//absl/time",
]
],
)

cc_binary(
Expand All @@ -101,27 +103,31 @@ cc_binary(
config_setting(
name = "opt_build",
values = {
"compilation_mode": "opt"
}
"compilation_mode": "opt",
},
)

config_setting(
name = "log_level_dbg",
values = {"define": "log_level=dbg"},
)

config_setting(
name = "log_level_info",
values = {"define": "log_level=info"},
)

config_setting(
name = "log_level_warn",
values = {"define": "log_level=warn"},
)

config_setting(
name = "log_level_err",
values = {"define": "log_level=err"},
)

config_setting(
name = "log_level_none",
values = {"define": "log_level=none"},
)
)
19 changes: 13 additions & 6 deletions asphr_load.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ def load_asphr_repos(asphr_path):
urls = ["https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip"],
)

http_archive(
name = "com_github_gperftools_gperftools",
build_file = asphr_path + "//:gperftools.BUILD",
patch_args = ["-p1"],
patches = [asphr_path + "//:gperftools.patch"], # random_shuffle not supported by c++20
sha256 = "83e3bfdd28b8bcf53222c3798d4d395d52dadbbae59e8730c4a6d31a9c3732d8",
strip_prefix = "gperftools-2.10",
urls = ["https://github.com/gperftools/gperftools/releases/download/gperftools-2.10/gperftools-2.10.tar.gz"],
)

http_archive(
name = "rules_cc",
sha256 = "4dccbfd22c0def164c8f47458bd50e0c7148f3d92002cdb459c2a96a68498241",
Expand All @@ -91,7 +101,7 @@ def load_asphr_repos(asphr_path):
"https://github.com/nelhage/rules_boost/archive/%s.tar.gz" % _RULES_BOOST_COMMIT,
],
patch_args = ["-p1"],
patches = [asphr_path + "//:rules_boost.patch"], # issue: https://github.com/nelhage/rules_boost/issues/160 (on certain linux distros, clang cannot find backtrace.h. see https://www.boost.org/doc/libs/1_71_0/doc/html/stacktrace/configuration_and_build.html#stacktrace.configuration_and_build.f3)
patches = [asphr_path + "//:rules_boost.patch"], # issue: https://github.com/nelhage/rules_boost/issues/160 (on certain linux distros, clang cannot find backtrace.h. see https://www.boost.org/doc/libs/1_71_0/doc/html/stacktrace/configuration_and_build.html#stacktrace.configuration_and_build.f3)
)

# To find additional information on this release or newer ones visit:
Expand All @@ -101,7 +111,7 @@ def load_asphr_repos(asphr_path):
sha256 = "872b04538ca20dad94791c348623f079ba93daf274c1d57ae6bfe0930ec77f0d",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_rust/releases/download/0.6.0/rules_rust-v0.6.0.tar.gz",
"https://github.com/bazelbuild/rules_rust/releases/download/0.6.0/rules_rust-v0.6.0.tar.gz",
"https://github.com/bazelbuild/rules_rust/releases/download/0.6.0/rules_rust-v0.6.0.tar.gz",
],
)

Expand All @@ -111,8 +121,5 @@ def load_asphr_repos(asphr_path):
strip_prefix = "cxx-1.0.68",
urls = ["https://github.com/dtolnay/cxx/archive/refs/tags/1.0.68.tar.gz"],
patch_args = ["-p1"],
patches = [asphr_path + "//:cxx.patch"], # issue: we want to derive custom traits in Rust that C++ doesn't necessarily need to know about!
patches = [asphr_path + "//:cxx.patch"], # issue: we want to derive custom traits in Rust that C++ doesn't necessarily need to know about!
)



13 changes: 5 additions & 8 deletions asphr_load2.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@

"""Load asphr repos (part 2)."""

load("@rules_proto_grpc//js:repositories.bzl", rules_proto_grpc_js_repos = "js_repos")
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps")
load("@com_grail_bazel_toolchain//toolchain:deps.bzl", "bazel_toolchain_dependencies")
load("@com_grail_bazel_toolchain//toolchain:rules.bzl", "llvm_toolchain")
load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps")
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")
load("@rules_proto_grpc//js:repositories.bzl", rules_proto_grpc_js_repos = "js_repos")
load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")
load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_deps")
load(":asphr_load.bzl", "RUST_VERSION")


def load_asphr_repos2():
"""Loads the remaining repositories for the asphr project (those that depend on load_asphr_repos())."""

Expand All @@ -40,8 +39,6 @@ def load_asphr_repos2():

rules_rust_dependencies()

rust_register_toolchains(version = RUST_VERSION, edition="2021")
rust_register_toolchains(version = RUST_VERSION, edition = "2021")

rust_analyzer_deps()


1 change: 0 additions & 1 deletion asphr_load3.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ def load_asphr_repos3():
"""Loads the remaining repositories for the asphr project (those that depend on load_asphr_repos2())."""

crate_universe_dependencies()

44 changes: 44 additions & 0 deletions gperftools.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make")

package(
default_visibility = ["//visibility:public"],
)

filegroup(
name = "all_srcs",
srcs = glob(["**"]),
visibility = ["//:__pkg__"],
)

# TODO: currently requires autoconf: `sudo apt install autoconf`. Make it independant of that.
configure_make(
name = "gperftools_build",
args = [
"install-libLTLIBRARIES",
"install-perftoolsincludeHEADERS",
], # the list of arguments passed to the make commands.
# autogen = True,
autoreconf = True,
configure_in_place = True,
configure_options = [
"--enable-shared=no",
"--enable-frame-pointers",
"--disable-libunwind",
],
lib_source = ":all_srcs",
linkopts = ["-lpthread"],
out_static_libs = select({
# "//bazel:debug_tcmalloc": ["libtcmalloc_debug.a"],
"//conditions:default": ["libtcmalloc_and_profiler.a"],
}),
)

# Workaround for https://github.com/bazelbuild/rules_foreign_cc/issues/227

cc_library(
name = "gperftools",
deps = [
"gperftools_build",
],
)
13 changes: 13 additions & 0 deletions gperftools.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/benchmark/malloc_bench.cc b/benchmark/malloc_bench.cc
index 371b8c6..55461b9 100644
--- a/benchmark/malloc_bench.cc
+++ b/benchmark/malloc_bench.cc
@@ -233,7 +233,7 @@ void randomize_one_size_class(size_t size) {
for (int i = 0; i < count; i++) {
randomize_buffer[i] = malloc(size);
}
- std::random_shuffle(randomize_buffer, randomize_buffer + count);
+ // std::random_shuffle(randomize_buffer, randomize_buffer + count);
for (int i = 0; i < count; i++) {
free(randomize_buffer[i]);
}

0 comments on commit ca33434

Please sign in to comment.