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

Commit d6d914d6 authored by Lee Shombert's avatar Lee Shombert
Browse files

Enable recording resource access times

Bug: 246953799

Monitor AssetManager.getResourceValue and AssetManager.retrieveAttributes.
The ResourceTimer loop is started from ResourcesManagerService, which
runs only on system_server.

Publication of the collected resource statistics will be done in a
subsequent commit.  For now, collected statistics values are logged.

Test: atest
 * androidfw_lib

Change-Id: I47b349900429969a6ae8436dc6b00416e9dd76fc
parent eb803fd5
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@
#include "androidfw/AssetManager2.h"
#include "androidfw/AttributeResolution.h"
#include "androidfw/MutexGuard.h"
#include <androidfw/ResourceTimer.h>
#include "androidfw/ResourceTypes.h"
#include "androidfw/ResourceUtils.h"

@@ -630,6 +631,7 @@ static jint NativeGetResourceValue(JNIEnv* env, jclass /*clazz*/, jlong ptr, jin
                                   jshort density, jobject typed_value,
                                   jboolean resolve_references) {
  ScopedLock<AssetManager2> assetmanager(AssetManagerFromLong(ptr));
  ResourceTimer _tag(ResourceTimer::Counter::GetResourceValue);
  auto value = assetmanager->GetResource(static_cast<uint32_t>(resid), false /*may_be_bag*/,
                                         static_cast<uint16_t>(density));
  if (!value.has_value()) {
@@ -1232,6 +1234,7 @@ static jboolean NativeRetrieveAttributes(JNIEnv* env, jclass /*clazz*/, jlong pt
  }

  ScopedLock<AssetManager2> assetmanager(AssetManagerFromLong(ptr));
  ResourceTimer _tag(ResourceTimer::Counter::RetrieveAttributes);
  ResXMLParser* xml_parser = reinterpret_cast<ResXMLParser*>(xml_parser_ptr);
  auto result =
          RetrieveAttributes(assetmanager.get(), xml_parser, reinterpret_cast<uint32_t*>(attrs),
+2 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.content.res.IResourcesManager;
import android.content.res.ResourceTimer;
import android.os.Binder;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
@@ -55,7 +56,7 @@ public class ResourcesManagerService extends SystemService {

    @Override
    public void onStart() {
        // Intentionally left empty.
        ResourceTimer.start();
    }

    private final IBinder mService = new IResourcesManager.Stub() {