Skip to content

Commit

Permalink
Pipe in native interface for logging classloads
Browse files Browse the repository at this point in the history
Summary: Profilo has a Java interface for logging classloads, but no native interface yet.

Reviewed By: BurntBrunch

Differential Revision: D7444993

fbshipit-source-id: 570a793029be23f887cf2db3fe2458bf2080ec86
  • Loading branch information
tophyr authored and facebook-github-bot committed Apr 20, 2018
1 parent dea7f80 commit 59cf99c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
12 changes: 11 additions & 1 deletion cpp/api/ExternalApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,22 @@ void api_mark_end(const char* provider) {
}
api->mark_end(provider);
}

void api_log_classload(const char* provider, int64_t classid) {
auto api = get_api_int();
if (api == nullptr) {
return;
}
api->log_classload(provider, classid);
}

} // namespace anonymous

ProfiloApi* profilo_api() {
static ProfiloApi api {
.mark_start = &api_mark_start,
.mark_end = &api_mark_end
.mark_end = &api_mark_end,
.log_classload = &api_log_classload,
};
return &api;
}
Expand Down
3 changes: 3 additions & 0 deletions cpp/api/ExternalApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,20 @@
#pragma once

#include <unistd.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef void (*profilo_int_mark_start)(const char* provider, const char* msg);
typedef void (*profilo_int_mark_end)(const char* provider);
typedef void (*profilo_int_log_classload)(const char* provider, int64_t classid);

typedef struct ProfiloApi {
profilo_int_mark_start mark_start;
profilo_int_mark_end mark_end;
profilo_int_log_classload log_classload;
} ProfiloApi;

ProfiloApi* profilo_api();
Expand Down
17 changes: 16 additions & 1 deletion cpp/api/ExternalApiImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ void internal_mark_end(const char* provider) {
logger.write(std::move(entry));
}

void internal_log_classload(const char* provider, int64_t classid) {
if (!TraceProviders::get().isEnabled(provider)) {
return;
}

auto& logger = Logger::get();
StandardEntry entry{};
entry.tid = threadID();
entry.timestamp = monotonicTime();
entry.type = entries::CLASS_LOAD;
entry.extra = classid;
logger.write(std::move(entry));
}

} // namespace

#ifdef __cplusplus
Expand All @@ -69,7 +83,8 @@ extern "C" {

PROFILO_EXPORT ProfiloApi profilo_api_int {
.mark_start = &internal_mark_start,
.mark_end = &internal_mark_end
.mark_end = &internal_mark_end,
.log_classload = &internal_log_classload,
};

#ifdef __cplusplus
Expand Down

0 comments on commit 59cf99c

Please sign in to comment.