Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 47c186ca authored by Stefan Lafon's avatar Stefan Lafon
Browse files

More adjustments to the loadtest app.

- Add ability to set the replication factor by intent.
- Add shell script to automate the loadtesting.

Test: Loadtest app works.

Change-Id: I7263a3c23049f3ed20144e4e15b6a54ac5fddcc8
parent a7afd131
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@
                android:layout_weight="1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:maxLength="3"
                android:maxLength="4"
                android:text="@integer/replication_default"
                android:textSize="30dp"/>
        </LinearLayout>
@@ -108,7 +108,7 @@
                android:layout_weight="1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:maxLength="2"
                android:maxLength="4"
                android:text="@integer/burst_default"
                android:textSize="30dp"/>
        </LinearLayout>
+99 −0
Original line number Diff line number Diff line
#!/bin/sh
#
# Script that measures statsd's PSS under an increasing number of metrics.

# Globals.
pss=""
pid=""

# Starts the loadtest.
start_loadtest() {
    echo "Starting loadtest"
    adb shell am start -n com.android.statsd.loadtest/.LoadtestActivity --es "type" "start"
}

# Stops the loadtest.
stop_loadtest() {
    echo "Stopping loadtest"
    adb shell am start -n com.android.statsd.loadtest/.LoadtestActivity --es "type" "stop"
}

# Sets the metrics replication.
# Arguments:
#   $1: The replication factor.
set_replication() {
    adb shell am start -n com.android.statsd.loadtest/.LoadtestActivity --es "type" "set_replication" --ei "replication" "${1}"
    echo "Replication set to ${1}"
}

# Reads statsd's pid and PSS.
update_pid_and_pss() {
    # Command that reads the PSS for statsd. This also gives us its pid.
    get_mem=$(adb shell dumpsys meminfo |grep statsd)
    # Looks for statsd's pid.
    regex="([0-9,]+)K: statsd \(pid ([0-9]+)\).*"
    if [[ $get_mem =~ $regex ]]; then
        pss=$(echo "${BASH_REMATCH[1]}" | tr -d , | sed 's/\.//g')
        pid=$(echo "${BASH_REMATCH[2]}")
    else
        echo $cmd doesnt match $regex
    fi
}

# Kills statsd.
# Assumes the pid has been set.
kill_statsd() {
    echo "Killing statsd (pid ${pid})"
    adb shell kill -9 "${pid}"
}

# Main loop.
main() {
    start_time=$(date +%s)
    values=()
    stop_loadtest

    echo ""
    echo "********************* NEW LOADTEST ************************"
    update_pid_and_pss
    for replication in 1 2 4 8 16 32 64 128 256 512 1024 2048 4096
    do
        echo "**** Starting test at replication ${replication} ****"

        # (1) Restart statsd. This will ensure its state is empty.
        kill_statsd
        sleep 3 # wait a bit for it to restart
        update_pid_and_pss
        echo "Before the test, statsd's PSS is ${pss}"

        # (2) Set the replication.
        set_replication "${replication}"
        sleep 1 # wait a bit

        # (3) Start the loadtest.
        start_loadtest

        # (4) Wait several seconds, then read the PSS.
        sleep 100 && update_pid_and_pss
        echo "During the test, statsd's PSS is ${pss}"
        values+=(${pss})

        echo "Values: ${values[@]}"

        # (5) Stop loadtest.
        stop_loadtest
        sleep 2

        echo ""
    done

    end_time=$(date +%s)
    echo "Completed loadtest in $((${end_time} - ${start_time})) seconds."

    values_as_str=$(IFS=$'\n'; echo "${values[*]}")
    echo "The PSS values are:"
    echo "${values_as_str}"
    echo ""
}

main
+13 −2
Original line number Diff line number Diff line
@@ -22,18 +22,28 @@ import com.android.os.StatsLog;
import java.util.List;

public class DisplayProtoUtils {
    private static final int MAX_NUM_METRICS_TO_DISPLAY = 10;

    public static void displayLogReport(StringBuilder sb, StatsLog.ConfigMetricsReportList reports) {
        sb.append("ConfigKey: ");
        sb.append("******************** Report ********************\n");
        if (reports.hasConfigKey()) {
            sb.append("ConfigKey: ");
            com.android.os.StatsLog.ConfigMetricsReportList.ConfigKey key = reports.getConfigKey();
            sb.append("\tuid: ").append(key.getUid()).append(" id: ").append(key.getId())
                    .append("\n");
        }

        int numMetrics = 0;
        for (StatsLog.ConfigMetricsReport report : reports.getReportsList()) {
            sb.append("StatsLogReport size: ").append(report.getMetricsCount()).append("\n");
            for (StatsLog.StatsLogReport log : report.getMetricsList()) {
                sb.append("\n\n");
                numMetrics++;
                if (numMetrics > MAX_NUM_METRICS_TO_DISPLAY) {
                    sb.append("... output truncated\n");
                    sb.append("************************************************");
                    return;
                }
                sb.append("\n");
                sb.append("metric id: ").append(log.getMetricId()).append("\n");
                sb.append("start time:").append(getDateStr(log.getStartReportNanos())).append("\n");
                sb.append("end time:").append(getDateStr(log.getEndReportNanos())).append("\n");
@@ -65,6 +75,7 @@ public class DisplayProtoUtils {
                }
            }
        }
        sb.append("************************************************");
    }

