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
This commit is contained in:
Lee Shombert
2022-09-18 18:17:26 -07:00
parent eb803fd53e
commit d6d914d6d7
2 changed files with 5 additions and 1 deletions

View File

@@ -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),

View File

@@ -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() {