mobile/android/thirdparty/com/squareup/picasso/StatsSnapshot.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/thirdparty/com/squareup/picasso/StatsSnapshot.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,120 @@
     1.4 +/*
     1.5 + * Copyright (C) 2013 Square, Inc.
     1.6 + *
     1.7 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.8 + * you may not use this file except in compliance with the License.
     1.9 + * You may obtain a copy of the License at
    1.10 + *
    1.11 + *      http://www.apache.org/licenses/LICENSE-2.0
    1.12 + *
    1.13 + * Unless required by applicable law or agreed to in writing, software
    1.14 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.16 + * See the License for the specific language governing permissions and
    1.17 + * limitations under the License.
    1.18 + */
    1.19 +package com.squareup.picasso;
    1.20 +
    1.21 +import android.util.Log;
    1.22 +import java.io.PrintWriter;
    1.23 +import java.io.StringWriter;
    1.24 +
    1.25 +/** Represents all stats for a {@link Picasso} instance at a single point in time. */
    1.26 +public class StatsSnapshot {
    1.27 +  private static final String TAG = "Picasso";
    1.28 +
    1.29 +  public final int maxSize;
    1.30 +  public final int size;
    1.31 +  public final long cacheHits;
    1.32 +  public final long cacheMisses;
    1.33 +  public final long totalOriginalBitmapSize;
    1.34 +  public final long totalTransformedBitmapSize;
    1.35 +  public final long averageOriginalBitmapSize;
    1.36 +  public final long averageTransformedBitmapSize;
    1.37 +  public final int originalBitmapCount;
    1.38 +  public final int transformedBitmapCount;
    1.39 +
    1.40 +  public final long timeStamp;
    1.41 +
    1.42 +  public StatsSnapshot(int maxSize, int size, long cacheHits, long cacheMisses,
    1.43 +      long totalOriginalBitmapSize, long totalTransformedBitmapSize, long averageOriginalBitmapSize,
    1.44 +      long averageTransformedBitmapSize, int originalBitmapCount, int transformedBitmapCount,
    1.45 +      long timeStamp) {
    1.46 +    this.maxSize = maxSize;
    1.47 +    this.size = size;
    1.48 +    this.cacheHits = cacheHits;
    1.49 +    this.cacheMisses = cacheMisses;
    1.50 +    this.totalOriginalBitmapSize = totalOriginalBitmapSize;
    1.51 +    this.totalTransformedBitmapSize = totalTransformedBitmapSize;
    1.52 +    this.averageOriginalBitmapSize = averageOriginalBitmapSize;
    1.53 +    this.averageTransformedBitmapSize = averageTransformedBitmapSize;
    1.54 +    this.originalBitmapCount = originalBitmapCount;
    1.55 +    this.transformedBitmapCount = transformedBitmapCount;
    1.56 +    this.timeStamp = timeStamp;
    1.57 +  }
    1.58 +
    1.59 +  /** Prints out this {@link StatsSnapshot} into log. */
    1.60 +  public void dump() {
    1.61 +    StringWriter logWriter = new StringWriter();
    1.62 +    dump(new PrintWriter(logWriter));
    1.63 +    Log.i(TAG, logWriter.toString());
    1.64 +  }
    1.65 +
    1.66 +  /** Prints out this {@link StatsSnapshot} with the the provided {@link PrintWriter}. */
    1.67 +  public void dump(PrintWriter writer) {
    1.68 +    writer.println("===============BEGIN PICASSO STATS ===============");
    1.69 +    writer.println("Memory Cache Stats");
    1.70 +    writer.print("  Max Cache Size: ");
    1.71 +    writer.println(maxSize);
    1.72 +    writer.print("  Cache Size: ");
    1.73 +    writer.println(size);
    1.74 +    writer.print("  Cache % Full: ");
    1.75 +    writer.println((int) Math.ceil((float) size / maxSize * 100));
    1.76 +    writer.print("  Cache Hits: ");
    1.77 +    writer.println(cacheHits);
    1.78 +    writer.print("  Cache Misses: ");
    1.79 +    writer.println(cacheMisses);
    1.80 +    writer.println("Bitmap Stats");
    1.81 +    writer.print("  Total Bitmaps Decoded: ");
    1.82 +    writer.println(originalBitmapCount);
    1.83 +    writer.print("  Total Bitmap Size: ");
    1.84 +    writer.println(totalOriginalBitmapSize);
    1.85 +    writer.print("  Total Transformed Bitmaps: ");
    1.86 +    writer.println(transformedBitmapCount);
    1.87 +    writer.print("  Total Transformed Bitmap Size: ");
    1.88 +    writer.println(totalTransformedBitmapSize);
    1.89 +    writer.print("  Average Bitmap Size: ");
    1.90 +    writer.println(averageOriginalBitmapSize);
    1.91 +    writer.print("  Average Transformed Bitmap Size: ");
    1.92 +    writer.println(averageTransformedBitmapSize);
    1.93 +    writer.println("===============END PICASSO STATS ===============");
    1.94 +    writer.flush();
    1.95 +  }
    1.96 +
    1.97 +  @Override public String toString() {
    1.98 +    return "StatsSnapshot{"
    1.99 +        + "maxSize="
   1.100 +        + maxSize
   1.101 +        + ", size="
   1.102 +        + size
   1.103 +        + ", cacheHits="
   1.104 +        + cacheHits
   1.105 +        + ", cacheMisses="
   1.106 +        + cacheMisses
   1.107 +        + ", totalOriginalBitmapSize="
   1.108 +        + totalOriginalBitmapSize
   1.109 +        + ", totalTransformedBitmapSize="
   1.110 +        + totalTransformedBitmapSize
   1.111 +        + ", averageOriginalBitmapSize="
   1.112 +        + averageOriginalBitmapSize
   1.113 +        + ", averageTransformedBitmapSize="
   1.114 +        + averageTransformedBitmapSize
   1.115 +        + ", originalBitmapCount="
   1.116 +        + originalBitmapCount
   1.117 +        + ", transformedBitmapCount="
   1.118 +        + transformedBitmapCount
   1.119 +        + ", timeStamp="
   1.120 +        + timeStamp
   1.121 +        + '}';
   1.122 +  }
   1.123 +}
   1.124 \ No newline at end of file

mercurial