Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoCouto committed Mar 10, 2015
0 parents commit bff875e
Show file tree
Hide file tree
Showing 86 changed files with 5,381 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
GreenDroid
==========

A tool to detect energy leaks in Android applications

# What the tool does

**GreenDroid** tool can be used to determine the methods of an application that are must likely associated with anomalous energy consumptions. It does that by running a set of tests (typical **Android** tests, written using the **Android** test framework) and collecting the information about the methods invoked, the time each test spent and an estimate of the energy consumed per test.

Its workflow is the following:

1. Receives the path to the application project and to the test project;
2. Intruments the code of both the projects in order to enable tracing and power consumption measuring;
3. Uses [ant](http://ant.apache.org/) to build the .apk files of both projects;
4. Installs them on the connected device;
5. Runs the tests of the application;
6. When tests are done, it pulls the information out off the device;
7. Runs an algorithm to detect methods associated with anomalous energy consumption;
8. Classify each method analyzed, and generate the result to a JSON file;

The JSON file contains data to be displayed in a sunburst diagram. That diagram can be found [here](http://bl.ocks.org/mbostock/4348373), and a version edited by us can be found [here](https://github.com/MarcoCouto/GreenDroid/tree/master/auxiliar/sunburst/)

# Current status

The **GreenDroid** tool is currently developed in a way that the input needed (application and test project) are set inside the application code.
We intend to soon include a property/configuration file, where are the variables can be previously set.


1 change: 1 addition & 0 deletions auxiliar/sunburst/authenticator.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
me":"GreenAnalysis","factor":0,"children":[{"name":"com.google.android.apps.authenticator","factor":100,"children":[{"name":"AccountDb","factor":100,"children":[{"name":"getEnum","size":1,"factor":100},{"name":"openDatabase","size":1,"factor":100},{"name":"getAccountDbOpenFailedErrorString","size":1,"factor":1},{"name":"close","size":1,"factor":100},{"name":"listTableColumnNamesLowerCase","size":1,"factor":100},{"name":"deleteAllData","size":1,"factor":100},{"name":"nameExists","size":1,"factor":100},{"name":"getSecret","size":1,"factor":100},{"name":"getSigningOracle","size":1,"factor":100},{"name":"decodeKey","size":1,"factor":100},{"name":"getCounter","size":1,"factor":100},{"name":"incrementCounter","size":1,"factor":100},{"name":"getType","size":1,"factor":100},{"name":"setType","size":1,"factor":100},{"name":"isGoogleAccount","size":1,"factor":100},{"name":"findGoogleCorpAccount","size":1,"factor":1},{"name":"whereClause","size":1,"factor":100},{"name":"delete","size":1,"factor":100},{"name":"update","size":1,"factor":100},{"name":"getNames","size":1,"factor":100},{"name":"getAccount","size":1,"factor":100},{"name":"cursorIsEmpty","size":1,"factor":100},{"name":"tryCloseCursor","size":1,"factor":100}]},{"name":"AddOtherAccountActivity","factor":100,"children":[{"name":"onCreate","size":1,"factor":100},{"name":"manuallyEnterAccountDetails","size":1,"factor":100},{"name":"scanBarcode","size":1,"factor":100}]},{"name":"AuthenticatorActivity","factor":100,"children":[{"name":"onCreate","size":1,"factor":100},{"name":"handleIntent","size":1,"factor":100},{"name":"onSaveInstanceState","size":1,"factor":1},{"name":"onRetainNonConfigurationInstance","size":1,"factor":1},{"name":"onNewIntent","size":1,"factor":1},{"name":"onStart","size":1,"factor":100},{"name":"onResume","size":1,"factor":100},{"name":"onStop","size":1,"factor":100},{"name":"updateCodesAndStartTotpCountdownTask","size":1,"factor":100},{"name":"stopTotpCountdownTask","size":1,"factor":100},{"name":"refreshUserList","size":1,"factor":100},{"name":"setTotpCountdownPhase","size":1,"factor":100},{"name":"setTotpCountdownPhaseFromTimeTillNextValue","size":1,"factor":100},{"name":"refreshVerificationCodes","size":1,"factor":100},{"name":"updateCountdownIndicators","size":1,"factor":100},{"name":"computeAndDisplayPin","size":1,"factor":100},{"name":"parseSecret","size":1,"factor":100},{"name":"validateAndGetUserInPath","size":1,"factor":100},{"name":"saveSecretAndRefreshUserList","size":1,"factor":100},{"name":"saveSecret","size":1,"factor":100},{"name":"idToEmail","size":1,"factor":100},{"name":"onCreateContextMenu","size":1,"factor":100},{"name":"onContextItemSelected","size":1,"factor":100},{"name":"getRenameClickListener","size":1,"factor":100},{"name":"onCreateOptionsMenu","size":1,"factor":100},{"name":"onMenuItemSelected","size":1,"factor":100},{"name":"onActivityResult","size":1,"factor":100},{"name":"displayHowItWorksInstructions","size":1,"factor":100},{"name":"addAccount","size":1,"factor":100},{"name":"scanBarcode","size":1,"factor":100},{"name":"getLaunchIntentActionScanBarcode","size":1,"factor":100},{"name":"showSettings","size":1,"factor":100},{"name":"interpretScanResult","size":1,"factor":100},{"name":"onCreateDialog","size":1,"factor":100},{"name":"markDialogAsResultOfSaveKeyIntent","size":1,"factor":100},{"name":"onSaveKeyIntentConfirmationPromptDismissed","size":1,"factor":100},{"name":"createOkAlertDialog","size":1,"factor":100},{"name":"onClick","size":1,"factor":100},{"name":"findAccountPositionInList","size":1,"factor":100},{"name":"getView","size":1,"factor":100},{"name":"importDataFromOldAppIfNecessary","size":1,"factor":100}]},{"name":"AuthenticatorApplication","factor":1,"children":[{"name":"onCreate","size":1,"factor":1},{"name":"onTerminate","size":1,"factor":1}]},{"name":"Base32String","factor":100,"children":[{"name":"getInstance","size":1,"factor":100},{"name":"decode","size":1,"factor":100},{"name":"decodeInternal","size":1,"factor":100},{"name":"encode","size":1,"factor":100},{"name":"encodeInternal","size":1,"factor":100},{"name":"clone","size":1,"factor":1}]},{"name":"CheckCodeActivity","factor":100,"children":[{"name":"onCreate","size":1,"factor":100},{"name":"getCheckCode","size":1,"factor":100}]},{"name":"CountdownIndicator","factor":100,"children":[{"name":"onDraw","size":1,"factor":100},{"name":"setPhase","size":1,"factor":100}]},{"name":"EnterKeyActivity","factor":100,"children":[{"name":"onCreate","size":1,"factor":100},{"name":"getEnteredKey","size":1,"factor":100},{"name":"validateKeyAndUpdateStatus","size":1,"factor":100},{"name":"onRightButtonPressed","size":1,"factor":100},{"name":"afterTextChanged","size":1,"factor":100}]},{"name":"FileUtilities","factor":100,"children":[{"name":"restrictAccessToOwnerOnly","size":1,"factor":100},{"name":"getStat","size":1,"factor":100},{"name":"getFileStatusInt","size":1,"factor":100},{"name":"getFileStatusLong","size":1,"factor":100},{"name":"toString","size":1,"factor":100}]},{"name":"HexEncoding","factor":1,"children":[{"name":"encode","size":1,"factor":1},{"name":"decode","size":1,"factor":1},{"name":"getHexadecimalDigitValue","size":1,"factor":1}]},{"name":"MarketBuildOptionalFeatures","factor":1,"children":[{"name":"interpretScanResult","size":1,"factor":100},{"name":"getSharedPreferencesForDataImportFromOldApp","size":1,"factor":1},{"name":"appendDataImportLearnMoreLink","size":1,"factor":100},{"name":"createOtpSource","size":1,"factor":100},{"name":"onAuthenticatorActivityGetNextOtpFailed","size":1,"factor":1},{"name":"onAuthenticatorActivityCreateDialog","size":1,"factor":1},{"name":"onAuthenticatorActivityAddAccount","size":1,"factor":100}]},{"name":"OtpProvider","factor":100,"children":[{"name":"enumerateAccounts","size":1,"factor":100},{"name":"getNextCode","size":1,"factor":100},{"name":"respondToChallenge","size":1,"factor":100},{"name":"getTotpCounter","size":1,"factor":100},{"name":"getTotpClock","size":1,"factor":100},{"name":"getCurrentCode","size":1,"factor":100},{"name":"computePin","size":1,"factor":100},{"name":"getSecret","size":1,"factor":100}]},{"name":"PasscodeGenerator","factor":100,"children":[{"name":"sign","size":1,"factor":100},{"name":"padOutput","size":1,"factor":100},{"name":"generateResponseCode","size":1,"factor":100},{"name":"hashToInt","size":1,"factor":100},{"name":"verifyResponseCode","size":1,"factor":1},{"name":"verifyTimeoutCode","size":1,"factor":1}]},{"name":"Preconditions","factor":1,"children":[{"name":"checkNotNull","size":1,"factor":1},{"name":"checkArgument","size":1,"factor":1},{"name":"checkState","size":1,"factor":1}]},{"name":"RunOnThisLooperThreadExecutor","factor":1,"children":[{"name":"execute","size":1,"factor":1}]},{"name":"SettingsAboutActivity","factor":100,"children":[{"name":"onCreate","size":1,"factor":100}]},{"name":"SettingsActivity","factor":1,"children":[{"name":"onCreate","size":1,"factor":1}]},{"name":"TotpClock","factor":100,"children":[{"name":"currentTimeMillis","size":1,"factor":100},{"name":"getTimeCorrectionMinutes","size":1,"factor":100},{"name":"setTimeCorrectionMinutes","size":1,"factor":100}]},{"name":"TotpCountdownTask","factor":100,"children":[{"name":"setListener","size":1,"factor":100},{"name":"startAndNotifyListener","size":1,"factor":100},{"name":"stop","size":1,"factor":100},{"name":"run","size":1,"factor":100},{"name":"scheduleNextInvocation","size":1,"factor":100},{"name":"fireTotpCountdown","size":1,"factor":100},{"name":"fireTotpCounterValueChanged","size":1,"factor":100},{"name":"getCounterValue","size":1,"factor":100},{"name":"getTimeTillNextCounterValue","size":1,"factor":100},{"name":"getCounterValueAge","size":1,"factor":100}]},{"name":"TotpCounter","factor":100,"children":[{"name":"getTimeStep","size":1,"factor":100},{"name":"getStartTime","size":1,"factor":1},{"name":"getValueAtTime","size":1,"factor":100},{"name":"getValueStartTime","size":1,"factor":100},{"name":"assertValidTime","size":1,"factor":100}]},{"name":"UserRowView","factor":1,"children":[{"name":"dispatchPopulateAccessibilityEvent","size":1,"factor":1}]},{"name":"Utilities","factor":100,"children":[{"name":"millisToSeconds","size":1,"factor":100},{"name":"secondsToMillis","size":1,"factor":100},{"name":"setWebViewHtml","size":1,"factor":100}]}]},{"name":"com.google.android.apps.authenticator.dataimport","factor":1,"children":[{"name":"ExportServiceBasedImportController","factor":1,"children":[{"name":"start","size":1,"factor":1},{"name":"onServiceConnected","size":1,"factor":1},{"name":"getOldAppVersionCode","size":1,"factor":1},{"name":"notifyListenerDataImported","size":1,"factor":1},{"name":"notifyListenerUninstallOldAppSuggested","size":1,"factor":1},{"name":"notifyListenerFinished","size":1,"factor":1}]},{"name":"Importer","factor":100,"children":[{"name":"importFromBundle","size":1,"factor":100},{"name":"importAccountDbFromBundle","size":1,"factor":100},{"name":"compare","size":1,"factor":100},{"name":"tryImportPreferencesFromBundle","size":1,"factor":100},{"name":"importPreferencesFromBundle","size":1,"factor":100}]}]},{"name":"com.google.android.apps.authenticator.howitworks","factor":100,"children":[{"name":"IntroEnterCodeActivity","factor":100,"children":[{"name":"onCreate","size":1,"factor":100},{"name":"onRightButtonPressed","size":1,"factor":100}]},{"name":"IntroEnterPasswordActivity","factor":100,"children":[{"name":"onCreate","size":1,"factor":100},{"name":"onRightButtonPressed","size":1,"factor":100}]},{"name":"IntroVerifyDeviceActivity","factor":100,"children":[{"name":"onCreate","size":1,"factor":100},{"name":"onRightButtonPressed","size":1,"factor":100}]}]},{"name":"com.google.android.apps.authenticator.testability","factor":100,"children":[{"name":"DependencyInjector","factor":100,"children":[{"name":"getContext","size":1,"factor":100},{"name":"setAccountDb","size":1,"factor":100},{"name":"getAccountDb","size":1,"factor":100},{"name":"setOtpProvider","size":1,"factor":1},{"name":"getOtpProvider","size":1,"factor":100},{"name":"setTotpClock","size":1,"factor":100},{"name":"getTotpClock","size":1,"factor":100},{"name":"setPackageManager","size":1,"factor":1},{"name":"getPackageManager","size":1,"factor":1},{"name":"setStartActivityListener","size":1,"factor":100},{"name":"getStartActivityListener","size":1,"factor":100},{"name":"setDataImportController","size":1,"factor":100},{"name":"getDataImportController","size":1,"factor":100},{"name":"setHttpClient","size":1,"factor":1},{"name":"getHttpClient","size":1,"factor":1},{"name":"setOptionalFeatures","size":1,"factor":1},{"name":"getOptionalFeatures","size":1,"factor":100},{"name":"configureForProductionIfNotConfigured","size":1,"factor":1},{"name":"resetForIntegrationTesting","size":1,"factor":100},{"name":"close","size":1,"factor":100}]},{"name":"HttpClientFactory","factor":100,"children":[{"name":"createHttpClient","size":1,"factor":100},{"name":"configureHttpClient","size":1,"factor":100},{"name":"createHttpClientForFroyoAndHigher","size":1,"factor":100},{"name":"createHttpClientForEclair","size":1,"factor":1}]},{"name":"SharedPreferencesRenamingDelegatingContext","factor":100,"children":[{"name":"getSharedPreferences","size":1,"factor":100}]},{"name":"TestableActivity","factor":100,"children":[{"name":"startActivity","size":1,"factor":100},{"name":"startActivityForResult","size":1,"factor":100}]},{"name":"TestablePreferenceActivity","factor":1,"children":[{"name":"startActivity","size":1,"factor":100},{"name":"startActivityForResult","size":1,"factor":1}]}]},{"name":"com.google.android.apps.authenticator.timesync","factor":1,"children":[{"name":"AboutActivity","factor":1,"children":[{"name":"onCreate","size":1,"factor":1},{"name":"onMiddleButtonPressed","size":1,"factor":1}]},{"name":"NetworkTimeProvider","factor":1,"children":[{"name":"getNetworkTime","size":1,"factor":1}]},{"name":"SettingsTimeCorrectionActivity","factor":1,"children":[{"name":"onCreate","size":1,"factor":1}]},{"name":"SyncNowActivity","factor":1,"children":[{"name":"onCreate","size":1,"factor":1},{"name":"onStop","size":1,"factor":1},{"name":"onRetainNonConfigurationInstance","size":1,"factor":1},{"name":"onBackPressed","size":1,"factor":1},{"name":"onStarted","size":1,"factor":1},{"name":"onDone","size":1,"factor":1},{"name":"showInProgressDialog","size":1,"factor":1},{"name":"dismissInProgressDialog","size":1,"factor":1}]},{"name":"SyncNowController","factor":1,"children":[{"name":"attach","size":1,"factor":1},{"name":"detach","size":1,"factor":1},{"name":"abort","size":1,"factor":1},{"name":"start","size":1,"factor":1},{"name":"onCancelledByUser","size":1,"factor":1},{"name":"onNewTimeCorrectionObtained","size":1,"factor":1},{"name":"finish","size":1,"factor":1},{"name":"runBackgroundSyncAndPostResult","size":1,"factor":1}]}]},{"name":"com.google.android.apps.authenticator.wizard","factor":100,"children":[{"name":"WizardPageActivity","factor":100,"children":[{"name":"onCreate","size":1,"factor":100},{"name":"onSaveInstanceState","size":1,"factor":1},{"name":"getWizardState","size":1,"factor":100},{"name":"setWizardState","size":1,"factor":1},{"name":"setPageContentView","size":1,"factor":100},{"name":"setButtonBarModeMiddleButtonOnly","size":1,"factor":1},{"name":"onLeftButtonPressed","size":1,"factor":100},{"name":"startPageActivity","size":1,"factor":100},{"name":"startPageActivityForResult","size":1,"factor":1},{"name":"getWizardStateFromIntent","size":1,"factor":100},{"name":"setTextViewHtmlFromResource","size":1,"factor":100},{"name":"setTextViewHtml","size":1,"factor":1},{"name":"setButtonBarType","size":1,"factor":100},{"name":"showInlineProgress","size":1,"factor":1},{"name":"dismissInlineProgress","size":1,"factor":1},{"name":"exitWizard","size":1,"factor":100}]}]}]}
110 changes: 110 additions & 0 deletions auxiliar/sunburst/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
CTYPE html>
<meta charset="utf-8">
<style>

path {
stroke: #fff;
fill-rule: evenodd;
}

</style>
<script src="d3.v3.min.js"></script>
<script src="jquery-2.1.0.min.js"></script>
<body>
<script>

var width = 960,
height = 600,
radius = Math.min(width, height) / 2;

var x = d3.scale.linear()
.range([0, 2 * Math.PI]);

var y = d3.scale.sqrt()
.range([0, radius]);


// Spectrum colors.
var colors = [
"#70ad47",
"#fbf038",
"#df0c0c"
];

//var color = d3.scale.category20c();
function getColor(x){
var arrayLength = colors.length;
var def = "#68fd88";
var ret = def;
var op = (parseInt(x-1)/100);
for (var i = 0; i < arrayLength && ret == def ; i++) {
if(i >= op){
ret = colors[i];
}
}
return ret;
}

var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height+30)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + (height / 2 + 10) + ")");

