-
Notifications
You must be signed in to change notification settings - Fork 0
ResultsAccumulator
The ResultsAccumulator
class is part of the AndroSpecter library and serves as a singleton utility class for accumulating results metrics.
The class offers a private constructor to enforce singleton usage:
-
private ResultsAccumulator()
: Constructs a newResultsAccumulator
object with an empty application name and an empty metrics map.
-
public static ResultsAccumulator v()
: Returns the singleton instance ofResultsAccumulator
. If the instance isnull
, a new instance is created.
-
public String getAppName()
: Returns the current application name. -
public void setAppName(String appName)
: Sets a new application name.
-
public void incrementMetric(String metric)
: Increments a specific metric by 1. If the metric does not exist, it is created and set to 1. -
public int getMetric(String metric)
: Returns the count of a specific metric, or 0 if the metric does not exist. -
public void setMetric(String metric, int value)
: Sets a specific metric to a certain value.
-
public void printVectorResults()
: Prints all the metrics in vector form. -
public String getVectorResults()
: Returns a string representation of the metrics in a vector form. -
public void printResults()
: Prints all the metrics in a readable format.
The ResultsAccumulator
class is primarily utilized in experiments for analyzing various aspects of an Android app, such as the number of methods in the call graph, the number of edges, and other specific metrics. The results can be formatted in two ways: a vector for machine processing and a human-readable format.
The vector format is particularly useful when you need to gather statistics across several apps, and then load this data into a dataframe for more in-depth analysis.
Here's an example of how to use the ResultsAccumulator
class to accumulate metrics and then obtain them in vector form:
ResultsAccumulator results = ResultsAccumulator.v();
results.setAppName("MyApp");
[...]
for [...] {
results.incrementMetric("MethodsInCallGraph", 1);
results.incrementMetric("Edges", 1);
}
String vectorResults = results.getVectorResults(); // Returns "MyApp,XX,YY"
This string can then be used as a row in a CSV file or other data storage, making it easy to load into a dataframe for statistical analysis.
The human-readable format provided by the printResults
method is intended for analysts to quickly understand the accumulated metrics, not for processing with a machine.
Here's an example of how to use this method:
ResultsAccumulator results = ResultsAccumulator.v();
results.setAppName("MyApp");
[...]
for [...] {
results.incrementMetric("MethodsInCallGraph", 1);
results.incrementMetric("Edges", 1);
}
results.printResults();
// Outputs:
// Results:
// - App name: MyApp
// - Number of MethodsInCallGraph: XX
// - Number of Edges: YY
This printout is beneficial for immediate review and interpretation by researchers or developers but is not designed for further processing by machine-learning or statistical tools.