001/*
002 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package com.oracle.graal.truffle;
024
025import java.util.*;
026
027public class TruffleInliningProfile {
028
029    private final OptimizedDirectCallNode callNode;
030    private final int nodeCount;
031    private final int deepNodeCount;
032    private final double frequency;
033    private final int recursions;
034
035    private String failedReason;
036    private int queryIndex = -1;
037    private double score;
038
039    public TruffleInliningProfile(OptimizedDirectCallNode callNode, int nodeCount, int deepNodeCount, double frequency, int recursions) {
040        this.callNode = callNode;
041        this.nodeCount = nodeCount;
042        this.deepNodeCount = deepNodeCount;
043        this.frequency = frequency;
044        this.recursions = recursions;
045    }
046
047    public int getRecursions() {
048        return recursions;
049    }
050
051    public OptimizedDirectCallNode getCallNode() {
052        return callNode;
053    }
054
055    public int getCallSites() {
056        return callNode.getCurrentCallTarget().getKnownCallSiteCount();
057    }
058
059    public int getNodeCount() {
060        return nodeCount;
061    }
062
063    public void setScore(double score) {
064        this.score = score;
065    }
066
067    public double getScore() {
068        return score;
069    }
070
071    public String getFailedReason() {
072        return failedReason;
073    }
074
075    public void setQueryIndex(int queryIndex) {
076        this.queryIndex = queryIndex;
077    }
078
079    public int getQueryIndex() {
080        return queryIndex;
081    }
082
083    public void setFailedReason(String reason) {
084        this.failedReason = reason;
085    }
086
087    public boolean isForced() {
088        return callNode.isInliningForced();
089    }
090
091    public double getFrequency() {
092        return frequency;
093    }
094
095    public int getDeepNodeCount() {
096        return deepNodeCount;
097    }
098
099    public Map<String, Object> getDebugProperties() {
100        Map<String, Object> properties = new LinkedHashMap<>();
101        properties.put("ASTSize", String.format("%5d/%5d", nodeCount, deepNodeCount));
102        properties.put("frequency", String.format("%8.4f", getFrequency()));
103        properties.put("score", String.format("%8.4f", getScore()));
104        properties.put(String.format("index=%3d, force=%s, callSites=%2d", queryIndex, (isForced() ? "Y" : "N"), getCallSites()), "");
105        properties.put("reason", failedReason);
106        return properties;
107    }
108}