var partition = d3.layout.partition()
.value(function(d) { return d.size; });

var arc = d3.svg.arc()
.startAngle(function(d) { return Math.max(0, Math.min(2 * Math.PI, x(d.x))); })
.endAngle(function(d) { return Math.max(0, Math.min(2 * Math.PI, x(d.x + d.dx))); })
.innerRadius(function(d) { return Math.max(0, y(d.y)); })
.outerRadius(function(d) { return Math.max(0, y(d.y + d.dy)); });

//d3.json("apptracker.json", function(error, root) {
//d3.json("bench.json", function(error, root) {
//d3.json("chordreader.json", function(error, root) {
//d3.json("connectbot.json", function(error, root) {
//d3.json("logcat.json", function(error, root) {
//d3.json("newsblur.json", function(error, root) {
d3.json("authenticator.json", function(error, root) {
var path = svg.selectAll("path")
.data(partition.nodes(root))
.enter().append("path")
.attr("d", arc)
.style("fill", function(d) { return getColor(d.factor ? d.factor : d.size); })
.on("click", click);

function click(d) {
path.transition()
.duration(750)
.attrTween("d", arcTween(d));
//HERE
if(d.factor){
$('#class').text(d.name);
}else{
$('#method').text(d.name);
}
//
}
});

d3.select(self.frameElement).style("height", height + "px");

// Interpolate the scales!
function arcTween(d) {
var xd = d3.interpolate(x.domain(), [d.x, d.x + d.dx]),
yd = d3.interpolate(y.domain(), [d.y, 1]),
yr = d3.interpolate(y.range(), [d.y ? 20 : 0, radius]);
return function(d, i) {
return i
? function(t) { return arc(d); }
: function(t) { x.domain(xd(t)); y.domain(yd(t)).range(yr(t)); return arc(d); };
};
}

</script>
<br/>
<span id="method"></span><br/>
<span id="class"></span>
</body>

Loading

0 comments on commit bff875e

Please sign in to comment.