From 907de4da7b2c620ea0503efd50294d2f4fbc111f Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 29 Jan 2017 22:37:25 +0100 Subject: [PATCH] execution profiler --- .../plugins/OpenAPSMA/OpenAPSMAPlugin.java | 5 +++++ .../java/info/nightscout/utils/Profiler.java | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 app/src/main/java/info/nightscout/utils/Profiler.java diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java index 47ef05e08f..181f43892f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java @@ -33,6 +33,7 @@ import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.client.data.DbLogger; import info.nightscout.client.data.NSProfile; import info.nightscout.utils.DateUtil; +import info.nightscout.utils.Profiler; import info.nightscout.utils.Round; import info.nightscout.utils.SafeParse; import info.nightscout.utils.ToastUtils; @@ -167,6 +168,7 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface { minBg = Round.roundTo(minBg, 0.1d); maxBg = Round.roundTo(maxBg, 0.1d); + Date start = new Date(); TreatmentsInterface treatments = MainApp.getConfigBuilder().getActiveTreatments(); TempBasalsInterface tempBasals = MainApp.getConfigBuilder().getActiveTempBasals(); treatments.updateTotalIOB(); @@ -179,6 +181,7 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface { TreatmentsPlugin.MealData mealData = treatments.getMealData(); maxIob = MainApp.getConfigBuilder().applyMaxIOBConstraints(maxIob); + Profiler.log(log, "MA data gathering", start); minBg = verifyHardLimits(minBg, "minBg", 72, 180); maxBg = verifyHardLimits(maxBg, "maxBg", 100, 270); @@ -193,7 +196,9 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface { if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return; if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return; + start = new Date(); determineBasalAdapterJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, pump, iobTotal, glucoseStatus, mealData); + Profiler.log(log, "MA calculation", start); DetermineBasalResult determineBasalResult = determineBasalAdapterJS.invoke(); diff --git a/app/src/main/java/info/nightscout/utils/Profiler.java b/app/src/main/java/info/nightscout/utils/Profiler.java new file mode 100644 index 0000000000..99093b238f --- /dev/null +++ b/app/src/main/java/info/nightscout/utils/Profiler.java @@ -0,0 +1,18 @@ +package info.nightscout.utils; + +import org.slf4j.Logger; + +import java.util.Date; + +/** + * Created by mike on 29.01.2017. + */ + +public class Profiler { + public Profiler(){} + + static public void log(Logger log, String function, Date start) { + long msec = new Date().getTime() - start.getTime(); + log.debug(">>> " + function + " <<< executed in " + msec + " miliseconds"); + } +}