Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

finding volley requests response time android

I have been using volley for making rest calls to server. I am trying to send the response time for each requests to Google analytic to analyze the server latency, in volley jsonobject request is there any way to finding the response time for each requests. If volley doesn't provide this function how can I calculate the response time for each requests?.

like image 880
Dinesh Kannan Avatar asked Apr 01 '15 08:04

Dinesh Kannan


1 Answers

You'll need to calculate this yourself. Here's a quick way to see how long it takes for the response to arrive:

private long mRequestStartTime;

public void performRequest()
{
    mRequestStartTime = System.currentTimeMillis(); // set the request start time just before you send the request.

    JsonObjectRequest request = new JsonObjectRequest(URL, PARAMS, 
        new Response.Listener<JSONObject>() 
        {
            @Override
            public void onResponse(JSONObject response) 
            {
                // calculate the duration in milliseconds
                long totalRequestTime = System.currentTimeMillis() - mRequestStartTime;
            }
        },
        new Response.ErrorListener() 
        {
            @Override
            public void onErrorResponse(VolleyError error) 
            {
                long totalRequestTime = System.currentTimeMillis() - mRequestStartTime;
            }
        });

    requestQueue.add(request);
}
like image 69
Gil Moshayof Avatar answered Sep 24 '22 15:09

Gil Moshayof