Example usage for android.util TimingLogger TimingLogger

List of usage examples for android.util TimingLogger TimingLogger

Introduction

In this page you can find the example usage for android.util TimingLogger TimingLogger.

Prototype

public TimingLogger(String tag, String label) 

Source Link

Document

Create and initialize a TimingLogger object that will log using the specific tag.

Usage

From source file:Main.java

@SuppressLint("NewApi")
public static Bitmap NV21ToRGBABitmap(byte[] nv21, int width, int height, Context context) {

    TimingLogger timings = new TimingLogger(TIMING_LOG_TAG, "NV21ToRGBABitmap");

    Rect rect = new Rect(0, 0, width, height);

    try {//  w  w w . j a  va2 s  .com
        Class.forName("android.renderscript.Element$DataKind").getField("PIXEL_YUV");
        Class.forName("android.renderscript.ScriptIntrinsicYuvToRGB");
        byte[] imageData = nv21;
        if (mRS == null) {
            mRS = RenderScript.create(context);
            mYuvToRgb = ScriptIntrinsicYuvToRGB.create(mRS, Element.U8_4(mRS));
            Type.Builder tb = new Type.Builder(mRS,
                    Element.createPixel(mRS, Element.DataType.UNSIGNED_8, Element.DataKind.PIXEL_YUV));
            tb.setX(width);
            tb.setY(height);
            tb.setMipmaps(false);
            tb.setYuvFormat(ImageFormat.NV21);
            ain = Allocation.createTyped(mRS, tb.create(), Allocation.USAGE_SCRIPT);
            timings.addSplit("Prepare for ain");
            Type.Builder tb2 = new Type.Builder(mRS, Element.RGBA_8888(mRS));
            tb2.setX(width);
            tb2.setY(height);
            tb2.setMipmaps(false);
            aOut = Allocation.createTyped(mRS, tb2.create(), Allocation.USAGE_SCRIPT & Allocation.USAGE_SHARED);
            timings.addSplit("Prepare for aOut");
            bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            timings.addSplit("Create Bitmap");
        }
        ain.copyFrom(imageData);
        timings.addSplit("ain copyFrom");
        mYuvToRgb.setInput(ain);
        timings.addSplit("setInput ain");
        mYuvToRgb.forEach(aOut);
        timings.addSplit("NV21 to ARGB forEach");
        aOut.copyTo(bitmap);
        timings.addSplit("Allocation to Bitmap");
    } catch (Exception e) {
        YuvImage yuvImage = new YuvImage(nv21, ImageFormat.NV21, width, height, null);
        timings.addSplit("NV21 bytes to YuvImage");

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        yuvImage.compressToJpeg(rect, 90, baos);
        byte[] cur = baos.toByteArray();
        timings.addSplit("YuvImage crop and compress to Jpeg Bytes");

        bitmap = BitmapFactory.decodeByteArray(cur, 0, cur.length);
        timings.addSplit("Jpeg Bytes to Bitmap");
    }

    timings.dumpToLog();
    return bitmap;
}

From source file:Main.java

