Created
May 11, 2017 10:42
-
-
Save wiyarmir/212f5a8a98efe525f14ffe2fe06b2346 to your computer and use it in GitHub Desktop.
Track your gradle build times
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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