Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ RUN mkdir /tmp/openssl && cd /tmp/openssl && \
cd ~ && rm -rf /tmp/openssl

# curl
RUN git clone --depth=1 -b curl-7_66_0 https://github.com/curl/curl.git /tmp/curl && \
RUN git clone --depth=1 -b curl-7_69_1 https://github.com/curl/curl.git /tmp/curl && \
cd /tmp/curl && \
./buildconf && \
./configure --disable-ldap --disable-shared --without-libssh2 \
Expand All @@ -75,8 +75,8 @@ RUN git clone --depth=1 -b v2.1.2 https://github.com/gflags/gflags.git /tmp/gfla

# google-glog
RUN mkdir /tmp/glog && cd /tmp/glog && \
curl -sL https://github.com/google/glog/archive/v0.3.5.tar.gz | \
tar xzv --strip=1 && ./configure --with-pic && \
curl -sL https://github.com/google/glog/archive/v0.4.0.tar.gz | \
tar xzv --strip=1 && ./autogen.sh && ./configure --with-pic && \
make -j && make install && \
cd ~ && rm -rf /tmp/glog

Expand Down
7 changes: 4 additions & 3 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ RUN mkdir /tmp/openssl && cd /tmp/openssl && \
cd ~ && rm -rf /tmp/openssl

# curl
RUN git clone --depth=1 -b curl-7_66_0 https://github.com/curl/curl.git /tmp/curl && \
RUN git clone --depth=1 -b curl-7_69_1 https://github.com/curl/curl.git /tmp/curl && \
cd /tmp/curl && \
./buildconf && \
./configure --disable-ldap --disable-shared --without-libssh2 \
Expand All @@ -73,8 +73,9 @@ RUN git clone --depth=1 -b v2.1.2 https://github.com/gflags/gflags.git /tmp/gfla

# google-glog
RUN mkdir /tmp/glog && cd /tmp/glog && \
curl -sL https://github.com/google/glog/archive/v0.3.5.tar.gz | \
tar xzv --strip=1 && LDFLAGS="-lexecinfo" ./configure --with-pic --enable-static && \
curl -sL https://github.com/google/glog/archive/v0.4.0.tar.gz | \
tar xzv --strip=1 && ./autogen.sh && \
LDFLAGS="-lexecinfo" ./configure --with-pic --enable-static && \
make -j && make install && \
cd ~ && rm -rf /tmp/glog

Expand Down
16 changes: 14 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

CC = g++

# Determine the machine type.
machine_type := $(shell uname -m)

# -fpermissive used to bypass <:: errors from gcc 4.7
CFLAGS = \
-m64 \
-std=c++11 \
-fpermissive \
-fPIC \
Expand All @@ -31,13 +33,23 @@ CFLAGS = \
-D_GNU_SOURCE \
-DENABLE_HEAP_SAMPLING

ifeq ($(machine_type),$(filter $(machine_type),aarch64 arm64))
# Building on an ARM64 machine.
CFLAGS += \
-march=native \
-mtune=native \
-mcpu=native
JAVA_PATH ?= /usr/lib/jvm/java-11-openjdk-arm64
else
CFLAGS += -m64
JAVA_PATH ?= /usr/lib/jvm/java-11-openjdk-amd64
endif
ifneq ($(AGENT_VERSION),)
CFLAGS += -DCLOUD_PROFILER_AGENT_VERSION=\"$(AGENT_VERSION)\"
endif

SRC_ROOT_PATH=.

