Skip to content

Instantly share code, notes, and snippets.

@wiyarmir
Created May 11, 2017 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wiyarmir/212f5a8a98efe525f14ffe2fe06b2346 to your computer and use it in GitHub Desktop.
Save wiyarmir/212f5a8a98efe525f14ffe2fe06b2346 to your computer and use it in GitHub Desktop.
Track your gradle build times
class BuildTracker {
private static final String STATS_SRV = ""
static void addBuildSpeedTracking(gradle) {
if (true) return
def startTime = System.currentTimeMillis()
gradle.buildFinished { buildResult ->
def time = System.currentTimeMillis() - startTime
def user = System.getProperty("user.name")
def branch = 'git rev-parse --abbrev-ref HEAD'.execute().text.trim()
def tasks = buildResult.gradle.startParameter.taskNames.collect { "\"$it\"" }.join(", ")
try {
def url = new URL(STATS_SRV)
HttpURLConnection conn = (HttpURLConnection) url.openConnection()
conn.requestMethod = "POST"
conn.setRequestProperty("Content-Type", "text/json")
conn.doOutput = true
def report = "{\"time\": $time, \"user\": \"$user\", \"branch\": \"$branch\", \"startTime\": $startTime, \"tasks\":[$tasks]}"
def out = new DataOutputStream(conn.outputStream)
out.write(report.bytes)
out.flush()
out.close()
conn.connect()
conn.responseCode
} catch (Exception e) {
println "Failed to send build stats $e"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment