/** * Fetch the values stored in a profile based on a start and end timestamp. * * @param clazz The type of values stored by the profile. * @param profile The name of the profile. * @param entity The name of the entity. * @param groups The groups used to sort the profile data. * @param start The start time in epoch milliseconds. * @param end The end time in epoch milliseconds. * @param defaultValue The default value to specify. If empty, the result will be sparse. * @param <T> The type of values stored by the profile. * @return A list of values. */ @Override public <T> List<ProfileMeasurement> fetch(Class<T> clazz, String profile, String entity, List<Object> groups, long start, long end, Optional<T> defaultValue) { List<ProfilePeriod> periods = ProfilePeriod.visitPeriods( start, end, periodDurationMillis, TimeUnit.MILLISECONDS, Optional.empty(), period -> period); return fetch(clazz, profile, entity, groups, periods, defaultValue); }
/** * Builds a list of row keys necessary to retrieve profile measurements over * a time horizon. * * @param profile The name of the profile. * @param entity The name of the entity. * @param groups The group(s) used to sort the profile data. * @param start When the time horizon starts in epoch milliseconds. * @param end When the time horizon ends in epoch milliseconds. * @return All of the row keys necessary to retrieve the profile measurements. */ @Override public List<byte[]> rowKeys(String profile, String entity, List<Object> groups, long start, long end) { // be forgiving of out-of-order start and end times; order is critical to this algorithm long max = Math.max(start, end); start = Math.min(start, end); end = max; // find the starting period and advance until the end time is reached return ProfilePeriod.visitPeriods( start , end , periodDurationMillis , TimeUnit.MILLISECONDS , Optional.empty() , period -> rowKey(profile, entity, period, groups) ); }
@Override public Object apply(List<Object> args, Context context) throws ParseException { Optional<Map> configOverridesMap = Optional.empty(); long durationAgo = Util.getArg(0, Long.class, args); String unitsName = Util.getArg(1, String.class, args); TimeUnit units = TimeUnit.valueOf(unitsName); if(args.size() > 2) { Map rawMap = Util.getArg(2, Map.class, args); configOverridesMap = rawMap == null || rawMap.isEmpty() ? Optional.empty() : Optional.of(rawMap); } Map<String, Object> effectiveConfigs = Util.getEffectiveConfig(context, configOverridesMap.orElse(null)); Long tickDuration = ProfilerClientConfig.PROFILER_PERIOD.get(effectiveConfigs, Long.class); TimeUnit tickUnit = TimeUnit.valueOf(ProfilerClientConfig.PROFILER_PERIOD_UNITS.get(effectiveConfigs, String.class)); long end = System.currentTimeMillis(); long start = end - units.toMillis(durationAgo); return ProfilePeriod.visitPeriods(start, end, tickDuration, tickUnit, Optional.empty(), period -> period); }
, ProfilePeriod.class ); return ProfilePeriod.visitPeriods(start, end, tickDuration, tickUnit, Optional.of(intervalSelector), period -> period);