@SuppressLint("NewApi")
public static Bitmap NV21ToRGBABitmap(byte[] nv21, int width, int height, Context context) {

    TimingLogger timings = new TimingLogger(TIMING_LOG_TAG, "NV21ToRGBABitmap");

    Rect rect = new Rect(0, 0, width, height);

    try {//from w w  w.  ja v a 2s.com
        Class.forName("android.renderscript.Element$DataKind").getField("PIXEL_YUV");
        Class.forName("android.renderscript.ScriptIntrinsicYuvToRGB");
        byte[] imageData = nv21;
        if (mRS == null) {
            mRS = RenderScript.create(context);
            mYuvToRgb = ScriptIntrinsicYuvToRGB.create(mRS, Element.U8_4(mRS));
            Type.Builder tb = new Type.Builder(mRS,
                    Element.createPixel(mRS, Element.DataType.UNSIGNED_8, Element.DataKind.PIXEL_YUV));
            tb.setX(width);
            tb.setY(height);
            tb.setMipmaps(false);
            tb.setYuvFormat(ImageFormat.NV21);
            ain = Allocation.createTyped(mRS, tb.create(), Allocation.USAGE_SCRIPT);
            timings.addSplit("Prepare for ain");
            Type.Builder tb2 = new Type.Builder(mRS, Element.RGBA_8888(mRS));
            tb2.setX(width);
            tb2.setY(height);
            tb2.setMipmaps(false);
            aOut = Allocation.createTyped(mRS, tb2.create(), Allocation.USAGE_SCRIPT & Allocation.USAGE_SHARED);
            timings.addSplit("Prepare for aOut");
            bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
            timings.addSplit("Create Bitmap");
        }
        ain.copyFrom(imageData);
        timings.addSplit("ain copyFrom");
        mYuvToRgb.setInput(ain);
        timings.addSplit("setInput ain");
        mYuvToRgb.forEach(aOut);
        timings.addSplit("NV21 to ARGB forEach");
        aOut.copyTo(bitmap);
        timings.addSplit("Allocation to Bitmap");
    } catch (Exception e) {
        YuvImage yuvImage = new YuvImage(nv21, ImageFormat.NV21, width, height, null);
        timings.addSplit("NV21 bytes to YuvImage");

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        yuvImage.compressToJpeg(rect, 90, baos);
        byte[] cur = baos.toByteArray();
        timings.addSplit("YuvImage crop and compress to Jpeg Bytes");

        bitmap = BitmapFactory.decodeByteArray(cur, 0, cur.length);
        timings.addSplit("Jpeg Bytes to Bitmap");
    }

    timings.dumpToLog();
    return bitmap;
}

From source file:org.mariotaku.twidere.util.net.TwidereDns.java

public TwidereDns(final Context context) {
    mLogger = new TimingLogger(RESOLVER_LOGTAG, "resolve");
    mHostMapping = SharedPreferencesWrapper.getInstance(context, HOST_MAPPING_PREFERENCES_NAME,
            Context.MODE_PRIVATE);
    mPreferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    mSystemHosts = new SystemHosts();
}

From source file:android.support.v7.graphics.ColorCutQuantizer.java

/**
 * Constructor./*from   w w w .java 2 s . c  o  m*/
 *
 * @param pixels histogram representing an image's pixel data
 * @param maxColors The maximum number of colors that should be in the result palette.
 * @param filters Set of filters to use in the quantization stage
 */
ColorCutQuantizer(final int[] pixels, final int maxColors, final Palette.Filter[] filters) {
    mTimingLogger = LOG_TIMINGS ? new TimingLogger(LOG_TAG, "Creation") : null;
    mFilters = filters;

    final int[] hist = mHistogram = new int[1 << (QUANTIZE_WORD_WIDTH * 3)];
    for (int i = 0; i < pixels.length; i++) {
        final int quantizedColor = quantizeFromRgb888(pixels[i]);
        // Now update the pixel value to the quantized value
        pixels[i] = quantizedColor;
        // And update the histogram
        hist[quantizedColor]++;
    }

    if (LOG_TIMINGS) {
        mTimingLogger.addSplit("Histogram created");
    }

    // Now let's count the number of distinct colors
    int distinctColorCount = 0;
    for (int color = 0; color < hist.length; color++) {
        if (hist[color] > 0 && shouldIgnoreColor(color)) {
            // If we should ignore the color, set the population to 0
            hist[color] = 0;
        }
        if (hist[color] > 0) {
            // If the color has population, increase the distinct color count
            distinctColorCount++;
        }
    }

    if (LOG_TIMINGS) {
        mTimingLogger.addSplit("Filtered colors and distinct colors counted");
    }

    // Now lets go through create an array consisting of only distinct colors
    final int[] colors = mColors = new int[distinctColorCount];
    int distinctColorIndex = 0;
    for (int color = 0; color < hist.length; color++) {
        if (hist[color] > 0) {
            colors[distinctColorIndex++] = color;
        }
    }

    if (LOG_TIMINGS) {
        mTimingLogger.addSplit("Distinct colors copied into array");
    }

    if (distinctColorCount <= maxColors) {
        // The image has fewer colors than the maximum requested, so just return the colors
        mQuantizedColors = new ArrayList<>();
        for (int color : colors) {
            mQuantizedColors.add(new Swatch(approximateToRgb888(color), hist[color]));
        }

        if (LOG_TIMINGS) {
            mTimingLogger.addSplit("Too few colors present. Copied to Swatches");
            mTimingLogger.dumpToLog();
        }
    } else {
        // We need use quantization to reduce the number of colors
        mQuantizedColors = quantizePixels(maxColors);

        if (LOG_TIMINGS) {
            mTimingLogger.addSplit("Quantized colors computed");
            mTimingLogger.dumpToLog();
        }
    }
}