    public static String getDateStr(long nanoSec) {
+23 −11
Original line number Diff line number Diff line
@@ -76,10 +76,12 @@ import java.util.Map;
 */
public class LoadtestActivity extends Activity implements AdapterView.OnItemSelectedListener {

    private static final String TAG = "StatsdLoadtest";
    private static final String TAG = "loadtest.LoadtestActivity";
    public static final String TYPE = "type";
    private static final String PUSH_ALARM = "push_alarm";
    public static final String PERF_ALARM = "perf_alarm";
    private static final String SET_REPLICATION = "set_replication";
    private static final String REPLICATION = "replication";
    private static final String START = "start";
    private static final String STOP = "stop";
    private static final Map<String, TimeUnit> TIME_UNIT_MAP = initializeTimeUnitMap();
@@ -231,7 +233,7 @@ public class LoadtestActivity extends Activity implements AdapterView.OnItemSele
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Log.d(TAG, "Starting loadtest");
        Log.d(TAG, "Starting loadtest Activity");

        setContentView(R.layout.activity_loadtest);
        mReportText = (TextView) findViewById(R.id.report_text);
@@ -289,6 +291,11 @@ public class LoadtestActivity extends Activity implements AdapterView.OnItemSele
            case PUSH_ALARM:
                onAlarm();
                break;
            case SET_REPLICATION:
                if (intent.hasExtra(REPLICATION)) {
                    setReplication(intent.getIntExtra(REPLICATION, 0));
                }
                break;
            case START:
                startLoadtest();
                break;
@@ -340,6 +347,10 @@ public class LoadtestActivity extends Activity implements AdapterView.OnItemSele
                ConfigMetricsReportList reports = null;
                try {
                    reports = ConfigMetricsReportList.parseFrom(data);
                    Log.d(TAG, "Num reports: " + reports.getReportsCount());
                    StringBuilder sb = new StringBuilder();
                    DisplayProtoUtils.displayLogReport(sb, reports);
                    Log.d(TAG, sb.toString());
                } catch (com.google.protobuf.InvalidProtocolBufferException e) {
                    Log.d(TAG, "Invalid data");
                }
@@ -411,9 +422,6 @@ public class LoadtestActivity extends Activity implements AdapterView.OnItemSele
        // Prepare to push a sequence of atoms to logd.
        mPusher = new SequencePusher(mBurst, mPlacebo);

        // Force a data flush by requesting data.
        getData();

        // Create a config and push it to statsd.
        if (!setConfig(mFactory.getConfig(mReplication, mBucket, mPlacebo,
                mIncludeCountMetric, mIncludeDurationMetric, mIncludeEventMetric,
@@ -464,6 +472,9 @@ public class LoadtestActivity extends Activity implements AdapterView.OnItemSele
            mPerfData = null;
        }

        // Obtain the latest data and display it.
        getData();

        long elapsedTimeMins = (long) Math.floor(
            (SystemClock.elapsedRealtime() - mStartedTimeMillis) / 60 / 1000);
        mReportText.setText("Loadtest ended. Elapsed time = " + elapsedTimeMins + " min(s)");
@@ -541,7 +552,10 @@ public class LoadtestActivity extends Activity implements AdapterView.OnItemSele
    }

    private synchronized void setReplication(int replication) {
        mReplication = replication;
        if (mStarted) {
          return;
        }
        mReplicationText.setText("" + replication);
    }

    private synchronized void setPeriodSecs(long periodSecs) {
@@ -573,7 +587,7 @@ public class LoadtestActivity extends Activity implements AdapterView.OnItemSele
    private void initBurst() {
        mBurst = getResources().getInteger(R.integer.burst_default);
        mBurstText = (EditText) findViewById(R.id.burst);
        mBurstText.addTextChangedListener(new NumericalWatcher(mBurstText, 0, 50) {
        mBurstText.addTextChangedListener(new NumericalWatcher(mBurstText, 0, 1000) {
            @Override
            public void onNewValue(int newValue) {
                setBurst(newValue);
@@ -585,10 +599,10 @@ public class LoadtestActivity extends Activity implements AdapterView.OnItemSele
    private void initReplication() {
        mReplication = getResources().getInteger(R.integer.replication_default);
        mReplicationText = (EditText) findViewById(R.id.replication);
        mReplicationText.addTextChangedListener(new NumericalWatcher(mReplicationText, 1, 100) {
        mReplicationText.addTextChangedListener(new NumericalWatcher(mReplicationText, 1, 4096) {
            @Override
            public void onNewValue(int newValue) {
                setReplication(newValue);
                mReplication = newValue;
            }
        });
        handleFocus(mReplicationText);
@@ -606,9 +620,7 @@ public class LoadtestActivity extends Activity implements AdapterView.OnItemSele
        mBucketSpinner.setOnItemSelectedListener(this);

        for (String label : TIME_UNIT_MAP.keySet()) {
          Log.d(TAG, "EVALUATE " + label + " VS " + defaultValue);
          if (defaultValue.equals(TIME_UNIT_MAP.get(label).toString())) {
                Log.d(TAG, " FOUND IT");
                mBucketSpinner.setSelection(dataAdapter.getPosition(label));
            }
        }