Projects >> android-frameworks-base-with-remote-control-service >>c9ad7c6dbb1d70b831cd79416cbe493ade50ed2c

Chunk
Conflicting content
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
<<<<<<< HEAD
=======
import java.io.PrintStream;
>>>>>>> 41e99538638795e38b0a02711ceb572d67a779a3
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
Solution content
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
File
SamplingProfilerIntegration.java
Developer's decision
Version 2
Kind of conflict
Import
Chunk
Conflicting content
     * Starts the profiler if profiling is enabled.
     */
    public static void start() {
<<<<<<< HEAD
        if (!enabled) return;
        SamplingProfiler.getInstance().start(samplingProfilerHz);
=======
        if (!enabled) {
            return;
        }
        ThreadGroup group = Thread.currentThread().getThreadGroup();
        SamplingProfiler.ThreadSet threadSet = SamplingProfiler.newThreadGroupTheadSet(group);
        INSTANCE = new SamplingProfiler(4, threadSet);
        INSTANCE.start(10);
>>>>>>> 41e99538638795e38b0a02711ceb572d67a779a3
    }

    /**
Solution content
     * Starts the profiler if profiling is enabled.
     */
    public static void start() {
        if (!enabled) {
            return;
        }
        ThreadGroup group = Thread.currentThread().getThreadGroup();
        SamplingProfiler.ThreadSet threadSet = SamplingProfiler.newThreadGroupTheadSet(group);
        INSTANCE = new SamplingProfiler(4, threadSet);
        INSTANCE.start(samplingProfilerHz);
    }

    /**
File
SamplingProfilerIntegration.java
Developer's decision
Manual
Kind of conflict
Attribute
If statement
Method invocation
Variable
Chunk
Conflicting content
    /**
     * Writes a snapshot if profiling is enabled.
     */