From source file:com.mobileglobe.android.customdialer.common.model.AccountTypeManager.java

/**
 * Loads account list and corresponding account types (potentially with data sets). Always
 * called on a background thread.//from   w ww.  j av a  2s  .  c o m
 */
protected void loadAccountsInBackground() {
    if (Log.isLoggable(Constants.PERFORMANCE_TAG, Log.DEBUG)) {
        Log.d(Constants.PERFORMANCE_TAG, "AccountTypeManager.loadAccountsInBackground start");
    }
    TimingLogger timings = new TimingLogger(TAG, "loadAccountsInBackground");
    final long startTime = SystemClock.currentThreadTimeMillis();
    final long startTimeWall = SystemClock.elapsedRealtime();

    // Account types, keyed off the account type and data set concatenation.
    final Map<AccountTypeWithDataSet, AccountType> accountTypesByTypeAndDataSet = Maps.newHashMap();

    // The same AccountTypes, but keyed off {@link RawContacts#ACCOUNT_TYPE}.  Since there can
    // be multiple account types (with different data sets) for the same type of account, each
    // type string may have multiple AccountType entries.
    final Map<String, List<AccountType>> accountTypesByType = Maps.newHashMap();

    final List<AccountWithDataSet> allAccounts = Lists.newArrayList();
    final List<AccountWithDataSet> contactWritableAccounts = Lists.newArrayList();
    final List<AccountWithDataSet> groupWritableAccounts = Lists.newArrayList();
    final Set<String> extensionPackages = Sets.newHashSet();

    final AccountManager am = mAccountManager;

    final SyncAdapterType[] syncs = ContentResolver.getSyncAdapterTypes();
    final AuthenticatorDescription[] auths = am.getAuthenticatorTypes();

    // First process sync adapters to find any that provide contact data.
    for (SyncAdapterType sync : syncs) {
        if (!ContactsContract.AUTHORITY.equals(sync.authority)) {
            // Skip sync adapters that don't provide contact data.
            continue;
        }

        // Look for the formatting details provided by each sync
        // adapter, using the authenticator to find general resources.
        final String type = sync.accountType;
        final AuthenticatorDescription auth = findAuthenticator(auths, type);
        if (auth == null) {
            Log.w(TAG, "No authenticator found for type=" + type + ", ignoring it.");
            continue;
        }

        AccountType accountType;
        if (GoogleAccountType.ACCOUNT_TYPE.equals(type)) {
            accountType = new GoogleAccountType(mContext, auth.packageName);
        } else if (ExchangeAccountType.isExchangeType(type)) {
            accountType = new ExchangeAccountType(mContext, auth.packageName, type);
        } else if (SamsungAccountType.isSamsungAccountType(mContext, type, auth.packageName)) {
            accountType = new SamsungAccountType(mContext, auth.packageName, type);
        } else {
            Log.d(TAG, "Registering external account type=" + type + ", packageName=" + auth.packageName);
            accountType = new ExternalAccountType(mContext, auth.packageName, false);
        }
        if (!accountType.isInitialized()) {
            if (accountType.isEmbedded()) {
                throw new IllegalStateException(
                        "Problem initializing embedded type " + accountType.getClass().getCanonicalName());
            } else {
                // Skip external account types that couldn't be initialized.
                continue;
            }
        }

        accountType.accountType = auth.type;
        accountType.titleRes = auth.labelId;
        accountType.iconRes = auth.iconId;

        addAccountType(accountType, accountTypesByTypeAndDataSet, accountTypesByType);

        // Check to see if the account type knows of any other non-sync-adapter packages
        // that may provide other data sets of contact data.
        extensionPackages.addAll(accountType.getExtensionPackageNames());
    }

    // If any extension packages were specified, process them as well.
    if (!extensionPackages.isEmpty()) {
        Log.d(TAG, "Registering " + extensionPackages.size() + " extension packages");
        for (String extensionPackage : extensionPackages) {
            ExternalAccountType accountType = new ExternalAccountType(mContext, extensionPackage, true);
            if (!accountType.isInitialized()) {
                // Skip external account types that couldn't be initialized.
                continue;
            }
            if (!accountType.hasContactsMetadata()) {
                Log.w(TAG, "Skipping extension package " + extensionPackage + " because"
                        + " it doesn't have the CONTACTS_STRUCTURE metadata");
                continue;
            }
            if (TextUtils.isEmpty(accountType.accountType)) {
                Log.w(TAG, "Skipping extension package " + extensionPackage + " because"
                        + " the CONTACTS_STRUCTURE metadata doesn't have the accountType" + " attribute");
                continue;
            }
            Log.d(TAG, "Registering extension package account type=" + accountType.accountType + ", dataSet="
                    + accountType.dataSet + ", packageName=" + extensionPackage);

            addAccountType(accountType, accountTypesByTypeAndDataSet, accountTypesByType);
        }
    }
    timings.addSplit("Loaded account types");

    Account[] accounts = mAccountManager.getAccounts();
    for (Account account : accounts) {
        boolean syncable = ContentResolver.getIsSyncable(account, ContactsContract.AUTHORITY) > 0;

        if (syncable) {
            List<AccountType> accountTypes = accountTypesByType.get(account.type);
            if (accountTypes != null) {
                // Add an account-with-data-set entry for each account type that is
                // authenticated by this account.
                for (AccountType accountType : accountTypes) {
                    AccountWithDataSet accountWithDataSet = new AccountWithDataSet(account.name, account.type,
                            accountType.dataSet);
                    allAccounts.add(accountWithDataSet);
                    if (accountType.areContactsWritable()) {
                        contactWritableAccounts.add(accountWithDataSet);
                    }
                    if (accountType.isGroupMembershipEditable()) {
                        groupWritableAccounts.add(accountWithDataSet);
                    }
                }
            }
        }
    }

    Collections.sort(allAccounts, ACCOUNT_COMPARATOR);
    Collections.sort(contactWritableAccounts, ACCOUNT_COMPARATOR);
    Collections.sort(groupWritableAccounts, ACCOUNT_COMPARATOR);

    timings.addSplit("Loaded accounts");

    synchronized (this) {
        mAccountTypesWithDataSets = accountTypesByTypeAndDataSet;
        mAccounts = allAccounts;
        mContactWritableAccounts = contactWritableAccounts;
        mGroupWritableAccounts = groupWritableAccounts;
        mInvitableAccountTypes = findAllInvitableAccountTypes(mContext, allAccounts,
                accountTypesByTypeAndDataSet);
    }

    timings.dumpToLog();
    final long endTimeWall = SystemClock.elapsedRealtime();
    final long endTime = SystemClock.currentThreadTimeMillis();

    Log.i(TAG,
            "Loaded meta-data for " + mAccountTypesWithDataSets.size() + " account types, " + mAccounts.size()
                    + " accounts in " + (endTimeWall - startTimeWall) + "ms(wall) " + (endTime - startTime)
                    + "ms(cpu)");

    if (mInitializationLatch != null) {
        mInitializationLatch.countDown();
        mInitializationLatch = null;
    }
    if (Log.isLoggable(Constants.PERFORMANCE_TAG, Log.DEBUG)) {
        Log.d(Constants.PERFORMANCE_TAG, "AccountTypeManager.loadAccountsInBackground finish");
    }

    // Check filter validity since filter may become obsolete after account update. It must be
    // done from UI thread.
    mMainThreadHandler.post(mCheckFilterValidityRunnable);
}