Skip to content

Commit

Permalink
Disable arena tracking in libgapii.
Browse files Browse the repository at this point in the history
This is a significant performance improvement.
  • Loading branch information
AWoloszyn committed Feb 27, 2018
1 parent ccdf900 commit 359e387
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/memory/arena/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ go_library(
srcs = [
"arena.go",
],
cdeps = ["//core/memory/arena/cc"],
cdeps = ["//core/memory/arena/tracking_arena"],
cgo = True,
clinkopts = [], # keep
importpath = "github.com/google/gapid/core/memory/arena",
Expand Down
13 changes: 13 additions & 0 deletions core/memory/arena/cc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,16 @@ cc_library(
copts = cc_copts(),
visibility = ["//visibility:public"],
)

cc_library(
name = "tracking_arena",
srcs = glob(
["*.cpp"],
),
deps = [
"//core/cc",
],
hdrs = glob(["*.h"]),
copts = cc_copts() + ["-DTRACK_ALLOCATIONS"],
visibility = ["//visibility:public"],
)
20 changes: 20 additions & 0 deletions core/memory/arena/cc/arena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,46 +44,66 @@ namespace core {
Arena::Arena() {}

Arena::~Arena() {
#ifdef TRACK_ALLOCATIONS
for (void* ptr : allocations) {
::free(ptr);
}
allocations.clear();
#endif
}

void* Arena::allocate(uint32_t size, uint32_t align) {
void* ptr = malloc(size); // TODO: alignment
#ifdef TRACK_ALLOCATIONS
allocations.insert(ptr);
#endif
return ptr;
}

void* Arena::reallocate(void* ptr, uint32_t size, uint32_t align) {
GAPID_ASSERT_MSG(this->owns(ptr), "ptr: %p", ptr);
void* newptr = realloc(ptr, size); // TODO: alignment
#ifdef TRACK_ALLOCATIONS
allocations.erase(ptr);
allocations.insert(newptr);
#endif
return newptr;
}

void Arena::free(void* ptr) {
GAPID_ASSERT_MSG(this->owns(ptr), "ptr: %p", ptr);
#ifdef TRACK_ALLOCATIONS
allocations.erase(ptr);
#endif
::free(ptr);
}

bool Arena::owns(void* ptr) {
#ifdef TRACK_ALLOCATIONS
return allocations.count(ptr) == 1;
#else
return true;
#endif
}

size_t Arena::num_allocations() const {
#ifdef TRACK_ALLOCATIONS
return allocations.size();
#else
return 0;
#endif
}

size_t Arena::num_bytes_allocated() const {
#ifdef TRACK_ALLOCATIONS
size_t bytes = 0;
for (void* ptr : allocations) {
bytes += alloc_size(ptr);
}
return bytes;
#else
return 0;
#endif
}

} // namespace core
Expand Down
2 changes: 1 addition & 1 deletion gapii/cc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ cc_library(
"//core/memory/arena/cc",
"//core/memory_tracker/cc",
"//core/os/device/deviceinfo/cc",
"//gapil/runtime/cc",
"//gapil/runtime/cc:cc",
"//gapis/api:api_cc_proto",
"//gapis/api/gles/gles_pb:gles_pb_cc_proto",
"//gapis/api/gvr/gvr_pb:gvr_pb_cc_proto",
Expand Down
20 changes: 16 additions & 4 deletions gapil/runtime/cc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,25 @@ cc_library(
hdrs = glob(["*.h"]),
copts = cc_copts(),
visibility = ["//visibility:public"],
)

cc_library(
name = "cc",
srcs = [
"runtime.cpp",
"string.cpp",
],
hdrs = glob(["*.inc"]),
copts = cc_copts(),
visibility = ["//visibility:public"],
deps = [
"//core/memory/arena/cc",
":headers",
"//core/memory/arena/cc:cc",
],
)

cc_library(
name = "cc",
name = "test_cc",
srcs = [
"runtime.cpp",
"string.cpp",
Expand All @@ -35,7 +47,7 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
":headers",
"//core/memory/arena/cc",
"//core/memory/arena/cc:tracking_arena",
],
)

Expand All @@ -53,7 +65,7 @@ cc_test(
"//conditions:default": [],
}),
deps = [
":cc",
":test_cc",
"@gtest//:gtest_main",
]
)
5 changes: 5 additions & 0 deletions gapil/runtime/cc/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
#include <stdlib.h>
#include <stdarg.h>

#if TARGET_OS == GAPID_OS_ANDROID
// for snprintf
#include <cstdio>
#endif

#define __STDC_FORMAT_MACROS
#include <inttypes.h>

Expand Down

0 comments on commit 359e387

Please sign in to comment.