Skip to content

ResultsAccumulator

Jordan Samhi edited this page Aug 22, 2023 · 2 revisions

ResultsAccumulator 🗄️

The ResultsAccumulator class is part of the AndroSpecter library and serves as a singleton utility class for accumulating results metrics.

Class Definition

Constructors

The class offers a private constructor to enforce singleton usage:

  • private ResultsAccumulator(): Constructs a new ResultsAccumulator object with an empty application name and an empty metrics map.

Singleton Access Method

  • public static ResultsAccumulator v(): Returns the singleton instance of ResultsAccumulator. If the instance is null, a new instance is created.

Getters and Setters

  • public String getAppName(): Returns the current application name.
  • public void setAppName(String appName): Sets a new application name.

Metric Management Methods

  • 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.

Result Printing Methods

  • 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.

Usage

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.

Vector Example

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.

Human-Readable Example

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.