Skip to content

Commit

Permalink
Added C++ Version of trace collection shell script.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 265996122
  • Loading branch information
sabarabc authored and schedviz-eng committed Aug 28, 2019
1 parent ca15ffb commit fb9bd67
Show file tree
Hide file tree
Showing 9 changed files with 802 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ build --host_force_python=PY2
test --host_force_python=PY2
run --host_force_python=PY2

# Use Clang with C++17
build --crosstool_top=@llvm_toolchain//:toolchain
run --crosstool_top=@llvm_toolchain//:toolchain
test --crosstool_top=@llvm_toolchain//:toolchain

build --incompatible_strict_action_env --incompatible_new_actions_api=false --experimental_allow_incremental_repository_updates --incompatible_depset_is_not_iterable=false
run --incompatible_strict_action_env --incompatible_new_actions_api=false --experimental_allow_incremental_repository_updates --incompatible_depset_is_not_iterable=false
test --test_output=errors --incompatible_strict_action_env --incompatible_new_actions_api=false --experimental_allow_incremental_repository_updates --incompatible_depset_is_not_iterable=false
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ git clone https://github.com/google/schedviz.git
SchedViz requires *yarn*. Closely follow the installation instructions
on the [yarn Website](https://www.yarnpkg.com).

Building SchedViz also requires the GNU C++ compiler *g++*. On Debian, for
example, the dependency can be installed by executing this command:
Building SchedViz also requires the GNU build tools and the unzip utility. On Debian, for
example, the dependencies can be installed by executing this command:

```bash
sudo apt-get update && sudo apt-get install build-essential
sudo apt-get update && sudo apt-get install build-essential unzip
```

To run SchedViz, run the following commands:
Expand Down Expand Up @@ -79,6 +79,14 @@ To load SchedViz, go to http://localhost:7042/collections
The shell script collects the `sched_switch`, `sched_wakeup`,
`sched_wakeup_new`, and `sched_migrate_task` tracepoints.

> NOTE: There is also a binary version of the trace collector script, which
can collect traces larger than the size of the buffer.
>
> To build it, run `bazel build util:trace` from the root of the repo.
>
> To run it, run `sudo bazel-bin/util/trace`. It takes the same arguments
as the shell script, except -copy_timeout.

2. Copy the generated tar.gz file off of the trace machine to a machine that
can access the SchedViz UI.

Expand Down
43 changes: 43 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ http_archive(
sha256 = "f04d2373bcaf8aa09bccb08a98a57e721306c8f6043a2a0ee610fd6853dcde3d",
)

http_archive(
name = "com_grail_bazel_toolchain",
sha256 = "4a8ed1ec0349a43a82eebc0a5792417125fe387bae90952322cff2b9e8283d9c",
strip_prefix = "bazel-toolchain-664914644452a1eb8b746d3701612877c0eef24d",
urls = ["https://github.com/grailbio/bazel-toolchain/archive/664914644452a1eb8b746d3701612877c0eef24d.zip"],
)

http_archive(
name = "rules_cc",
sha256 = "67412176974bfce3f4cf8bdaff39784a72ed709fc58def599d1f68710b58d68b",
strip_prefix = "rules_cc-b7fe9697c0c76ab2fd431a891dbb9a6a32ed7c3e",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_cc/archive/b7fe9697c0c76ab2fd431a891dbb9a6a32ed7c3e.zip",
"https://github.com/bazelbuild/rules_cc/archive/b7fe9697c0c76ab2fd431a891dbb9a6a32ed7c3e.zip",
],
)
http_archive(
name = "bazel_gazelle",
urls = ["https://github.com/bazelbuild/bazel-gazelle/releases/download/0.17.0/bazel-gazelle-0.17.0.tar.gz"],
Expand Down Expand Up @@ -44,6 +60,17 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_reposi

check_bazel_version(minimum_bazel_version = "0.27.0")

load("@com_grail_bazel_toolchain//toolchain:rules.bzl", "llvm_toolchain")

llvm_toolchain(
name = "llvm_toolchain",
llvm_version = "8.0.0",
)

load("@llvm_toolchain//:toolchains.bzl", "llvm_register_toolchains")

llvm_register_toolchains()

# Setup the Node repositories. We need a NodeJS version that is more recent than v10.15.0
# because "selenium-webdriver" which is required for "ng e2e" cannot be installed.
# TODO: remove the custom repositories once "rules_nodejs" supports v10.16.0 by default.
Expand Down Expand Up @@ -121,6 +148,22 @@ go_repository(
tag = "112230192c580c3556b8cee6403af37a4fc5f28c",
)

# abseil-cpp
http_archive(
name = "com_google_absl",
urls = ["https://github.com/abseil/abseil-cpp/archive/20190808.zip"],
strip_prefix = "abseil-cpp-20190808",
sha256 = "0b62fc2d00c2b2bc3761a892a17ac3b8af3578bd28535d90b4c914b0a7460d4e",
)

# re2
http_archive(
name = "com_googlesource_code_re2",
urls = ["https://github.com/google/re2/archive/2019-08-01.zip"],
strip_prefix = "re2-2019-08-01",
sha256 = "ae686c2f48e8df31414476a5e8dea4221c6fa679c0444470ab8703c1730e51dc",
)

load("@npm_bazel_typescript//:defs.bzl", "ts_setup_workspace")

ts_setup_workspace()
Expand Down
1 change: 1 addition & 0 deletions tracedata/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
load("@io_bazel_rules_docker//container:container.bzl", "container_image")
load("@npm_bazel_typescript//:defs.bzl", "ts_library")
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")

Expand Down
24 changes: 24 additions & 0 deletions util/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
load("@rules_cc//cc:defs.bzl", "cc_binary")

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

licenses(["notice"]) # Apache License 2.0

cc_binary(
name = "trace",
srcs = [
"status.h",
"trace.cc",
"trace.h",
],
copts = ["-std=c++17"],
linkopts = ["-lc++fs"],
deps = [
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/flags:parse",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/time",
"@com_googlesource_code_re2//:re2",
],
)
37 changes: 37 additions & 0 deletions util/status.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef SCHEDVIZ_UTIL_STATUS_H_
#define SCHEDVIZ_UTIL_STATUS_H_

#include <string>

#include "absl/base/attributes.h"
#include "absl/strings/string_view.h"

enum class StatusCode : int {
kOk = 0,
kInternal = 13,
};

class ABSL_MUST_USE_RESULT Status final {
StatusCode code_;
std::string message_;

Status(StatusCode code, absl::string_view message)
: code_(code), message_(message) {}

public:
Status() : code_(StatusCode::kOk), message_("") {}

inline static Status InternalError(absl::string_view msg) {
return Status(StatusCode::kInternal, msg);
}

inline static Status OkStatus() { return Status(); }

StatusCode code() const { return code_; }

ABSL_MUST_USE_RESULT bool ok() const { return code_ == StatusCode::kOk; }

absl::string_view message() const { return message_; }
};

#endif // SCHEDVIZ_UTIL_STATUS_H_
Loading

0 comments on commit fb9bd67

Please sign in to comment.