michael@0: /* michael@0: * Copyright (C) 2013 Square, Inc. michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: package com.squareup.picasso; michael@0: michael@0: import android.util.Log; michael@0: import java.io.PrintWriter; michael@0: import java.io.StringWriter; michael@0: michael@0: /** Represents all stats for a {@link Picasso} instance at a single point in time. */ michael@0: public class StatsSnapshot { michael@0: private static final String TAG = "Picasso"; michael@0: michael@0: public final int maxSize; michael@0: public final int size; michael@0: public final long cacheHits; michael@0: public final long cacheMisses; michael@0: public final long totalOriginalBitmapSize; michael@0: public final long totalTransformedBitmapSize; michael@0: public final long averageOriginalBitmapSize; michael@0: public final long averageTransformedBitmapSize; michael@0: public final int originalBitmapCount; michael@0: public final int transformedBitmapCount; michael@0: michael@0: public final long timeStamp; michael@0: michael@0: public StatsSnapshot(int maxSize, int size, long cacheHits, long cacheMisses, michael@0: long totalOriginalBitmapSize, long totalTransformedBitmapSize, long averageOriginalBitmapSize, michael@0: long averageTransformedBitmapSize, int originalBitmapCount, int transformedBitmapCount, michael@0: long timeStamp) { michael@0: this.maxSize = maxSize; michael@0: this.size = size; michael@0: this.cacheHits = cacheHits; michael@0: this.cacheMisses = cacheMisses; michael@0: this.totalOriginalBitmapSize = totalOriginalBitmapSize; michael@0: this.totalTransformedBitmapSize = totalTransformedBitmapSize; michael@0: this.averageOriginalBitmapSize = averageOriginalBitmapSize; michael@0: this.averageTransformedBitmapSize = averageTransformedBitmapSize; michael@0: this.originalBitmapCount = originalBitmapCount; michael@0: this.transformedBitmapCount = transformedBitmapCount; michael@0: this.timeStamp = timeStamp; michael@0: } michael@0: michael@0: /** Prints out this {@link StatsSnapshot} into log. */ michael@0: public void dump() { michael@0: StringWriter logWriter = new StringWriter(); michael@0: dump(new PrintWriter(logWriter)); michael@0: Log.i(TAG, logWriter.toString()); michael@0: } michael@0: michael@0: /** Prints out this {@link StatsSnapshot} with the the provided {@link PrintWriter}. */ michael@0: public void dump(PrintWriter writer) { michael@0: writer.println("===============BEGIN PICASSO STATS ==============="); michael@0: writer.println("Memory Cache Stats"); michael@0: writer.print(" Max Cache Size: "); michael@0: writer.println(maxSize); michael@0: writer.print(" Cache Size: "); michael@0: writer.println(size); michael@0: writer.print(" Cache % Full: "); michael@0: writer.println((int) Math.ceil((float) size / maxSize * 100)); michael@0: writer.print(" Cache Hits: "); michael@0: writer.println(cacheHits); michael@0: writer.print(" Cache Misses: "); michael@0: writer.println(cacheMisses); michael@0: writer.println("Bitmap Stats"); michael@0: writer.print(" Total Bitmaps Decoded: "); michael@0: writer.println(originalBitmapCount); michael@0: writer.print(" Total Bitmap Size: "); michael@0: writer.println(totalOriginalBitmapSize); michael@0: writer.print(" Total Transformed Bitmaps: "); michael@0: writer.println(transformedBitmapCount); michael@0: writer.print(" Total Transformed Bitmap Size: "); michael@0: writer.println(totalTransformedBitmapSize); michael@0: writer.print(" Average Bitmap Size: "); michael@0: writer.println(averageOriginalBitmapSize); michael@0: writer.print(" Average Transformed Bitmap Size: "); michael@0: writer.println(averageTransformedBitmapSize); michael@0: writer.println("===============END PICASSO STATS ==============="); michael@0: writer.flush(); michael@0: } michael@0: michael@0: @Override public String toString() { michael@0: return "StatsSnapshot{" michael@0: + "maxSize=" michael@0: + maxSize michael@0: + ", size=" michael@0: + size michael@0: + ", cacheHits=" michael@0: + cacheHits michael@0: + ", cacheMisses=" michael@0: + cacheMisses michael@0: + ", totalOriginalBitmapSize=" michael@0: + totalOriginalBitmapSize michael@0: + ", totalTransformedBitmapSize=" michael@0: + totalTransformedBitmapSize michael@0: + ", averageOriginalBitmapSize=" michael@0: + averageOriginalBitmapSize michael@0: + ", averageTransformedBitmapSize=" michael@0: + averageTransformedBitmapSize michael@0: + ", originalBitmapCount=" michael@0: + originalBitmapCount michael@0: + ", transformedBitmapCount=" michael@0: + transformedBitmapCount michael@0: + ", timeStamp=" michael@0: + timeStamp michael@0: + '}'; michael@0: } michael@0: }