4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 |
23 | public class Example
24 | {
25 |
26 | public static void main(String[] args) throws Exception
27 | {
28 | for (int i = 0; i < 2000; i++)
29 | {
30 | Thread.sleep(1);
31 | subMethod();
32 | }
33 | }
34 |
35 | private static void subMethod()
36 | {
37 | System.out.println("calling some code, lalala");
38 | }
39 |
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/src/main/java/InfiniteExample.java:
--------------------------------------------------------------------------------
1 | import com.insightfullogic.honest_profiler.core.control.Agent;
2 |
3 | import java.lang.management.ManagementFactory;
4 |
5 | import static java.lang.Long.parseLong;
6 |
7 | /**
8 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
9 | *
10 | * Permission is hereby granted, free of charge, to any person obtaining a
11 | * copy of this software and associated documentation files (the "Software"),
12 | * to deal in the Software without restriction, including without limitation
13 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 | * and/or sell copies of the Software, and to permit persons to whom the
15 | * Software is furnished to do so, subject to the following conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be included
18 | * in all copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 | * DEALINGS IN THE SOFTWARE.
27 | **/
28 | public class InfiniteExample
29 | {
30 |
31 | public static void main(String[] args) throws Exception
32 | {
33 | final String jvmName = ManagementFactory.getRuntimeMXBean().getName();
34 | final int index = jvmName.indexOf('@');
35 | final Thread control = new Thread(InfiniteExample::startOrStop);
36 |
37 | System.out.println(parseLong(jvmName.substring(0, index)));
38 | control.start();
39 |
40 | while (true)
41 | {
42 | Thread.sleep(1);
43 | subMethod();
44 | }
45 | }
46 |
47 | private static void subMethod()
48 | {
49 | System.out.println("calling some code, lalala");
50 | }
51 |
52 | private static void startOrStop()
53 | {
54 | try
55 | {
56 | while (true)
57 | {
58 | int ch = System.in.read();
59 |
60 | if (ch == 'S')
61 | Agent.start();
62 | else if (ch == 's')
63 | Agent.stop();
64 | }
65 | }
66 | catch (Exception e)
67 | {
68 | throw new RuntimeException(e);
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/Box.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.core;
23 |
24 | import java.util.function.Consumer;
25 |
26 | public class Box implements Consumer
27 | {
28 | private T t;
29 |
30 | public void accept(final T t)
31 | {
32 | this.t = t;
33 | }
34 |
35 | public T get()
36 | {
37 | return t;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/MachineListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.core;
23 |
24 | import com.insightfullogic.honest_profiler.core.sources.VirtualMachine;
25 |
26 | public interface MachineListener
27 | {
28 |
29 | void onNewMachine(VirtualMachine machine);
30 |
31 | void onClosedMachine(VirtualMachine machine);
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/ThreadedAgent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.core;
23 |
24 | import org.slf4j.Logger;
25 |
26 | public class ThreadedAgent implements Runnable
27 | {
28 |
29 | public interface Block
30 | {
31 | /**
32 | * @return false iff you're ready to stop, true otherwise
33 | * @throws Exception when things go bump
34 | */
35 | boolean run() throws Exception;
36 | }
37 |
38 | private final Logger logger;
39 | private final Block block;
40 |
41 | private Thread thread;
42 |
43 | public ThreadedAgent(final Logger logger, Block block)
44 | {
45 | this.logger = logger;
46 | this.block = block;
47 | }
48 |
49 | public void start()
50 | {
51 | thread = new Thread(this);
52 | thread.setDaemon(true);
53 | thread.start();
54 | }
55 |
56 | public void stop()
57 | {
58 | thread.interrupt();
59 | }
60 |
61 | @Override
62 | public void run()
63 | {
64 | logger.debug("Started");
65 | try
66 | {
67 | while (!Thread.currentThread().isInterrupted() && block.run())
68 | ;
69 |
70 | logger.debug(Thread.currentThread().getName() + " Stopped");
71 | }
72 | catch (Throwable throwable)
73 | {
74 | // Deliberately catching throwable since we're at the top of a thread
75 | logger.error(throwable.getMessage(), throwable);
76 | }
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/aggregation/ReferenceMode.java:
--------------------------------------------------------------------------------
1 | package com.insightfullogic.honest_profiler.core.aggregation;
2 |
3 | import com.insightfullogic.honest_profiler.core.aggregation.result.diff.DiffNode;
4 | import com.insightfullogic.honest_profiler.core.aggregation.result.straight.Entry;
5 | import com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node;
6 |
7 | /**
8 | * {@link Entry}s contain some percentage values, which are calculated by dividing one of the other contained values by
9 | * a reference value. Several references can make sense in various circumstances. This enumeration lists the various
10 | * supported "reference modes" for {@link Entry}s.
11 | */
12 | public enum ReferenceMode
13 | {
14 | /**
15 | * Mode which specifies that the aggregated total values of the entire profile are used as reference.
16 | */
17 | GLOBAL("Global"),
18 | /**
19 | * Mode which specifies that for a given {@link Entry}, the aggregated total values of the containing thread are
20 | * used as reference. WARNING : This can obviously only be used in aggregations where the {@link Entry}s are
21 | * guaranteed to aggregate data from a single thread.
22 | */
23 | THREAD("Thread"),
24 | /**
25 | * Mode which is applicable only to {@link Node}s or {@link DiffNode}s, and which specified that the aggregated
26 | * total values of the parent {@link Node} or {@link DiffNode} is used as reference.
27 | */
28 | PARENT("Parent");
29 |
30 | // Instance Properties
31 |
32 | private String name;
33 |
34 | // Instance Constructors
35 |
36 | /**
37 | * Constructor specifying a display name for the ReferenceMode.
38 | *
39 | * @param name the display name for the ReferenceMode
40 | */
41 | private ReferenceMode(String name)
42 | {
43 | this.name = name;
44 | }
45 |
46 | // Object Implementation
47 |
48 | @Override
49 | public String toString()
50 | {
51 | return this.name;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/aggregation/aggregator/ProfileAggregator.java:
--------------------------------------------------------------------------------
1 | package com.insightfullogic.honest_profiler.core.aggregation.aggregator;
2 |
3 | import com.insightfullogic.honest_profiler.core.aggregation.AggregationProfile;
4 | import com.insightfullogic.honest_profiler.core.aggregation.grouping.CombinedGrouping;
5 | import com.insightfullogic.honest_profiler.core.aggregation.result.Aggregation;
6 | import com.insightfullogic.honest_profiler.core.aggregation.result.Keyed;
7 |
8 | /**
9 | * Generic interface for aggregation functions which operate on the entire {@link AggregationProfile}. An Aggregator
10 | * aggregates an input {@link AggregationProfile} into an {@link Aggregation} containing results of type T, which are
11 | * keyed by a String.
12 | *
13 | * @param the type of the content items in the resulting {@link Aggregation}
14 | */
15 | public interface ProfileAggregator>
16 | {
17 | /**
18 | * Aggregate the provided {@link AggregationProfile}.
19 | *
20 | * @param input the {@link AggregationProfile} to be aggregated
21 | * @param grouping the {@link CombinedGrouping} to be used when aggregating
22 | * @return the resulting {@link Aggregation}
23 | */
24 | Aggregation aggregate(AggregationProfile input, CombinedGrouping grouping);
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/aggregation/aggregator/SubAggregator.java:
--------------------------------------------------------------------------------
1 | package com.insightfullogic.honest_profiler.core.aggregation.aggregator;
2 |
3 | import com.insightfullogic.honest_profiler.core.aggregation.result.Aggregation;
4 | import com.insightfullogic.honest_profiler.core.aggregation.result.Keyed;
5 |
6 | /**
7 | * Generic interface for aggregation functions which operate on already aggregated items. An Aggregator aggregates input
8 | * of type I into an {@link Aggregation} containing results of type T, which are keyed by a key of type String.
9 | *
10 | * @param I the type of the input being aggregated
11 | * @param T the type of the content items in the resulting {@link Aggregation}
12 | */
13 | public interface SubAggregator>
14 | {
15 | /**
16 | * Aggregate the provided input.
17 | *
18 | * @param input the input for the aggregation
19 | * @return the resulting {@link Aggregation}
20 | */
21 | Aggregation aggregate(I input);
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/aggregation/filter/FilterPredicate.java:
--------------------------------------------------------------------------------
1 | package com.insightfullogic.honest_profiler.core.aggregation.filter;
2 |
3 | import java.util.function.Function;
4 | import java.util.function.Predicate;
5 |
6 | import com.insightfullogic.honest_profiler.core.aggregation.result.ItemType;
7 |
8 | /**
9 | * This {@link Predicate} extracts the value described by {@link Target} from its input, and compares it using the
10 | * specified {@link Comparison} against a specified value.
11 | *
12 | * The filter is composed of 2 parts :
13 | *
14 | *
an extractor {@link Function} which extracts the value to be compared from the input
15 | *
a comparer {@link Predicate} which will compare the extracted value against the value specified by the
16 | * filter
17 | *
18 | *
19 | * @param the type of the input items which will be tested
20 | * @param the type of the values which will be compared
21 | */
22 | public class FilterPredicate implements Predicate
23 | {
24 | // Instance Properties
25 |
26 | private Function extractor;
27 | private Predicate comparer;
28 |
29 | // Instance COnstructors
30 |
31 | /**
32 | * Basic constructor which takes the type of the item being filtered, the {@link Target} describing the value to be
33 | * extracted from the input, the type of {@link Comparison} and the value to be compared against.
34 | *
35 | * @param type the type of the item this FilterPredicate can be used on
36 | * @param target the {@link Target} for the filter
37 | * @param comparison the {@link Comparison} to be applied
38 | * @param value the value to be compared against
39 | */
40 | public FilterPredicate(ItemType type, Target target, Comparison comparison, U value)
41 | {
42 | extractor = target.getExtractor(type);
43 | comparer = comparison.getPredicate(value);
44 | }
45 |
46 | // Predicate Implementation
47 |
48 | @Override
49 | public boolean test(T t)
50 | {
51 | return comparer.test(extractor.apply(t));
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/aggregation/grouping/ThreadGrouping.java:
--------------------------------------------------------------------------------
1 | package com.insightfullogic.honest_profiler.core.aggregation.grouping;
2 |
3 | import java.util.function.Function;
4 |
5 | import com.insightfullogic.honest_profiler.core.profiles.lean.LeanThreadNode;
6 |
7 | /**
8 | * A ThreadGrouping describes how a collection of {@link LeanThreadNode}s describing thread-level aggregations can be
9 | * partitioned for aggregation. The grouping maps each {@link LeanThreadNode} to a String key, and
10 | * {@link LeanThreadNode}s with the same key will be aggregated together.
11 | *
12 | * Every ThreadGrouping contains a name for front-end display purposes, and wraps a {@link Function} which maps an a
13 | * {@link LeanThreadNode} to the String key.
14 | */
15 | public enum ThreadGrouping implements Function
16 | {
17 | /**
18 | * Group all threads together into a single group.
19 | */
20 | ALL_TOGETHER("All threads", node -> "All Threads"),
21 | /**
22 | * Group threads by Thread name.
23 | */
24 | BY_NAME("By name", node -> node.getThreadInfo() == null || node.getThreadInfo().getName() == null || node.getThreadInfo().getName().isEmpty() ? "Unknown Thread(s)" : node.getThreadInfo().getName()),
25 | /**
26 | * Group threads by Thread Id. This is more specific than by name, since several threads in aggregations can have
27 | * the same name (e.g. in Diffs).
28 | */
29 | BY_ID("By ID", node -> node.getThreadInfo() == null ? "Unknown Thread " : node.getThreadInfo().getIdentification());
30 |
31 | // Instance Properties
32 |
33 | private String name;
34 | private Function function;
35 |
36 | // Instance Constructors
37 |
38 | private ThreadGrouping(String name, Function function)
39 | {
40 | this.name = name;
41 | this.function = function;
42 | }
43 |
44 | // Function Implementation
45 |
46 | @Override
47 | public String apply(LeanThreadNode node)
48 | {
49 | return function.apply(node);
50 | }
51 |
52 | @Override
53 | public String toString()
54 | {
55 | return this.name;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/aggregation/result/Keyed.java:
--------------------------------------------------------------------------------
1 | package com.insightfullogic.honest_profiler.core.aggregation.result;
2 |
3 | /**
4 | * Interface for aggregation data structure classes which have an aggregation key.
5 | *
6 | * @param the type of the key
7 | */
8 | public interface Keyed
9 | {
10 | /**
11 | * Returns the aggregation key which was used to aggregate data into this data structure.
12 | *
13 | * @return the aggregation key which was used to aggregate data into this data structure
14 | */
15 | T getKey();
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/aggregation/result/Parent.java:
--------------------------------------------------------------------------------
1 | package com.insightfullogic.honest_profiler.core.aggregation.result;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Interface for data structure classes which have children ot type T.
7 | *
8 | * @param the type of the children
9 | */
10 | public interface Parent
11 | {
12 | /**
13 | * Returns the list of children.
14 | *
15 | * @return the list of children
16 | */
17 | List getChildren();
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/aggregation/result/straight/Flat.java:
--------------------------------------------------------------------------------
1 | package com.insightfullogic.honest_profiler.core.aggregation.result.straight;
2 |
3 | import static java.util.stream.Collectors.toList;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | import com.insightfullogic.honest_profiler.core.aggregation.AggregationProfile;
9 | import com.insightfullogic.honest_profiler.core.aggregation.filter.FilterSpecification;
10 | import com.insightfullogic.honest_profiler.core.aggregation.grouping.CombinedGrouping;
11 | import com.insightfullogic.honest_profiler.core.aggregation.result.Aggregation;
12 | import com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode;
13 |
14 | /**
15 | * A Flat is a list-based {@link Aggregation}. {@link LeanNode}s are aggregated by using the {@link CombinedGrouping} to
16 | * extract a String key, and each {@link Entry} in the Flat is the aggregation of all {@link LeanNode}s with the same
17 | * key.
18 | */
19 | public class Flat extends Aggregation
20 | {
21 | // Instance Constructors
22 |
23 | /**
24 | * Create an empty Flat for the specified {@link AggregationProfile} and {@link CombinedGrouping}.
25 | *
26 | * @param source the {@link AggregationProfile} whose {@link LeanNode}s are aggregated into this Flat
27 | * @param grouping the {@link CombinedGrouping} used for aggregation
28 | */
29 | public Flat(AggregationProfile source, CombinedGrouping grouping)
30 | {
31 | super(source, grouping, new ArrayList<>());
32 | }
33 |
34 | /**
35 | * Internal constructor used by the {@link #filter(FilterSpecification)} method.
36 | *
37 | * @param source the {@link AggregationProfile} whose {@link LeanNode}s are aggregated into this Flat
38 | * @param grouping the {@link CombinedGrouping} used for aggregation
39 | * @param data the list of {@link Entry}s in the Flat
40 | */
41 | private Flat(AggregationProfile source, CombinedGrouping grouping, List data)
42 | {
43 | super(source, grouping, data);
44 | }
45 |
46 | // Instance Accessors
47 |
48 | @Override
49 | public List getData()
50 | {
51 | return super.getData();
52 | }
53 |
54 | // Aggregation Implementation
55 |
56 | @Override
57 | public Flat filter(FilterSpecification filterSpec)
58 | {
59 | return new Flat(
60 | getSource(),
61 | getGrouping(),
62 | getData().stream().filter(filterSpec.getFilter()).collect(toList()));
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/collector/CallCounts.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.core.collector;
23 |
24 | class CallCounts
25 | {
26 | private int timeAppeared;
27 | private int timeInvokingThis;
28 |
29 | CallCounts()
30 | {
31 | this.timeAppeared = 0;
32 | this.timeInvokingThis = 0;
33 | }
34 |
35 | int getTimeAppeared(){
36 | return timeAppeared;
37 | }
38 |
39 | int getTimeInvokingThis(){
40 | return timeInvokingThis;
41 | }
42 |
43 | void onAppearance(final boolean endOfTrace)
44 | {
45 | timeAppeared++;
46 | if (endOfTrace)
47 | {
48 | timeInvokingThis++;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/collector/Frame.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.core.collector;
23 |
24 | public interface Frame
25 | {
26 | default String getFullName()
27 | {
28 | return getClassName() + "." + getMethodName();
29 | }
30 |
31 | int BCI_ERR_IGNORE = -42;
32 |
33 | long getMethodId();
34 |
35 | String getClassName();
36 |
37 | String getMethodName();
38 |
39 | String getMethodSignature();
40 |
41 | String getMethodReturnType();
42 |
43 | int getBci();
44 |
45 | int getLine();
46 |
47 | Frame copy();
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/collector/lean/ProfileSource.java:
--------------------------------------------------------------------------------
1 | package com.insightfullogic.honest_profiler.core.collector.lean;
2 |
3 | /**
4 | * Interface for classes a profile can be requested from.
5 | */
6 | public interface ProfileSource
7 | {
8 | /**
9 | * Request that a profile be emitted as soon as possible. There is no guarantee that any profile will be emitted.
10 | */
11 | void requestProfile();
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/control/Agent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.core.control;
23 |
24 | public class Agent
25 | {
26 | public static native boolean start();
27 |
28 | public static native void stop();
29 |
30 | public static native boolean isRunning();
31 |
32 | public static native int getSamplingIntervalMin();
33 |
34 | public static native int getSamplingIntervalMax();
35 |
36 | public static native int getMaxFramesToCapture();
37 |
38 | public static native String getFilePath();
39 |
40 | public static native void setFilePath(String filePath);
41 |
42 | public static native void setSamplingInterval(int intervalMin, int intervalMax);
43 |
44 | public static native void setMaxFramesToCapture(int maxFramesToCapture);
45 |
46 | public static native int getCurrentNativeThreadId();
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/filters/ClassNameFilter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.core.filters;
23 |
24 | import static com.insightfullogic.honest_profiler.core.filters.Filter.Mode.CONTAINS;
25 |
26 | public final class ClassNameFilter extends StringFilter
27 | {
28 |
29 | ClassNameFilter(final String className)
30 | {
31 | this(CONTAINS, className);
32 | }
33 |
34 | public ClassNameFilter(Mode mode, String input)
35 | {
36 | super(mode, frame -> frame.getClassName(), input);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/filters/Filter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.core.filters;
23 |
24 | import com.insightfullogic.honest_profiler.core.profiles.Profile;
25 |
26 | /**
27 | * All implementations should be immutable and thus threadsafe.
28 | */
29 | public interface Filter
30 | {
31 | static enum Mode
32 | {
33 | CONTAINS, EQUALS, STARTS_WITH, ENDS_WITH, MATCHES, GT, LT, GE, LE
34 | }
35 |
36 | void filter(Profile profile);
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/filters/FilterParseException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.core.filters;
23 |
24 | public final class FilterParseException extends RuntimeException
25 | {
26 | FilterParseException(String message)
27 | {
28 | super(message);
29 | }
30 |
31 | FilterParseException(Exception e)
32 | {
33 | super(e);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/filters/MethodNameFilter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
5 | * associated documentation files (the "Software"), to deal in the Software without restriction,
6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
8 | * furnished to do so, subject to the following conditions:
9 | *
10 | * The above copyright notice and this permission notice shall be included in all copies or
11 | * substantial portions of the Software.
12 | *
13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
14 | * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18 | **/
19 | package com.insightfullogic.honest_profiler.core.filters;
20 |
21 | import static com.insightfullogic.honest_profiler.core.filters.Filter.Mode.CONTAINS;
22 |
23 | public final class MethodNameFilter extends StringFilter
24 | {
25 | MethodNameFilter(final String className)
26 | {
27 | this(CONTAINS, className);
28 | }
29 |
30 | public MethodNameFilter(Mode mode, String input)
31 | {
32 | super(mode, frame -> frame.getMethodName(), input);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/filters/ProfileFilter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.core.filters;
23 |
24 | import com.insightfullogic.honest_profiler.core.profiles.Profile;
25 | import com.insightfullogic.honest_profiler.core.profiles.ProfileListener;
26 |
27 | import static com.insightfullogic.honest_profiler.core.filters.Filters.parse;
28 | import static java.util.Collections.emptyList;
29 |
30 | import java.util.ArrayList;
31 | import java.util.List;
32 |
33 | public class ProfileFilter implements ProfileListener
34 | {
35 | private volatile List filters;
36 |
37 | public ProfileFilter()
38 | {
39 | filters = emptyList();
40 | }
41 |
42 | public ProfileFilter(List filters)
43 | {
44 | this.filters = filters;
45 | }
46 |
47 | public void updateFilters(String filterDescription)
48 | {
49 | filters = parse(filterDescription);
50 | }
51 |
52 | public List getFilters() {
53 | return new ArrayList<>(filters);
54 | }
55 |
56 | public void setFilters(List filters)
57 | {
58 | this.filters = filters;
59 | }
60 |
61 | @Override
62 | public void accept(Profile profile)
63 | {
64 | filters.forEach(filter -> filter.filter(profile));
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/filters/SelfTimeShareFilter.java:
--------------------------------------------------------------------------------
1 | package com.insightfullogic.honest_profiler.core.filters;
2 |
3 | import com.insightfullogic.honest_profiler.core.collector.FlatProfileEntry;
4 | import com.insightfullogic.honest_profiler.core.profiles.ProfileNode;
5 |
6 | public final class SelfTimeShareFilter extends TimeShareFilter {
7 |
8 | SelfTimeShareFilter(double minShare) {
9 | super(minShare);
10 | }
11 |
12 | public SelfTimeShareFilter(Mode mode, double minShare) {
13 | super(mode, minShare);
14 | }
15 |
16 | @Override
17 | protected double flatField(FlatProfileEntry entry) {
18 | return entry.getSelfTimeShare();
19 | }
20 |
21 | @Override
22 | protected double treeField(ProfileNode node) {
23 | return node.getSelfTimeShare();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/filters/TotalTimeShareFilter.java:
--------------------------------------------------------------------------------
1 | package com.insightfullogic.honest_profiler.core.filters;
2 |
3 | import com.insightfullogic.honest_profiler.core.collector.FlatProfileEntry;
4 | import com.insightfullogic.honest_profiler.core.profiles.ProfileNode;
5 |
6 | public final class TotalTimeShareFilter extends TimeShareFilter {
7 |
8 | TotalTimeShareFilter(double minShare) {
9 | super(minShare);
10 | }
11 |
12 | public TotalTimeShareFilter(Mode mode, double minShare) {
13 | super(mode, minShare);
14 | }
15 |
16 | @Override
17 | protected double flatField(FlatProfileEntry entry) {
18 | return entry.getTotalTimeShare();
19 | }
20 |
21 | @Override
22 | protected double treeField(ProfileNode node) {
23 | return node.getTotalTimeShare();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | *
22 | * Conducts the flow of information about logs themselves, currently streaming, historical, etc.
23 | *
24 | * Conducts the flow of information about logs themselves, currently streaming, historical, etc.
25 | *
26 | * Conducts the flow of information about logs themselves, currently streaming, historical, etc.
27 | */
28 | /**
29 | * Conducts the flow of information about logs themselves, currently streaming, historical, etc.
30 | */
31 | package com.insightfullogic.honest_profiler.core;
32 |
33 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/parser/LogEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.core.parser;
23 |
24 | public interface LogEvent
25 | {
26 | void accept(LogEventListener listener);
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/parser/LogEventListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.core.parser;
23 |
24 | public interface LogEventListener
25 | {
26 |
27 | void handle(TraceStart traceStart);
28 |
29 | void handle(StackFrame stackFrame);
30 |
31 | void handle(Method newMethod);
32 |
33 | void handle(ThreadMeta newThreadMeta);
34 |
35 | void endOfLog();
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/parser/LogEventPublisher.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.core.parser;
23 |
24 | import java.util.ArrayList;
25 | import java.util.List;
26 |
27 | public class LogEventPublisher implements LogEventListener
28 | {
29 | private final List listeners = new ArrayList<>();
30 |
31 | public LogEventPublisher publishTo(final LogEventListener listener)
32 | {
33 | listeners.add(listener);
34 | return this;
35 | }
36 |
37 | public void handle(final TraceStart traceStart)
38 | {
39 | for (LogEventListener listener : listeners)
40 | {
41 | listener.handle(traceStart);
42 | }
43 | }
44 |
45 | public void handle(final StackFrame stackFrame)
46 | {
47 | for (LogEventListener listener : listeners)
48 | {
49 | listener.handle(stackFrame);
50 | }
51 | }
52 |
53 | public void handle(final Method newMethod)
54 | {
55 | for (LogEventListener listener : listeners)
56 | {
57 | listener.handle(newMethod);
58 | }
59 | }
60 |
61 | public void handle(final ThreadMeta newThreadMeta)
62 | {
63 | for (LogEventListener listener : listeners)
64 | {
65 | listener.handle(newThreadMeta);
66 | }
67 | }
68 |
69 | public void endOfLog()
70 | {
71 | for (LogEventListener listener : listeners)
72 | {
73 | listener.endOfLog();
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/platform/Platforms.java:
--------------------------------------------------------------------------------
1 | package com.insightfullogic.honest_profiler.core.platform;
2 |
3 |
4 | public class Platforms
5 | {
6 | private Platforms() {}
7 |
8 | public static String getDynamicLibraryExtension()
9 | {
10 | if (isOsx())
11 | {
12 | return ".dylib";
13 | }
14 | // Default is .so
15 | return ".so";
16 | }
17 |
18 | private static boolean isOsx()
19 | {
20 | return getOsName().toUpperCase().contains("MAC");
21 | }
22 |
23 | private static String getOsName()
24 | {
25 | return System.getProperty("os.name");
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/profiles/FlameGraph.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2015 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.core.profiles;
23 |
24 | import java.util.ArrayList;
25 | import java.util.List;
26 |
27 | /**
28 | * Represents the stored data model for a flamegraph
29 | */
30 | public class FlameGraph
31 | {
32 | private List traces = new ArrayList<>();
33 |
34 | public FlameGraph()
35 | {
36 | }
37 |
38 | public void onNewTrace(FlameTrace trace)
39 | {
40 | traces.add(trace);
41 | }
42 |
43 | public List getTraces()
44 | {
45 | return traces;
46 | }
47 |
48 | public long totalWeight()
49 | {
50 | return traces.stream().mapToLong(FlameTrace::getWeight).sum();
51 | }
52 |
53 | public int maxTraceHeight()
54 | {
55 | return traces.stream().mapToInt(trace -> trace.getMethods().size()).max().getAsInt();
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/profiles/FlameGraphListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.core.profiles;
23 |
24 | import java.util.function.Consumer;
25 |
26 | public interface FlameGraphListener extends Consumer
27 | {
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/profiles/FlameTrace.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.core.profiles;
23 |
24 | import com.insightfullogic.honest_profiler.core.parser.Method;
25 |
26 | import java.util.Collections;
27 | import java.util.List;
28 |
29 | public class FlameTrace
30 | {
31 | private final List methods;
32 |
33 | private long weight;
34 |
35 | public FlameTrace(final List methods, final long weight)
36 | {
37 | Collections.reverse(methods);
38 |
39 | this.methods = methods;
40 | this.weight = weight;
41 | }
42 |
43 | public long getWeight()
44 | {
45 | return weight;
46 | }
47 |
48 | public List getMethods()
49 | {
50 | return methods;
51 | }
52 |
53 | public Method at(final int row)
54 | {
55 | return methods.size() > row ? methods.get(row) : null;
56 | }
57 |
58 | public void incrementWeight()
59 | {
60 | weight++;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/profiles/ProfileListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.core.profiles;
23 |
24 | import java.util.function.Consumer;
25 |
26 | public interface ProfileListener extends Consumer
27 | {
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/profiles/ProfileTree.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.core.profiles;
23 |
24 | import com.insightfullogic.honest_profiler.core.parser.ThreadMeta;
25 |
26 | public final class ProfileTree
27 | {
28 | private final int numberOfSamples;
29 | private final ThreadMeta threadMeta;
30 | private final ProfileNode rootNode;
31 |
32 | public ProfileTree(long threadId, ProfileNode rootNode, int numberOfSamples)
33 | {
34 | this(new ThreadMeta(threadId, ""), rootNode, numberOfSamples);
35 | }
36 |
37 | public ProfileTree(ThreadMeta threadMeta, ProfileNode rootNode, int numberOfSamples)
38 | {
39 | this.threadMeta = threadMeta;
40 | this.rootNode = rootNode;
41 | this.numberOfSamples = numberOfSamples;
42 | }
43 |
44 | public int getNumberOfSamples()
45 | {
46 | return numberOfSamples;
47 | }
48 |
49 | public ProfileNode getRootNode()
50 | {
51 | return rootNode;
52 | }
53 |
54 | public long getThreadId()
55 | {
56 | return threadMeta.getThreadId();
57 | }
58 |
59 | public String getThreadName()
60 | {
61 | return threadMeta.getThreadName();
62 | }
63 |
64 | @Override
65 | public String toString()
66 | {
67 | return "ProfileTree{" +
68 | rootNode +
69 | '}';
70 | }
71 |
72 | public ProfileTree copy()
73 | {
74 | return new ProfileTree(threadMeta.copy(), rootNode.copy(), numberOfSamples);
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/profiles/lean/LeanProfileListener.java:
--------------------------------------------------------------------------------
1 | package com.insightfullogic.honest_profiler.core.profiles.lean;
2 |
3 | import java.util.function.Consumer;
4 |
5 | import com.insightfullogic.honest_profiler.core.collector.lean.LeanLogCollector;
6 |
7 | /**
8 | * Marker interface for Classes which can be used to receive {@link LeanProfile}s emitted by the
9 | * {@link LeanLogCollector}.
10 | *
11 | * Not sure if this adds anything but noise, might get rid of it.
12 | */
13 | public interface LeanProfileListener extends Consumer
14 | {
15 | // Marker Interface
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/profiles/lean/LeanThreadNode.java:
--------------------------------------------------------------------------------
1 | package com.insightfullogic.honest_profiler.core.profiles.lean;
2 |
3 | import com.insightfullogic.honest_profiler.core.profiles.lean.info.FrameInfo;
4 | import com.insightfullogic.honest_profiler.core.profiles.lean.info.NumericInfo;
5 | import com.insightfullogic.honest_profiler.core.profiles.lean.info.ThreadInfo;
6 |
7 | /**
8 | * Subclass of {@link LeanNode} which stores {@link ThreadInfo} metadata and aggregated {@link NumericInfo} for a thread
9 | * in a {@link LeanProfile}. The root nodes in the {@link LeanProfile} trees are {@link LeanThreadNode}s. All other
10 | * {@link LeanNode}s are instances of the {@link LeanNode} superclass.
11 | */
12 | public class LeanThreadNode extends LeanNode
13 | {
14 | // Instance Properties
15 |
16 | private ThreadInfo threadInfo;
17 |
18 | // Instance Constructors
19 |
20 | /**
21 | * Empty constructor.
22 | */
23 | public LeanThreadNode()
24 | {
25 | super((FrameInfo)null, null);
26 | }
27 |
28 | /**
29 | * Copy constructor.
30 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.core.sources;
23 |
24 | import java.io.IOException;
25 | import java.nio.ByteBuffer;
26 |
27 | public interface LogSource extends AutoCloseable
28 | {
29 | public ByteBuffer read();
30 |
31 | @Override
32 | void close() throws IOException;
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/sources/MachineSource.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.core.sources;
23 |
24 | import com.insightfullogic.honest_profiler.core.MachineListener;
25 |
26 | public interface MachineSource
27 | {
28 | void poll(MachineListener listener);
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/core/sources/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | *
22 | * Core implementation for methods of discovering machines and sources of logs.
23 | *
24 | * Core implementation for methods of discovering machines and sources of logs.
25 | *
26 | * Core implementation for methods of discovering machines and sources of logs.
27 | */
28 |
29 | /**
30 | * Core implementation for methods of discovering machines and sources of logs.
31 | */
32 | package com.insightfullogic.honest_profiler.core.sources;
33 |
34 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/ports/LoggerInjector.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.ports;
23 |
24 | import org.picocontainer.PicoContainer;
25 | import org.picocontainer.injectors.FactoryInjector;
26 | import org.picocontainer.injectors.InjectInto;
27 | import org.slf4j.Logger;
28 | import org.slf4j.LoggerFactory;
29 |
30 | import java.lang.reflect.Type;
31 |
32 | public class LoggerInjector extends FactoryInjector
33 | {
34 | @Override
35 | public Logger getComponentInstance(PicoContainer container, Type into)
36 | {
37 | Class> cls = getClass(into);
38 | if (cls == null)
39 | {
40 | cls = ((InjectInto) into).getIntoClass();
41 | }
42 | return LoggerFactory.getLogger(cls);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/ports/console/Console.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.ports.console;
23 |
24 | import org.fusesource.jansi.Ansi;
25 |
26 | import java.io.PrintStream;
27 | import java.util.function.Function;
28 |
29 | import static org.fusesource.jansi.Ansi.ansi;
30 |
31 | public interface Console
32 | {
33 |
34 | PrintStream stream();
35 |
36 | default void eraseScreen()
37 | {
38 | write(a -> a.eraseScreen().reset());
39 | }
40 |
41 | default void write(Function func)
42 | {
43 | stream().println(func.apply(ansi()));
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/ports/console/MachinePickerView.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.ports.console;
23 |
24 | import com.insightfullogic.honest_profiler.core.sources.VirtualMachine;
25 | import org.fusesource.jansi.Ansi;
26 |
27 | import java.util.List;
28 |
29 | import static org.fusesource.jansi.Ansi.Color.DEFAULT;
30 | import static org.fusesource.jansi.Ansi.Color.GREEN;
31 |
32 | public class MachinePickerView
33 | {
34 |
35 | private final Terminal terminal;
36 |
37 | public MachinePickerView(final Terminal terminal)
38 | {
39 | this.terminal = terminal;
40 | }
41 |
42 | public void renderAll(final List machines)
43 | {
44 | terminal.eraseScreen();
45 | renderHeader();
46 | for (int i = 0; i < machines.size(); i++)
47 | {
48 | render(machines.get(i), i);
49 | }
50 | }
51 |
52 | public void renderHeader()
53 | {
54 | terminal.write(a -> a.bold().a("Virtual Machines:\n").boldOff());
55 | }
56 |
57 | public void render(final VirtualMachine machine, final int index)
58 | {
59 | boolean agentLoaded = machine.isAgentLoaded();
60 | Ansi.Color color = agentLoaded ? GREEN : DEFAULT;
61 | String prefix = agentLoaded ? index + ": " : " - ";
62 | terminal.write(a -> a.fg(color)
63 | .a(prefix)
64 | .a(machine.getDisplayName())
65 | .reset());
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/ports/console/ProfileScreen.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014-2015 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.ports.console;
23 |
24 | import com.insightfullogic.honest_profiler.core.Monitor;
25 | import com.insightfullogic.honest_profiler.core.sources.VirtualMachine;
26 |
27 | /**
28 | * .
29 | */
30 | public class ProfileScreen implements Screen
31 | {
32 |
33 | private final VirtualMachine machine;
34 | private final Screen previousScreen;
35 | private final Terminal terminal;
36 | private final ProfileView profileView;
37 |
38 | public ProfileScreen(VirtualMachine machine, Screen previousScreen, Terminal terminal)
39 | {
40 | this.machine = machine;
41 | this.previousScreen = previousScreen;
42 | this.terminal = terminal;
43 |
44 | profileView = new ProfileView(terminal);
45 | profileView.setProfileFormat(ProfileFormat.FLAT_BY_METHOD);
46 | }
47 |
48 | @Override
49 | public void onShow()
50 | {
51 | Monitor.pipeFile(machine.getLogSource(), profileView);
52 | }
53 |
54 | @Override
55 | public void handleInput(int input)
56 | {
57 | if (input == '<')
58 | {
59 | terminal.display(previousScreen);
60 | }
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/ports/console/ProfileView.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.ports.console;
23 |
24 | import com.insightfullogic.honest_profiler.core.profiles.Profile;
25 | import com.insightfullogic.honest_profiler.core.profiles.ProfileListener;
26 |
27 | import java.io.PrintStream;
28 |
29 | import static com.insightfullogic.honest_profiler.ports.console.ProfileFormat.ALL;
30 |
31 | public class ProfileView implements ProfileListener
32 | {
33 |
34 | private final Console output;
35 |
36 | private ProfileFormat profileFormat = ALL;
37 |
38 | public ProfileView(Console output)
39 | {
40 | this.output = output;
41 | }
42 |
43 | @Override
44 | public void accept(Profile profile)
45 | {
46 | PrintStream out = output.stream();
47 | printHeader(profile, out);
48 | out.println();
49 | profileFormat.printProfile(profile, out);
50 | out.println();
51 | }
52 |
53 | private void printHeader(Profile profile, PrintStream out)
54 | {
55 | out.print("Number of stack traces: ");
56 | out.print(Integer.toString(profile.getTraceCount()));
57 | }
58 |
59 | public void setProfileFormat(ProfileFormat profileFormat)
60 | {
61 | this.profileFormat = profileFormat;
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/ports/console/Screen.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 | package com.insightfullogic.honest_profiler.ports.console;
23 |
24 | /**
25 | * .
26 | */
27 | public interface Screen
28 | {
29 |
30 | default void onShow()
31 | {
32 | }
33 |
34 | default void onHide()
35 | {
36 | }
37 |
38 | void handleInput(int input);
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/ports/javafx/UserInterfaceConfigurationException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com)
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included
12 | * in all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | **/
22 |
23 | package com.insightfullogic.honest_profiler.ports.javafx;
24 |
25 | public class UserInterfaceConfigurationException extends RuntimeException
26 | {
27 | /**
28 | * Serial Version UID
29 | */
30 | private static final long serialVersionUID = 3285965573715557555L;
31 |
32 | public UserInterfaceConfigurationException(Throwable cause)
33 | {
34 | super(cause);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/ports/javafx/ViewType.java:
--------------------------------------------------------------------------------
1 | package com.insightfullogic.honest_profiler.ports.javafx;
2 |
3 | public enum ViewType
4 | {
5 | FLAT("Flat View"), TREE("Tree View"), FLAME("Flame View");
6 |
7 | private String name;
8 |
9 | private ViewType(String displayName)
10 | {
11 | name = displayName;
12 | }
13 |
14 | @Override
15 | public String toString()
16 | {
17 | return name;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/ports/javafx/controller/dialog/AbstractDialogController.java:
--------------------------------------------------------------------------------
1 | package com.insightfullogic.honest_profiler.ports.javafx.controller.dialog;
2 |
3 | import java.util.Optional;
4 |
5 | import com.insightfullogic.honest_profiler.ports.javafx.controller.AbstractController;
6 |
7 | import javafx.scene.control.ButtonType;
8 | import javafx.scene.control.Dialog;
9 | import javafx.util.Callback;
10 |
11 | /**
12 | * Abstract superclass for DialogController implementations.
13 | *
14 | *
15 | * @param the return type of the {@link Dialog}
16 | */
17 | public abstract class AbstractDialogController extends AbstractController
18 | {
19 | private Dialog dialog;
20 |
21 | /**
22 | * This method must be called by subclasses in their FXML initialize().
23 | *
24 | * The idea is to streamline similar tasks happening in the initialization method, and encourage decluttering of the
25 | * initialize() methods by extracting similar tasks to separate methods.
26 | */
27 | protected void initialize(Dialog dialog)
28 | {
29 | super.initialize();
30 |
31 | this.dialog = dialog;
32 | dialog.setResultConverter(createResultHandler());
33 | }
34 |
35 | public void show()
36 | {
37 | this.dialog.show();
38 | }
39 |
40 | public Optional showAndWait()
41 | {
42 | return this.dialog.showAndWait();
43 | }
44 |
45 | public abstract Callback createResultHandler();
46 |
47 | public abstract void reset();
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/ports/javafx/model/task/AggregateProfileTask.java:
--------------------------------------------------------------------------------
1 | package com.insightfullogic.honest_profiler.ports.javafx.model.task;
2 |
3 | import com.insightfullogic.honest_profiler.core.aggregation.AggregationProfile;
4 | import com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfile;
5 | import com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfileListener;
6 | import com.insightfullogic.honest_profiler.ports.javafx.model.ProfileContext;
7 |
8 | import javafx.concurrent.Task;
9 |
10 | /**
11 | * Background task which aggregates a back-end {@link LeanProfile} into an {@link AggregationProfile} for the front-end.
12 | *
13 | * It also serves the important function of decoupling the back-end thread which invokes the {@link LeanProfileListener}
14 | * accept(LeanProfile) method from the front-end threads : the task will be submitted for processing on a worker thread
15 | * by the back-end thread. When the task finishes, it invokes its succeeded() method on the FX thread.
16 | *
17 | */
18 | public class AggregateProfileTask extends Task
19 | {
20 | // Instance Properties
21 |
22 | private ProfileContext context;
23 | private LeanProfile leanProfile;
24 |
25 | // Instance Constructors
26 |
27 | /**
28 | * Constructor which specifies the {@link ProfileContext} which will receive the resulting
29 | * {@link AggregationProfile}, and the {@link LeanProfile} being aggregated.
30 | *
31 | * @param context the {@link ProfileContext} which will receive the resulting {@link AggregationProfile}
32 | * @param leanProfile the {@link LeanProfile} being aggregated
33 | */
34 | public AggregateProfileTask(ProfileContext context, LeanProfile leanProfile)
35 | {
36 | super();
37 | this.context = context;
38 | this.leanProfile = leanProfile;
39 | }
40 |
41 | @Override
42 | protected AggregationProfile call() throws Exception
43 | {
44 | return new AggregationProfile(leanProfile);
45 | }
46 |
47 | // Guaranteed to be called on the FX thread.
48 | @Override
49 | protected void succeeded()
50 | {
51 | super.succeeded();
52 | context.update(this.getValue());
53 | }
54 |
55 | // Guaranteed to be called on the FX thread.
56 | @Override
57 | protected void failed()
58 | {
59 | super.failed();
60 | getException().printStackTrace();
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/ports/javafx/util/ConversionUtil.java:
--------------------------------------------------------------------------------
1 | package com.insightfullogic.honest_profiler.ports.javafx.util;
2 |
3 | import static java.util.EnumSet.allOf;
4 |
5 | import javafx.util.StringConverter;
6 |
7 | /**
8 | * Utility class for various conversions.
9 | */
10 | public final class ConversionUtil
11 | {
12 | // Class Properties
13 |
14 | private static final long NS_TO_MS = 1000 * 1000;
15 |
16 | // Class Methods
17 |
18 | /**
19 | * Convert the specified number of nanoseconds to number of milliseconds, ignoring the fractional part of the
20 | * result.
21 | *
22 | * @param nanos the number of nanoseconds
23 | * @return the number of milliseconds
24 | */
25 | public static final long toMillis(long nanos)
26 | {
27 | return nanos / NS_TO_MS;
28 | }
29 |
30 | /**
31 | * Generates a {@link StringConverter} for an {@link Enum}, converting between the String representation obtained by
32 | * calling {@link Enum#toString()} and the {@link Enum} value.
33 | *
34 | * @param the type of the {@link Enum} subclass
35 | * @param type the type of the {@link Enum} subclass.
36 | * @return a {@link StringConverter} which converts between {@link Enum} values and their {@link Enum#toString()}
37 | * representations
38 | */
39 | public static > StringConverter getStringConverterForType(Class type)
40 | {
41 | return new StringConverter()
42 | {
43 | @Override
44 | public String toString(T type)
45 | {
46 | return type == null ? "" : type.toString();
47 | }
48 |
49 | @Override
50 | public T fromString(String name)
51 | {
52 | return name == null ? null
53 | : allOf(type).stream().filter(type -> type.toString().equals(name)).findFirst()
54 | .get();
55 | }
56 | };
57 | }
58 |
59 | // Instance Constructors
60 |
61 | /**
62 | * Private Constructor for utility class
63 | */
64 | private ConversionUtil()
65 | {
66 | // Private Constructor for utility class
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/ports/javafx/util/FontUtil.java:
--------------------------------------------------------------------------------
1 | package com.insightfullogic.honest_profiler.ports.javafx.util;
2 |
3 | import static javafx.scene.text.Font.loadFont;
4 |
5 | import javafx.scene.text.Font;
6 |
7 | /**
8 | * Utility class for managing {@link Font}s.
9 | */
10 | public final class FontUtil
11 | {
12 | // Class Properties
13 |
14 | private static final String PATH_OPENSANS_REGULAR = "/com/insightfullogic/honest_profiler/ports/javafx/font/OpenSans-Regular.ttf";
15 | private static final String PATH_OPENSANS_BOLD = "/com/insightfullogic/honest_profiler/ports/javafx/font/OpenSans-Bold.ttf";
16 |
17 | private static Font OPENSANS_REGULAR;
18 | private static Font OPENSANS_BOLD;
19 |
20 | // Class Methods
21 |
22 | /**
23 | * Loads the fonts included in the resources.
24 | *
25 | * @param c a {@link Class} used for resolving the font URLs.
26 | */
27 | public static void initialize(Class> c)
28 | {
29 | OPENSANS_REGULAR = loadFont(c.getResource(PATH_OPENSANS_REGULAR).toExternalForm(), 10);
30 | OPENSANS_BOLD = loadFont(c.getResource(PATH_OPENSANS_BOLD).toExternalForm(), 10);
31 | }
32 |
33 | /**
34 | * Returns the Open Sans Regular {@link Font}.
35 | *
36 | * @return the Open Sans Regular {@link Font}
37 | */
38 | public static final Font openSansRegular()
39 | {
40 | return OPENSANS_REGULAR;
41 | }
42 |
43 | /**
44 | * Returns the Open Sans Bold {@link Font}.
45 | *
46 | * @return the Open Sans Bold {@link Font}
47 | */
48 | public static final Font openSansBold()
49 | {
50 | return OPENSANS_BOLD;
51 | }
52 |
53 | // Instance Constructors
54 |
55 | /**
56 | * Private Utility Class Constructor.
57 | */
58 | private FontUtil()
59 | {
60 | // Private Utility Class Constructor
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/com/insightfullogic/honest_profiler/ports/javafx/util/MenuUtil.java:
--------------------------------------------------------------------------------
1 | package com.insightfullogic.honest_profiler.ports.javafx.util;
2 |
3 | import javafx.collections.ObservableList;
4 | import javafx.event.ActionEvent;
5 | import javafx.event.EventHandler;
6 | import javafx.scene.control.Menu;
7 | import javafx.scene.control.MenuItem;
8 |
9 | /**
10 | * Utility class which offers convenience methods for working with {@link Menu}s and related objects.
11 | */
12 | public final class MenuUtil
13 | {
14 | // Class Methods
15 |
16 | /**
17 | * Add a {@link MenuItem} with the specified label and {@link EventHandler} to the specified {@link ObservableList}.
18 | *
19 | * This is a convenience method for significantly condensing menu creation code.
20 | *
21 | * @param menu an {@link ObservableList} of {@link MenuItem}s the new item will be added to
22 | * @param label the label for the new {@link MenuItem}
23 | * @param handler the {@link EventHandler} which is invoked when the {@link MenuItem} is selected
24 | */
25 | public static void addMenuItem(ObservableList