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

Commit 9cefd00f authored by Android Git Automerger's avatar Android Git Automerger
Browse files

resolved conflicts for merge of 6ba69734 to eclair, skipping preloaded-classes as pre Bob

parents 30c0b834 6ba69734
Loading
Loading
Loading
Loading
+190 KiB (15.2 MiB)

File changed.

No diff preview for this file type.

+1 −1
Original line number Diff line number Diff line
@@ -3,13 +3,13 @@ LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
	ClassRank.java \
	Compile.java  \
	LoadedClass.java \
	MemoryUsage.java \
	Operation.java \
	Policy.java \
	PrintCsv.java \
	PrintHtmlDiff.java \
	PrintPsTree.java \
	Proc.java \
	Record.java \

tools/preload/ClassRank.java

deleted100644 → 0
+0 −53
Original line number Diff line number Diff line
/*
 * Copyright (C) 2008 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.
 */

import java.util.Comparator;

/**
 * Ranks classes for preloading based on how long their operations took
 * and how early the operations happened. Higher ranked classes come first.
 */
class ClassRank implements Comparator<Operation> {

    /**
     * Increase this number to add more weight to classes which were loaded
     * earlier.
     */
    static final int SEQUENCE_WEIGHT = 500; // 0.5ms

    static final int BUCKET_SIZE = 5;

    public int compare(Operation a, Operation b) {
        // Higher ranked operations should come first.
        int result = rankOf(b) - rankOf(a);
        if (result != 0) {
            return result;
        }

        // Make sure we don't drop one of two classes w/ the same rank.
        // If a load and an initialization have the same rank, it's OK
        // to treat the operations equally.
        return a.loadedClass.name.compareTo(b.loadedClass.name);
    }

    /** Ranks the given operation. */
    private static int rankOf(Operation o) {
        return o.medianExclusiveTimeMicros()
                + SEQUENCE_WEIGHT / (o.index / BUCKET_SIZE + 1);
    }
}

+14 −37
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ class LoadedClass implements Serializable, Comparable<LoadedClass> {
    }

    void measureMemoryUsage() {
//        this.memoryUsage = MemoryUsage.forClass(name);
        this.memoryUsage = MemoryUsage.forClass(name);
    }

    int mlt = -1;
@@ -76,6 +76,10 @@ class LoadedClass implements Serializable, Comparable<LoadedClass> {
        return mit = calculateMedian(initializations);
    }

    int medianTimeMicros() {
        return medianInitTimeMicros() + medianLoadTimeMicros();
    }

    /** Calculates the median duration for a list of operations. */
    private static int calculateMedian(List<Operation> operations) {
        int size = operations.size();
@@ -99,18 +103,18 @@ class LoadedClass implements Serializable, Comparable<LoadedClass> {
        }
    }

    /** Returns names of apps that loaded this class. */
    Set<String> applicationNames() {
        Set<String> appNames = new HashSet<String>();
        addProcessNames(loads, appNames);
        addProcessNames(initializations, appNames);
        return appNames;
    /** Returns names of processes that loaded this class. */
    Set<String> processNames() {
        Set<String> names = new HashSet<String>();
        addProcessNames(loads, names);
        addProcessNames(initializations, names);
        return names;
    }

    private void addProcessNames(List<Operation> ops, Set<String> appNames) {
    private void addProcessNames(List<Operation> ops, Set<String> names) {
        for (Operation operation : ops) {
            if (operation.process.isApplication()) {
                appNames.add(operation.process.name);
            if (operation.process.fromZygote()) {
                names.add(operation.process.name);
            }
        }
    }
@@ -123,31 +127,4 @@ class LoadedClass implements Serializable, Comparable<LoadedClass> {
    public String toString() {
        return name;
    }

    /**
     * Returns true if this class's initialization causes the given class to
     * initialize.
     */
    public boolean initializes(LoadedClass clazz, Set<LoadedClass> visited) {
        // Avoid infinite recursion.
        if (!visited.add(this)) {
            return false;
        }

        if (clazz == this) {
            return true;
        }

        for (Operation initialization : initializations) {
            if (initialization.loadedClass.initializes(clazz, visited)) {
                return true;
            }
        }

        return false;
    }

    public boolean isPreloadable() {
        return systemClass && Policy.isPreloadableClass(name);
    }
}
+26 −11
Original line number Diff line number Diff line
@@ -34,8 +34,8 @@ class MemoryUsage implements Serializable {
    static final MemoryUsage NOT_AVAILABLE = new MemoryUsage();
    
    static int errorCount = 0;
    static final int MAXIMUM_ERRORS = 10;        // give up after this many fails

    // These values are in 1kB increments (not 4kB like you'd expect).
    final int nativeSharedPages;
    final int javaSharedPages;
    final int otherSharedPages;
@@ -123,15 +123,24 @@ class MemoryUsage implements Serializable {
        return allocSize - freedSize;
    }

    int totalHeap() {
        return javaHeapSize() + (int) nativeHeapSize;
    }

    int javaPagesInK() {
        return (javaSharedPages + javaPrivatePages) * 4;
        return javaSharedPages + javaPrivatePages;
    }

    int nativePagesInK() {
        return (nativeSharedPages + nativePrivatePages) * 4;
        return nativeSharedPages + nativePrivatePages;
    }
    int otherPagesInK() {
        return (otherSharedPages + otherPrivatePages) * 4;
        return otherSharedPages + otherPrivatePages;
    }

    int totalPages() {
        return javaSharedPages + javaPrivatePages + nativeSharedPages +
                nativePrivatePages + otherSharedPages + otherPrivatePages;
    }

    /**
@@ -163,13 +172,6 @@ class MemoryUsage implements Serializable {
     * Measures memory usage for the given class.
     */
    static MemoryUsage forClass(String className) {
        
        // This is a coarse approximation for determining that no device is connected,
        // or that the communication protocol has changed, but we'll keep going and stop whining.
        if (errorCount >= MAXIMUM_ERRORS) {
            return NOT_AVAILABLE;
        }
        
        MeasureWithTimeout measurer = new MeasureWithTimeout(className);

        new Thread(measurer).start();
@@ -280,4 +282,17 @@ class MemoryUsage implements Serializable {
            e.printStackTrace();
        }
    }

    /** Measures memory usage information and stores it in the model. */
    public static void main(String[] args) throws IOException,
            ClassNotFoundException {
        Root root = Root.fromFile(args[0]);
        root.baseline = baseline();
        for (LoadedClass loadedClass : root.loadedClasses.values()) {
            if (loadedClass.systemClass) {
                loadedClass.measureMemoryUsage();
            }
        }
        root.toFile(args[0]);
    }
}
Loading