JAVA_PATH ?= /usr/lib/jvm/java-11-openjdk-amd64
PROTOC ?= /usr/local/bin/protoc
PROTOC_GEN_GRPC ?= /usr/local/bin/grpc_cpp_plugin

Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ commands below.
$ ./build.sh
```

## To build for Alpine.
## To build for Alpine

**Only Alpine versions 3.11 and later are currently supported.**

Expand All @@ -39,5 +39,16 @@ the flag `-cprof_cpu_use_per_thread_timers` is ignored on this platform.
```shell
$ git clone https://github.com/GoogleCloudPlatform/cloud-profiler-java.git
$ cd cloud-profiler-java
$ ./build.sh -a
$ ./build.sh -m alpine
```

## To build for ARM64

**Support for ARM64 is provided for testing purposes only.** The following
commands must be run on an ARM64 machine. Cross compilation is not supported.

```shell
$ git clone https://github.com/GoogleCloudPlatform/cloud-profiler-java.git
$ cd cloud-profiler-java
$ ./build.sh -m arm64
```
46 changes: 40 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,52 @@ set -o nounset
#
# Command line arguments: [-d]
# -d: specify the temporary directory for the build.
# -m: use 'amd64' to build for amd64, 'alpine' for Alpine Linux,
# 'arm64' for ARM64. Omitting -m builds for amd64.
# -v: the version for this build of the agent.

ARM64_BUILD="0"
ALPINE_BUILD="0"
DOCKERFILE="Dockerfile"
FILE_SUFFIX=""
while getopts ":ad:v:" opt; do
MACHINE_TYPE=$(uname -m)
while getopts ":d:m:v:" opt; do
case $opt in
a)
ALPINE_BUILD="1"
FILE_SUFFIX="_alpine"
;;
d)
BUILD_TEMP_DIR=$OPTARG
;;
m)
TARGET=$OPTARG
if [[ "${TARGET}" == "arm64" ]]; then
if [[ "${MACHINE_TYPE}" != "aarch64" ]] || [[ "${MACHINE_TYPE}" != "arm64" ]]; then
echo "-m arm64 is supported only when running on an ARM64 system."
exit;
fi
ARM64_BUILD="1"
FILE_SUFFIX="_arm64"
ALPINE_BUILD="0"
echo "Building for ARM64 is provided only for testing."
elif [[ "${TARGET}" == "alpine" ]]; then
if [[ "${MACHINE_TYPE}" != "x86_64" ]]; then
echo "-m alpine is supported only when running on an x86_64 system."
exit;
fi
ALPINE_BUILD="1"
FILE_SUFFIX="_alpine"
ARM64_BUILD="0"
elif [[ "${TARGET}" == "amd64" ]]; then
if [[ "${MACHINE_TYPE}" != "x86_64" ]]; then
echo "-m amd64 is supported only when running on an x86_64 system."
exit;
fi
ARM64_BUILD="0"
ALPINE_BUILD="0"
FILE_SUFFIX=""
else
echo "-m must be either amd64, arm64 or alpine."
exit;
fi
;;
v)
VERSION=$OPTARG
;;
Expand Down Expand Up @@ -75,10 +107,12 @@ mkdir -p "${BUILD_TEMP_DIR}"
if [[ "${ALPINE_BUILD}" = "1" ]]; then
PrintMessage "Building the builder Alpine Docker container..."
DOCKERFILE="Dockerfile.alpine"
elif [[ "${ARM64_BUILD}" = "1" ]]; then
PrintMessage "Building the builder ARM64 Docker container..."
else
PrintMessage "Building the builder Docker container..."
fi
docker build -f "${DOCKERFILE}" -t cprof-agent-builder . >> "${LOG_FILE}" 2>&1
docker build -f "${DOCKERFILE}" -t cprof-agent-builder . >> "${LOG_FILE}" 2>&1

PrintMessage "Packaging the agent code..."
mkdir -p "${BUILD_TEMP_DIR}"/build
Expand Down
6 changes: 2 additions & 4 deletions src/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ namespace cloud {
namespace profiler {

using google::javaprofiler::Clock;
using google::javaprofiler::kNanosPerSecond;
using google::javaprofiler::kNanosPerMilli;
using google::javaprofiler::kNanosPerSecond;

inline struct timespec TimeAdd(const struct timespec t1,
const struct timespec t2) {
Expand All @@ -44,9 +44,7 @@ inline int64_t TimeSpecToNanos(const struct timespec &ts) {
return google::javaprofiler::TimeSpecToNanos(ts);
}

inline Clock *DefaultClock() {
return google::javaprofiler::DefaultClock();
}
inline Clock *DefaultClock() { return google::javaprofiler::DefaultClock(); }

} // namespace profiler
} // namespace cloud
Expand Down
1 change: 1 addition & 0 deletions src/cloud_profiler_java_agent.lds
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
VERS_1.0 {
global:
google_find_phdr;
Agent_OnLoad;
Agent_OnUnload;
Java_org_apache_beam_runners_dataflow_worker_profiler_Profiler_disable;
Expand Down
14 changes: 7 additions & 7 deletions src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ namespace profiler {
// easier to just re-use the constants this way to keep the code easy to read.
//
// Remove this when porting is done.
using google::javaprofiler::kDeopt;
using google::javaprofiler::kGcActive;
using google::javaprofiler::kNativeStackTrace;
using google::javaprofiler::kNoClassLoad;
using google::javaprofiler::kGcActive;
using google::javaprofiler::kUnknownNotJava;
using google::javaprofiler::kNotWalkableFrameJava;
using google::javaprofiler::kNotWalkableFrameNotJava;
using google::javaprofiler::kSafepoint;
using google::javaprofiler::kThreadExit;
using google::javaprofiler::kUnknownJava;
using google::javaprofiler::kNotWalkableFrameJava;
using google::javaprofiler::kUnknownNotJava;
using google::javaprofiler::kUnknownState;
using google::javaprofiler::kThreadExit;
using google::javaprofiler::kDeopt;
using google::javaprofiler::kSafepoint;

using google::javaprofiler::kCallTraceErrorLineNum;
using google::javaprofiler::kMaxFramesToCapture;
Expand All @@ -76,7 +76,7 @@ using google::javaprofiler::JVMPI_CallFrame;
using google::javaprofiler::JVMPI_CallTrace;

// Gets us around -Wunused-parameter
#define IMPLICITLY_USE(x) (void) x;
#define IMPLICITLY_USE(x) (void)x;

#define AGENTEXPORT __attribute__((visibility("default"))) JNIEXPORT

Expand Down
2 changes: 1 addition & 1 deletion src/http.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bool HTTPRequest::DoRequest(const std::string& url) {
size_t HTTPRequest::ResponseCallback(void* contents, size_t size, size_t nmemb,
std::string* resp) {
size_t real_size = size * nmemb;
resp->append(static_cast<char *>(contents), real_size);
resp->append(static_cast<char*>(contents), real_size);
return real_size;
}

Expand Down
7 changes: 6 additions & 1 deletion src/profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ void Profiler::Handle(int signum, siginfo_t *info, void *context) {
// counter in such case to provide at least some clue into where the time is
// being spent. The alternative would be to mark such samples as erroneous
// but it appears even having just the shared object name is more useful.
uint64_t pc = static_cast<ucontext_t*>(context)->uc_mcontext.gregs[REG_RIP];
#ifdef __aarch64__
uint64_t pc = static_cast<ucontext_t *>(context)->uc_mcontext.pc;
#else
uint64_t pc =
static_cast<ucontext_t *>(context)->uc_mcontext.gregs[REG_RIP];
#endif
trace.frames[0] =
JVMPI_CallFrame{kNativeFrameLineNum, reinterpret_cast<jmethodID>(pc)};
++trace.num_frames;
Expand Down
1 change: 1 addition & 0 deletions src/proto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <errno.h>
#include <stdlib.h>
#include <sys/time.h>

#include <map>
#include <string>

Expand Down
1 change: 1 addition & 0 deletions src/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define CLOUD_PROFILER_AGENT_JAVA_THREADS_H_

#include <time.h>

#include <mutex> // NOLINT(build/c++11)
#include <utility>

Expand Down
1 change: 0 additions & 1 deletion src/uploader_gcs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.


#include "src/uploader_gcs.h"

#include <sstream>
Expand Down