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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ RUN mkdir /tmp/openssl && cd /tmp/openssl && \
cd ~ && rm -rf /tmp/openssl

# curl
RUN git clone --depth=1 -b curl-7_69_1 https://github.com/curl/curl.git /tmp/curl && \
RUN git clone --depth=1 -b curl-8_10_1 https://github.com/curl/curl.git /tmp/curl && \
cd /tmp/curl && \
./buildconf && \
./configure --disable-ldap --disable-shared --without-libssh2 \
--without-librtmp --without-libidn --enable-static \
--without-libidn2 \
--without-libidn2 --without-libpsl \
--with-pic --with-ssl=/usr/local/ssl/ && \
make -j && make install && \
cd ~ && rm -rf /tmp/curl
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ RUN mkdir /tmp/openssl && cd /tmp/openssl && \
cd ~ && rm -rf /tmp/openssl

# curl
RUN git clone --depth=1 -b curl-7_69_1 https://github.com/curl/curl.git /tmp/curl && \
RUN git clone --depth=1 -b curl-8_10_1 https://github.com/curl/curl.git /tmp/curl && \
cd /tmp/curl && \
./buildconf && \
./configure --disable-ldap --disable-shared --without-libssh2 \
--without-librtmp --without-libidn --enable-static \
--without-libidn2 \
--without-libidn2 --without-libpsl \
--with-pic --with-ssl=/usr/local/ssl/ && \
make -j && make install && \
cd ~ && rm -rf /tmp/curl
Expand Down
10 changes: 10 additions & 0 deletions src/throttler_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@

#include <grpc/grpc_security.h>
#include <grpc/support/string_util.h>
#include <grpcpp/client_context.h>
#include <grpcpp/create_channel.h>
#include <grpcpp/security/credentials.h>
#include <grpcpp/support/channel_arguments.h>
#include <grpcpp/support/status.h>

#include <algorithm>
#include <chrono> // NOLINT
#include <cstddef>
#include <cstdint>
#include <ctime>
#include <map>
#include <memory>
#include <mutex>
Expand All @@ -36,6 +41,7 @@
#include "src/globals.h"
#include "src/pem_roots.h"
#include "src/string.h"
#include "src/throttler.h"
#include "google/devtools/cloudprofiler/v2/profiler.grpc.pb.h"
#include "google/protobuf/duration.pb.h" // NOLINT
#include "google/rpc/error_details.pb.h" // NOLINT
Expand Down Expand Up @@ -76,6 +82,7 @@ const char kServiceVersionLabel[] = "version";
// Range of random number
const int64_t kRandomRange = 65536;

#ifdef STANDALONE_BUILD
// Routes GRPC logging through cloud profiler logger.
// Otherwise GRPC would log to stderr.
void GRPCLog(gpr_log_func_args* args) {
Expand All @@ -93,6 +100,7 @@ void GRPCLog(gpr_log_func_args* args) {
<< args->message;
}
}
#endif // STANDALONE_BUILD

// Overrides the default SSL roots. Otherwise gRPC calls would fail if a SSL
// roots file can't be found neither at a location specified by
Expand Down Expand Up @@ -285,7 +293,9 @@ APIThrottler::APIThrottler(
// GRPCLog is equivalent to what gRPC is doing internally, it would be safe to
// delete this line and the entire GRPCLog function when you upgrade gRPC to
// version 1.65 or later.
#ifdef STANDALONE_BUILD
gpr_set_log_function(GRPCLog);
#endif // STANDALONE_BUILD

// Create a random number generator.
gen_ = std::default_random_engine(clock_->Now().tv_nsec / 1000);
Expand Down
4 changes: 4 additions & 0 deletions src/throttler_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
#ifndef CLOUD_PROFILER_AGENT_JAVA_THROTTLER_API_H_
#define CLOUD_PROFILER_AGENT_JAVA_THROTTLER_API_H_

#include <grpcpp/client_context.h>
#include <grpcpp/support/status.h>
#include <jni.h>

#include <atomic>
#include <cstdint>
#include <ctime>
#include <memory>
#include <mutex> // NOLINT
#include <random>
Expand Down
24 changes: 24 additions & 0 deletions third_party/perftools/profiles/proto/builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ int64_t Builder::StringId(const char *str) {
if (str == nullptr || !str[0]) {
return 0;
}
return InternalStringId(str);
}

int64_t Builder::InternalStringId(const std::string &str) {
const int64_t index = profile_->string_table_size();
const auto inserted = strings_.emplace(str, index);
if (!inserted.second) {
Expand Down Expand Up @@ -108,6 +111,22 @@ uint64_t Builder::FunctionId(const char *name, const char *system_name,
return index;
}

void Builder::SetDocURL(const std::string &url) {
const std::string kHttp = "http://";
const std::string kHttps = "https://";

if (!url.empty() && url.compare(0, kHttp.size(), kHttp) != 0 &&
url.compare(0, kHttps.size(), kHttps) != 0) {
if (error_.empty()) {
error_ = "setting invalid profile doc URL '";
error_.append(url);
error_.append("'");
}
return;
}
profile_->set_doc_url(InternalStringId(url));
}

bool Builder::Emit(std::string *output) {
*output = "";
if (!profile_ || !Finalize()) {
Expand Down Expand Up @@ -265,6 +284,11 @@ bool Builder::CheckValid(const Profile &profile) {
// - Creates missing locations for unsymbolized profiles.
// - Associates locations to the corresponding mappings.
bool Builder::Finalize() {
if (!error_.empty()) {
// We really should be returning an absl::Status instead of logging here.
LOG(ERROR) << error_;
return false;
}
if (profile_->location_size() == 0) {
IndexMap address_to_id;
address_to_id.reserve(profile_->sample_size());
Expand Down
8 changes: 8 additions & 0 deletions third_party/perftools/profiles/proto/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class Builder {
// Adds mappings for the currently running binary to the profile.
void AddCurrentMappings();

// Add documentation URL.
void SetDocURL(const std::string &url);

// Prepares the profile for encoding. Returns true on success.
// If the profile has no locations, inserts location using the
// location_ids from the samples as addresses.
Expand Down Expand Up @@ -128,12 +131,17 @@ class Builder {
Profile *mutable_profile() { return profile_.get(); }

private:
int64_t InternalStringId(const std::string &str);

// Maps to deduplicate strings and functions.
StringIndexMap strings_;
FunctionIndexMap functions_;

// Actual profile being updated.
std::unique_ptr<Profile> profile_;

// Any error that may have been encountered while building the profile.
std::string error_;
};

} // namespace profiles
Expand Down
6 changes: 6 additions & 0 deletions third_party/perftools/profiles/proto/profile.proto
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ message Profile {
// Index into the string table of the type of the preferred sample
// value. If unset, clients should default to the last sample value.
int64 default_sample_type = 14;
// Documentation link for this profile. The URL must be absolute,
// e.g., http://pprof.example.com/cpu-profile.html
//
// The URL may be missing if the profile was generated by older code or code
// that did not bother to supply a link.
int64 doc_url = 15; // Index into string table.
}

// ValueType describes the semantics and measurement units of a value.
Expand Down