<<<<<<< HEAD
    public static void writeSnapshot(final String processName, final PackageInfo packageInfo) {
        if (!enabled) return;
=======
    public static void writeSnapshot(final String name) {
        if (!enabled) {
            return;
        }
>>>>>>> 41e99538638795e38b0a02711ceb572d67a779a3

        /*
         * If we're already writing a snapshot, don't bother enqueueing another
Solution content
    /**
     * Writes a snapshot if profiling is enabled.
     */
    public static void writeSnapshot(final String processName, final PackageInfo packageInfo) {
        if (!enabled) {
            return;
        }

        /*
         * If we're already writing a snapshot, don't bother enqueueing another
File
SamplingProfilerIntegration.java
Developer's decision
Combination
Kind of conflict
If statement
Method signature
Chunk
Conflicting content
     * Writes the zygote's snapshot to internal storage if profiling is enabled.
     */
    public static void writeZygoteSnapshot() {
<<<<<<< HEAD
        if (!enabled) return;
        writeSnapshot("zygote", null);
    }

    /**
     * pass in PackageInfo to retrieve various values for snapshot header
     */
    private static void writeSnapshot(String dir, String processName, PackageInfo packageInfo) {
        byte[] snapshot = SamplingProfiler.getInstance().snapshot();
        if (snapshot == null) {
=======
        if (!enabled) {
            return;
        }

        String dir = "/data/zygote/snapshots";
        new File(dir).mkdirs();
        writeSnapshot(dir, "zygote");
        INSTANCE.shutdown();
        INSTANCE = null;
    }

    private static void writeSnapshot(String dir, String name) {
        if (!enabled) {
>>>>>>> 41e99538638795e38b0a02711ceb572d67a779a3
            return;
        }
        INSTANCE.stop();
Solution content
     * Writes the zygote's snapshot to internal storage if profiling is enabled.
     */
    public static void writeZygoteSnapshot() {
        if (!enabled) {
            return;
        }
        writeSnapshot("zygote", null);
        INSTANCE.shutdown();
        INSTANCE = null;
    }

    /**
     * pass in PackageInfo to retrieve various values for snapshot header
     */
    private static void writeSnapshot(String dir, String processName, PackageInfo packageInfo) {
        if (!enabled) {
            return;
        }
        INSTANCE.stop();
File
SamplingProfilerIntegration.java
Developer's decision
Combination
Kind of conflict
Attribute
Comment
If statement
Method invocation
Method signature
Variable
Chunk
Conflicting content
         * we capture two snapshots in rapid succession.
         */
        long start = System.currentTimeMillis();
<<<<<<< HEAD
        String name = processName.replaceAll(":", ".");
        String path = dir + "/" + name + "-" +System.currentTimeMillis() + ".snapshot";
        FileOutputStream out = null;
        try {
            out = new FileOutputStream(path);
            generateSnapshotHeader(name, packageInfo, out);
            out.write(snapshot);
        } catch (IOException e) {
            Log.e(TAG, "Error writing snapshot.", e);
        } finally {
            try {
                if(out != null) {
                    out.close();
                }
            } catch (IOException ex) {
                // let it go.
            }
        }
        // set file readable to the world so that SamplingProfilerService
        // can put it to dropbox
        new File(path).setReadable(true, false);

        long elapsed = System.currentTimeMillis() - start;
        Log.i(TAG, "Wrote snapshot for " + name + " in " + elapsed + "ms.");
    }

    /**
     * generate header for snapshots, with the following format (like http header):
     *
     * Version: \n
     * Process: \n
     * Package: \n
     * Package-Version: \n
     * Build: \n
     * \n
     * 
     */
    private static void generateSnapshotHeader(String processName, PackageInfo packageInfo,
            FileOutputStream out) throws IOException {
        // profiler version
        out.write("Version: 1\n".getBytes());
        out.write(("Process: " + processName + "\n").getBytes());
        if(packageInfo != null) {
            out.write(("Package: " + packageInfo.packageName + "\n").getBytes());
            out.write(("Package-Version: " + packageInfo.versionCode + "\n").getBytes());
=======
        String path = dir + "/" + name.replace(':', '.') + "-"
                + System.currentTimeMillis() + ".snapshot";

        // Try to open the file a few times. The SD card may not be mounted.
        PrintStream out;
        int count = 0;
        while (true) {
            try {
                out = new PrintStream(new BufferedOutputStream(new FileOutputStream(path)));
                break;
            } catch (FileNotFoundException e) {
                if (++count > 3) {
                    Log.e(TAG, "Could not open " + path + ".");
                    return;
                }

                // Sleep for a bit and then try again.
                try {
                    Thread.sleep(2500);
                } catch (InterruptedException e1) { /* ignore */ }
            }
        }

        try {
            INSTANCE.writeHprofData(out);
        } finally {
            out.close();
        }
        if (out.checkError()) {
            Log.e(TAG, "Error writing snapshot.");
        } else {
            long elapsed = System.currentTimeMillis() - start;
            Log.i(TAG, "Wrote snapshot for " + name
                  + " in " + elapsed + "ms.");
>>>>>>> 41e99538638795e38b0a02711ceb572d67a779a3
        }
        out.write(("Build: " + Build.FINGERPRINT + "\n").getBytes());
        // single blank line means the end of snapshot header.
Solution content
            return;
        }
        try {
         * we capture two snapshots in rapid succession.
         */
        long start = System.currentTimeMillis();
        String name = processName.replaceAll(":", ".");
        String path = dir + "/" + name + "-" +System.currentTimeMillis() + ".snapshot";
        PrintStream out = null;
        try {
            out = new PrintStream(new BufferedOutputStream(new FileOutputStream(path)));
        } catch (IOException e) {
            Log.e(TAG, "Could not open " + path + ":" + e);
            generateSnapshotHeader(name, packageInfo, out);
            INSTANCE.writeHprofData(out);
        } finally {
            out.close();
        }
        if (out.checkError()) {
            Log.e(TAG, "Error writing snapshot.");
            return;
        }
        // set file readable to the world so that SamplingProfilerService
        // can put it to dropbox
        new File(path).setReadable(true, false);

        long elapsed = System.currentTimeMillis() - start;
        Log.i(TAG, "Wrote snapshot for " + name + " in " + elapsed + "ms.");
    }

    /**
     * generate header for snapshots, with the following format (like http header):
     *
     * Version: \n
     * Process: \n
     * Package: \n
     * Package-Version: \n
     * Build: \n
     * \n
     * 
     */
    private static void generateSnapshotHeader(String processName, PackageInfo packageInfo,
            PrintStream out) {
        // profiler version
        out.println("Version: 2");
        out.println("Process: " + processName);
        if (packageInfo != null) {
            out.println("Package: " + packageInfo.packageName);
            out.println("Package-Version: " + packageInfo.versionCode);
        }
        out.println("Build: " + Build.FINGERPRINT);
        // single blank line means the end of snapshot header.
File
SamplingProfilerIntegration.java
Developer's decision
Manual
Kind of conflict
Comment
If statement
Method invocation
Method signature
Try statement
Variable
While statement