All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.jodamob.android.tracing.TracedRetrofitProfiler Maven / Gradle / Ivy

The newest version!
package de.jodamob.android.tracing;

import java.io.IOException;
import java.util.List;

import retrofit.Profiler;
import retrofit.client.Client;
import retrofit.client.Header;
import retrofit.client.Request;
import retrofit.client.Response;

public class TracedRetrofitProfiler implements Profiler{

    private final Tracer tracer;

    public TracedRetrofitProfiler(Tracer tracer) {
        this.tracer = tracer;
    }

    private long getTime() {
        return System.currentTimeMillis();
    }

    @Override
    public Long beforeCall() {
        return getTime();
    }

    @Override
    public void afterCall(RequestInformation requestInfo, long elapsedTime, int statusCode, Long beforeCallData) {
        tracer.trace(getUrl(requestInfo), statusCode, beforeCallData, beforeCallData+elapsedTime, requestInfo.getContentLength(), 0);
    }

    private String getUrl(RequestInformation requestInfo) {
        String baseUrl = requestInfo.getBaseUrl();
        String relativePath = requestInfo.getRelativePath();
        if ((baseUrl.endsWith("/")) || (relativePath.startsWith("/"))) {
            return baseUrl + relativePath;
        }
        return baseUrl + "/" + relativePath;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy