Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b9f62d6b authored by Adithya Srinivasan's avatar Adithya Srinivasan
Browse files

GpuMem perfetto producer

To overcome the problem of ftrace gpumem events not emitting anything
during MEC (with apps that do launch-time allocations), this change adds
a perfetto producer to emit initial counter values at the start of a
trace, so that the visualization won't so zero usage.

Test: adb shell perfetto --query | grep gpu.
Test: Take a perfetto trace with android.gpumem enabled
Bug: 157142645
Change-Id: I5c8278754549399ffa51e6e6fc2ca69b51976cb2
parent a265b40f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ cc_defaults {
        "libcutils",
        "libgfxstats",
        "libgpumem",
        "libgpumemtracer",
        "libgraphicsenv",
        "liblog",
        "libutils",
+8 −2
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include <gpumem/GpuMem.h>
#include <gpustats/GpuStats.h>
#include <private/android_filesystem_config.h>
#include <tracing/GpuMemTracer.h>
#include <utils/String8.h>
#include <utils/Trace.h>
#include <vkjson.h>
@@ -48,8 +49,13 @@ const String16 sDump("android.permission.DUMP");
const char* const GpuService::SERVICE_NAME = "gpu";

GpuService::GpuService()
      : mGpuMem(std::make_unique<GpuMem>()), mGpuStats(std::make_unique<GpuStats>()) {
    std::thread asyncInitThread([this]() { mGpuMem->initialize(); });
      : mGpuMem(std::make_shared<GpuMem>()),
        mGpuStats(std::make_unique<GpuStats>()),
        mGpuMemTracer(std::make_unique<GpuMemTracer>()) {
    std::thread asyncInitThread([this]() {
        mGpuMem->initialize();
        mGpuMemTracer->initialize(mGpuMem);
    });
    asyncInitThread.detach();
};

+3 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ namespace android {

class GpuMem;
class GpuStats;
class GpuMemTracer;

class GpuService : public BnGpuService, public PriorityDumper {
public:
@@ -75,8 +76,9 @@ private:
    /*
     * Attributes
     */
    std::unique_ptr<GpuMem> mGpuMem;
    std::shared_ptr<GpuMem> mGpuMem;
    std::unique_ptr<GpuStats> mGpuStats;
    std::unique_ptr<GpuMemTracer> mGpuMemTracer;
    std::string developerDriverPath;
};

+23 −0
Original line number Diff line number Diff line
@@ -31,6 +31,29 @@ public:
    void initialize();
    // dumpsys interface
    void dump(const Vector<String16>& args, std::string* result);
    bool isInitialized() { return mInitialized.load(); }

    // Traverse the map and send each value read back to the callback function.
    // Used for tracing.
    template <typename lambda>
    void traceGpuMemTotals(lambda tracerCallback) {
        auto res = mGpuMemTotalMap.getFirstKey();
        if (!res.ok()) return;
        uint64_t key = res.value();
        while (true) {
            uint32_t gpu_id = key >> 32;
            uint32_t pid = key;

            res = mGpuMemTotalMap.readValue(key);
            if (!res.ok()) break;
            uint64_t size = res.value();

            tracerCallback(gpu_id, pid, size);
            res = mGpuMemTotalMap.getNextKey(key);
            if (!res.ok()) break;
            key = res.value();
        }
    }

private:
    // Friend class for testing.
+41 −0
Original line number Diff line number Diff line
// Copyright 2020 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

cc_library_shared {
    name: "libgpumemtracer",
    srcs: [
        "GpuMemTracer.cpp",
    ],
    shared_libs: [
        "libgpumem",
        "libbase",
        "liblog",
        "libutils",
    ],
    static_libs: [
        "libperfetto_client_experimental",
    ],
    export_include_dirs: ["include"],
    export_static_lib_headers: [
        "libperfetto_client_experimental",
    ],
    cppflags: [
        "-Wall",
        "-Werror",
        "-Wformat",
        "-Wthread-safety",
        "-Wunused",
        "-Wunreachable-code",
    ],
}
Loading