class ProfilingContext {

    private static final double NS_TO_MS_FACTOR = 1_000_000.0d;
    private final HashMap<String, Double> durationInMSByTimer;
    private final List<QueryProfiler> profilers;

    public ProfilingContext(List<QueryProfiler> profilers) {
        this.profilers = profilers;
        this.durationInMSByTimer = new HashMap<>();
    }

    public Map<String, Object> getDurationInMSByTimer() {
        HashMap<String, Object> builder = new HashMap<>(durationInMSByTimer);
        ArrayList<Map<String, Object>> queryTimings = new ArrayList<>();
        for (var profiler : profilers) {
            for (var profileResult : profiler.getTree()) {
                queryTimings.add(resultAsMap(profileResult));
            }
        }
        if (!queryTimings.isEmpty()) {
            builder.put("QueryBreakdown", queryTimings);
        }
        return Collections.unmodifiableMap(builder);
    }

    private static Map<String, Object> resultAsMap(ProfileResult profileResult) {<FILL_FUNCTION_BODY>}

    public Timer createAndStartTimer(String name) {
        Timer timer = createTimer(name);
        timer.start();
        return timer;
    }

    public void stopTimerAndStoreDuration(Timer timer) {
        timer.stop();
        durationInMSByTimer.put(timer.name(), timer.durationNanos() / NS_TO_MS_FACTOR);
    }

    public Timer createTimer(String name) {
        return new Timer(name);
    }

    public static String generateProfilingKey(int id, String name) {
        return id + "-" + name;
    }
}

        HashMap<String, Object> queryTimingsBuilder = new HashMap<>();
        queryTimingsBuilder.put("QueryName", profileResult.getQueryName());
        queryTimingsBuilder.put("QueryDescription", profileResult.getLuceneDescription());
        queryTimingsBuilder.put("Time", profileResult.getTime() / NS_TO_MS_FACTOR);
        queryTimingsBuilder.put("BreakDown", profileResult.getTimeBreakdown().entrySet().stream()
            .collect(Collectors.toMap(
                Map.Entry::getKey,
                e -> e.getKey().endsWith("_count") ? e.getValue() : e.getValue() / NS_TO_MS_FACTOR))
        );
        List<Map<String, Object>> children = profileResult.getProfiledChildren().stream()
            .map(ProfilingContext::resultAsMap)
            .collect(Collectors.toList());
        if (!children.isEmpty()) {
            queryTimingsBuilder.put("Children", children);
        }
        return Collections.unmodifiableMap(queryTimingsBuilder);
    
<no_super_class>