Android Picasso - How to Get Hits and Cache Downloads Statistics

I am currently using Picasso 2.0.1 (also tried 1.0.2 before) and get bitmaps from images on the web.

Everything works fine, I saw improvements in image loading ... at least it seems faster.

My question is, how can I get statistics from the actions performed by PICASSO? I wanted to know if the picture was received from the cache or uploaded ...

I am trying to get information from com.squareup.picasso.StatsSnapshot, however it does not seem to be updated ... or I am not using it correctly.

Picasso pi = Picasso.with(getActivity().getApplicationContext()); Bitmap bitmap = pi.load(url.toString()).get(); Log.d(this.getClass().getSimpleName(),"Cache hits:" + pi.getSnapshot().cacheHits + " Cache misses:" + pi.getSnapshot().cacheMisses); 

adding a log before and / or after a load call always returns the same result

Cache hits: 0 Cached misses: 0

What am I doing wrong or how can I get this information?

Thanks in advance!

Mark

+4
source share
4 answers

To get the color triangle that David Hewitt describes, you really need to use setIndicatorsEnabled like this

 Picasso.with(mContext).setIndicatorsEnabled(true); 

You can get statistics in your logs for Picasso using setLoggingEnabled so

 Picasso.with(mContext).setLoggingEnabled(true); 

You can search the magazine with the Picasso filter and see where Picasso receives the image and how long it takes. Very comfortably!

+5
source

According to the website here: http://square.imtqy.com/picasso/

You can do setDebugging(true) and it will place the colored triangles in the corner or each image that indicates whether they have been downloaded from the Internet, disk or memory. I cannot find any specific link to the functions that you used on the website, but it can satisfy your needs.

0
source

You can call this from onStop () or onPause of your activity or fragment

 StatsSnapshot picassoStats = Picasso.with(context).getSnapshot(); Log.d("Picasso stats ", picasspStats.toString()); 

then from the logarithm of Android, select verbose and Picasso filter.

You will receive a log of the following form:

 Picasso stats: [main] StatsSnapshot{maxSize=76695844, size=75737296, cacheHits=656, cacheMisses=1091, downloadCount=8, totalDownloadSize=213376, averageDownloadSize=26672, totalOriginalBitmapSize=437547196, totalTransformedBitmapSize=609434304, averageOriginalBitmapSize=527801, averageTransformedBitmapSize=735143, originalBitmapCount=829, transformedBitmapCount=826, timeStamp=1484426664382} 
0
source

'get ()' is synchronous and skips the cache. Use one of the load () methods to take full advantage of Picasso.

-one
source

Source: https://habr.com/ru/post/1500941/


All Articles