comparison graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugHistogram.java @ 21554:b1530a6cce8c

renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Tue, 26 May 2015 23:21:15 +0200
parents graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugHistogram.java@cda2a7d1dcff
children
comparison
equal deleted inserted replaced
21553:0910a9497b02 21554:b1530a6cce8c
1 /*
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.oracle.jvmci.debug;
24
25 import java.util.*;
26
27 /**
28 * Facility for recording value frequencies.
29 */
30 public interface DebugHistogram {
31
32 /**
33 * Gets the name specified when this objected was {@linkplain Debug#createHistogram(String)
34 * created}.
35 */
36 String getName();
37
38 /**
39 * Increments the count for a given value.
40 */
41 void add(Object value);
42
43 void add(Object value, long count);
44
45 /**
46 * A value and a frequency. The ordering imposed by {@link #compareTo(CountedValue)} places
47 * values with higher frequencies first.
48 */
49 public class CountedValue implements Comparable<CountedValue> {
50
51 private long count;
52 private final Object value;
53
54 public CountedValue(long count, Object value) {
55 this.count = count;
56 this.value = value;
57 }
58
59 public int compareTo(CountedValue o) {
60 if (count < o.count) {
61 return 1;
62 } else if (count > o.count) {
63 return -1;
64 }
65 return 0;
66 }
67
68 @Override
69 public String toString() {
70 return count + " -> " + value;
71 }
72
73 public void inc() {
74 count++;
75 }
76
77 public void add(long n) {
78 count += n;
79 }
80
81 public long getCount() {
82 return count;
83 }
84
85 public Object getValue() {
86 return value;
87 }
88 }
89
90 /**
91 * Gets a list of the counted values, sorted in descending order of frequency.
92 */
93 List<CountedValue> getValues();
94
95 /**
96 * Interface for a service that can render a visualization of a histogram.
97 */
98 public interface Printer {
99
100 void print(DebugHistogram histogram);
101 }
102 }