├── .clang-format ├── .gitignore ├── .travis.yml ├── ATTRIBUTIONS ├── AUTHORS ├── CMakeLists.txt ├── COPYING ├── LICENSE ├── README.md ├── pom.xml └── src ├── assembly └── zip.xml ├── main ├── cpp │ ├── agent.cpp │ ├── circular_queue.cpp │ ├── circular_queue.h │ ├── common.cpp │ ├── common.h │ ├── concurrent_map.cpp │ ├── concurrent_map.h │ ├── control.cpp │ ├── controller.cpp │ ├── controller.h │ ├── globals.h │ ├── log_writer.cpp │ ├── log_writer.h │ ├── processor.cpp │ ├── processor.h │ ├── profiler.cpp │ ├── profiler.h │ ├── signal_handler.cpp │ ├── signal_handler.h │ ├── stacktraces.h │ ├── thread_map.cpp │ ├── thread_map.h │ └── trace.h ├── java │ ├── AgentApiExample.java │ ├── Example.java │ ├── InfiniteExample.java │ └── com │ │ └── insightfullogic │ │ └── honest_profiler │ │ ├── core │ │ ├── Box.java │ │ ├── Conductor.java │ │ ├── MachineListener.java │ │ ├── Monitor.java │ │ ├── ProfileUpdateModerator.java │ │ ├── ThreadedAgent.java │ │ ├── aggregation │ │ │ ├── AggregationProfile.java │ │ │ ├── ReferenceMode.java │ │ │ ├── ReferenceUtil.java │ │ │ ├── aggregator │ │ │ │ ├── AncestorTreeAggregator.java │ │ │ │ ├── DescendantFlatAggregator.java │ │ │ │ ├── DescendantTreeAggregator.java │ │ │ │ ├── FlatProfileAggregator.java │ │ │ │ ├── ProfileAggregator.java │ │ │ │ ├── SubAggregator.java │ │ │ │ └── TreeProfileAggregator.java │ │ │ ├── filter │ │ │ │ ├── Comparison.java │ │ │ │ ├── FilterItem.java │ │ │ │ ├── FilterPredicate.java │ │ │ │ ├── FilterSpecification.java │ │ │ │ ├── Target.java │ │ │ │ └── ValueType.java │ │ │ ├── grouping │ │ │ │ ├── CombinedGrouping.java │ │ │ │ ├── FrameGrouping.java │ │ │ │ └── ThreadGrouping.java │ │ │ ├── package-info.java │ │ │ └── result │ │ │ │ ├── Aggregation.java │ │ │ │ ├── ItemType.java │ │ │ │ ├── Keyed.java │ │ │ │ ├── Parent.java │ │ │ │ ├── diff │ │ │ │ ├── AbstractDiff.java │ │ │ │ ├── DiffEntry.java │ │ │ │ ├── DiffNode.java │ │ │ │ ├── FlatDiff.java │ │ │ │ └── TreeDiff.java │ │ │ │ └── straight │ │ │ │ ├── Entry.java │ │ │ │ ├── Flat.java │ │ │ │ ├── Node.java │ │ │ │ └── Tree.java │ │ ├── collector │ │ │ ├── CallCountAggregator.java │ │ │ ├── CallCounts.java │ │ │ ├── FlameGraphCollector.java │ │ │ ├── FlatProfileEntry.java │ │ │ ├── Frame.java │ │ │ ├── FullFrame.java │ │ │ ├── LogCollector.java │ │ │ ├── NodeCollector.java │ │ │ └── lean │ │ │ │ ├── LeanLogCollector.java │ │ │ │ └── ProfileSource.java │ │ ├── control │ │ │ └── Agent.java │ │ ├── filters │ │ │ ├── ClassNameFilter.java │ │ │ ├── Filter.java │ │ │ ├── FilterParseException.java │ │ │ ├── Filters.java │ │ │ ├── MethodNameFilter.java │ │ │ ├── ProfileFilter.java │ │ │ ├── SelfTimeShareFilter.java │ │ │ ├── StringFilter.java │ │ │ ├── ThreadSampleFilter.java │ │ │ ├── TimeShareFilter.java │ │ │ └── TotalTimeShareFilter.java │ │ ├── package-info.java │ │ ├── parser │ │ │ ├── LogEvent.java │ │ │ ├── LogEventListener.java │ │ │ ├── LogEventPublisher.java │ │ │ ├── LogParser.java │ │ │ ├── Method.java │ │ │ ├── StackFrame.java │ │ │ ├── ThreadMeta.java │ │ │ └── TraceStart.java │ │ ├── platform │ │ │ └── Platforms.java │ │ ├── profiles │ │ │ ├── FlameGraph.java │ │ │ ├── FlameGraphListener.java │ │ │ ├── FlameTrace.java │ │ │ ├── Profile.java │ │ │ ├── ProfileListener.java │ │ │ ├── ProfileNode.java │ │ │ ├── ProfileTree.java │ │ │ └── lean │ │ │ │ ├── LeanNode.java │ │ │ │ ├── LeanProfile.java │ │ │ │ ├── LeanProfileListener.java │ │ │ │ ├── LeanThreadNode.java │ │ │ │ ├── info │ │ │ │ ├── FrameInfo.java │ │ │ │ ├── MethodInfo.java │ │ │ │ ├── NumericInfo.java │ │ │ │ └── ThreadInfo.java │ │ │ │ └── package-info.java │ │ └── sources │ │ │ ├── CantReadFromSourceException.java │ │ │ ├── LogSource.java │ │ │ ├── MachineSource.java │ │ │ ├── VirtualMachine.java │ │ │ └── package-info.java │ │ └── ports │ │ ├── LoggerInjector.java │ │ ├── console │ │ ├── Console.java │ │ ├── ConsoleApplication.java │ │ ├── ConsoleLogDumpApplication.java │ │ ├── FlameGraphDumperApplication.java │ │ ├── MachinePicker.java │ │ ├── MachinePickerView.java │ │ ├── ProfileFormat.java │ │ ├── ProfileScreen.java │ │ ├── ProfileView.java │ │ ├── Screen.java │ │ └── Terminal.java │ │ ├── javafx │ │ ├── JavaFXApplication.java │ │ ├── UserInterfaceConfigurationException.java │ │ ├── ViewType.java │ │ ├── controller │ │ │ ├── AbstractController.java │ │ │ ├── AbstractProfileDiffViewController.java │ │ │ ├── AbstractProfileViewController.java │ │ │ ├── AbstractViewController.java │ │ │ ├── FlameDiffViewController.java │ │ │ ├── FlameViewController.java │ │ │ ├── FlatDiffViewController.java │ │ │ ├── FlatViewController.java │ │ │ ├── ProfileDiffRootController.java │ │ │ ├── ProfileRootController.java │ │ │ ├── RootController.java │ │ │ ├── TreeDiffViewController.java │ │ │ ├── TreeViewController.java │ │ │ ├── dialog │ │ │ │ └── AbstractDialogController.java │ │ │ └── filter │ │ │ │ ├── FilterCreationDialogController.java │ │ │ │ └── FilterDialogController.java │ │ ├── model │ │ │ ├── ApplicationContext.java │ │ │ ├── ProfileContext.java │ │ │ └── task │ │ │ │ ├── AggregateProfileTask.java │ │ │ │ └── InitializeProfileTask.java │ │ ├── util │ │ │ ├── BindUtil.java │ │ │ ├── ContextMenuUtil.java │ │ │ ├── ConversionUtil.java │ │ │ ├── DialogUtil.java │ │ │ ├── FontUtil.java │ │ │ ├── FxUtil.java │ │ │ ├── MenuUtil.java │ │ │ ├── ResourceUtil.java │ │ │ ├── StyleUtil.java │ │ │ ├── TreeUtil.java │ │ │ ├── extraction │ │ │ │ ├── FlatExtractor.java │ │ │ │ └── TreeExtractor.java │ │ │ ├── handle │ │ │ │ ├── AbstractListenerHandle.java │ │ │ │ ├── ChangeListenerHandle.java │ │ │ │ ├── InvalidationListenerHandle.java │ │ │ │ └── ListenerHandle.java │ │ │ ├── report │ │ │ │ ├── ReportUtil.java │ │ │ │ └── Table.java │ │ │ └── validation │ │ │ │ └── StringValidationListener.java │ │ └── view │ │ │ ├── Icon.java │ │ │ ├── Rendering.java │ │ │ ├── cell │ │ │ ├── CountTableCell.java │ │ │ ├── CountTreeTableCell.java │ │ │ ├── GraphicalShareTableCell.java │ │ │ ├── GraphicalShareTreeTableCell.java │ │ │ ├── MethodNameTableCell.java │ │ │ ├── MethodNameTreeTableCell.java │ │ │ ├── PercentageTableCell.java │ │ │ ├── PercentageTreeTableCell.java │ │ │ ├── TimeTableCell.java │ │ │ └── TimeTreeTableCell.java │ │ │ ├── flame │ │ │ ├── AbstractFlameCanvas.java │ │ │ ├── FlameBlock.java │ │ │ ├── FlameDiffViewCanvas.java │ │ │ └── FlameViewCanvas.java │ │ │ ├── menu │ │ │ ├── ColumnGroupMenuItem.java │ │ │ └── ColumnMenuItem.java │ │ │ └── tree │ │ │ ├── DiffNodeTreeItem.java │ │ │ └── NodeTreeItem.java │ │ └── sources │ │ ├── FileLogSource.java │ │ ├── LocalMachineSource.java │ │ ├── WebSocketMachineSource.java │ │ └── package-info.java ├── resources │ └── com │ │ └── insightfullogic │ │ └── honest_profiler │ │ └── ports │ │ └── javafx │ │ ├── css │ │ └── HPUI.css │ │ ├── font │ │ ├── OpenSans-Bold.ttf │ │ └── OpenSans-Regular.ttf │ │ ├── fxml │ │ ├── FilterCreationDialog.fxml │ │ ├── FilterDialog.fxml │ │ ├── FlameDiffView.fxml │ │ ├── FlameView.fxml │ │ ├── FlatDiffView.fxml │ │ ├── FlatView.fxml │ │ ├── ProfileDiffRoot.fxml │ │ ├── ProfileRoot.fxml │ │ ├── Root.fxml │ │ ├── TreeDiffView.fxml │ │ └── TreeView.fxml │ │ ├── i18n │ │ └── HPUIBundle_en.properties │ │ └── icon │ │ └── icon16 │ │ ├── arrow-in.png │ │ ├── arrow-out.png │ │ ├── balance-unbalance.png │ │ ├── clock--exclamation.png │ │ ├── clock.png │ │ ├── document-binary.png │ │ ├── document-import.png │ │ ├── eye--exclamation.png │ │ ├── eye.png │ │ ├── funnel--exclamation.png │ │ ├── funnel.png │ │ ├── minus-white.png │ │ ├── monitor.png │ │ └── plus-white.png └── scripts │ ├── console │ ├── dump-flamegraph │ └── gui └── test ├── cpp ├── fixtures.h ├── ostreambuf.h ├── test.cpp ├── test.h ├── test_agent.cpp ├── test_circular_queue.cpp ├── test_log_writer.cpp ├── test_maps.cpp ├── test_profiler_config.cpp └── test_thread_map.cpp ├── java └── com │ └── insightfullogic │ └── honest_profiler │ ├── core │ ├── ConductorTest.java │ ├── Util.java │ ├── aggregation │ │ ├── AggregationProfileTest.java │ │ ├── aggregator │ │ │ ├── AncestorTreeAggregatorTest.java │ │ │ ├── DescendantFlatAggregatorTest.java │ │ │ ├── DescendantTreeAggregatorTest.java │ │ │ ├── FlatDiffAggregatorTest.java │ │ │ ├── FlatProfileAggregatorTest.java │ │ │ ├── TreeDiffAggregatorTest.java │ │ │ └── TreeProfileAggregatorTest.java │ │ └── filter │ │ │ ├── FlatFilterTest.java │ │ │ └── TreeFilterTest.java │ ├── collector │ │ ├── FakeProfileListener.java │ │ ├── FlatProfileTest.java │ │ ├── LogCollectorTest.java │ │ ├── ProfileTreeTest.java │ │ └── lean │ │ │ └── LeanLogCollectorTest.java │ └── filters │ │ ├── ClassNameFilterTest.java │ │ ├── FilterParserTest.java │ │ └── ThreadSampleFilterTest.java │ ├── framework │ ├── AggregationUtil.java │ ├── LeanLogCollectorDriver.java │ ├── LogEventFactory.java │ ├── ParameterUtil.java │ ├── checker │ │ ├── CheckAdapter.java │ │ ├── DiffCheckAdapter.java │ │ ├── FlatCheckAdapter.java │ │ ├── FlatDiffCheckAdapter.java │ │ ├── FlatDiffTableViewCheckAdapter.java │ │ ├── FlatTableViewCheckAdapter.java │ │ ├── TreeCheckAdapter.java │ │ ├── TreeDiffCheckAdapter.java │ │ ├── TreeDiffTableViewCheckAdapter.java │ │ └── TreeTableViewCheckAdapter.java │ ├── generator │ │ ├── FlatGenerator.java │ │ ├── LeanProfileGenerator.java │ │ ├── ProfileContextGenerator.java │ │ └── TreeGenerator.java │ └── scenario │ │ ├── FltScenario.java │ │ ├── LogScenario.java │ │ ├── Scenario01.java │ │ ├── Scenario02.java │ │ ├── Scenario03.java │ │ ├── Scenario04.java │ │ ├── Scenario05.java │ │ ├── Scenario06.java │ │ ├── Scenario07.java │ │ ├── Scenario08.java │ │ ├── ScenarioDiffFilter.java │ │ ├── ScenarioStraightFilter.java │ │ └── SimplifiedLogScenario.java │ ├── ports │ ├── console │ │ ├── ConsoleApplicationTest.java │ │ ├── FakeConsole.java │ │ ├── MachinePickerTest.java │ │ ├── ProfileViewTest.java │ │ └── TerminalTest.java │ ├── javafx │ │ ├── controller │ │ │ ├── FlatDiffViewTest.java │ │ │ ├── FlatViewQuickFilterTest.java │ │ │ ├── FlatViewTest.java │ │ │ ├── SampleCountTest.java │ │ │ ├── TreeDiffViewTest.java │ │ │ ├── TreeViewQuickFilterTest.java │ │ │ └── TreeViewTest.java │ │ └── framework │ │ │ ├── AbstractJavaFxTest.java │ │ │ └── HPFXUtil.java │ └── sources │ │ ├── FileLogSourceTest.java │ │ └── LocalMachineSourceTest.java │ ├── system_tests │ └── AgentIntegrationTest.java │ └── testing_utilities │ ├── AgentRunner.java │ ├── LargeStacktracesExample.java │ ├── NonInteractiveAgentRunner.java │ ├── ProfileFixtures.java │ ├── SleepingThreadExample.java │ └── VirtualMachineFixtures.java └── resources ├── alex_log_16_07_2014.hpl.gz ├── example.hpl └── log0.hpl /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # binaries 3 | build* 4 | target/ 5 | 6 | # Gradle 7 | .gradle 8 | !build.gradle 9 | 10 | # vim 11 | *.swp 12 | 13 | # JDK crashes 14 | hs_err_pid* 15 | 16 | # output files 17 | log-*.hpl 18 | dump.hpl 19 | traces.txt 20 | 21 | # IDE 22 | .idea 23 | *.iml 24 | 25 | logs/* 26 | !.gitkeep 27 | node_modules/ 28 | bower_components/ 29 | tmp 30 | .DS_Store 31 | 32 | src/test/resources/private_logs/ 33 | 34 | # CMake 35 | CMakeFiles/ 36 | CMakeCache.txt 37 | CTestTestfile.cmake 38 | cmake_install.cmake 39 | Makefile 40 | Testing 41 | 42 | /.classpath 43 | /.project 44 | .settings 45 | 46 | /bin/ 47 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | matrix: 3 | include: 4 | - os: linux 5 | dist: trusty 6 | sudo: required 7 | compiler: gcc 8 | - os: linux 9 | dist: trusty 10 | sudo: required 11 | compiler: clang 12 | - os: osx 13 | osx_image: xcode7.3 14 | compiler: gcc 15 | - os: osx 16 | osx_image: xcode7.3 17 | compiler: clang 18 | - os: osx 19 | osx_image: xcode9 20 | compiler: gcc 21 | - os: osx 22 | osx_image: xcode9 23 | compiler: clang 24 | - os: osx 25 | osx_image: xcode9.3 26 | compiler: clang 27 | env: 28 | - EXT_CXX_FLAGS="-fsanitize=address -DDEBUG_MAP_GC" ASAN_OPTIONS="detect_odr_violation=0" 29 | branches: 30 | only: 31 | - master 32 | - stage 33 | before_install: 34 | - if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get update && sudo apt-get install -y libunittest++-dev; fi 35 | - if [ $TRAVIS_OS_NAME == osx ]; then brew update && brew install unittest-cpp && brew uninstall cmake && brew install cmake; fi 36 | - if [ $TRAVIS_OS_NAME == osx ]; then export UNITTEST_INCLUDE_DIRS=/usr/local/Cellar/unittest-cpp/; fi 37 | - g++ --version 38 | - clang++ --version 39 | - java -version 40 | install: cmake CMakeLists.txt 41 | script: make && build/unitTests 42 | after_script: rm -f *.hpl *.log 43 | -------------------------------------------------------------------------------- /ATTRIBUTIONS: -------------------------------------------------------------------------------- 1 | All icons used in the JavaFX UI are from the Fugue icon pack by Yusuke Kamiyamane, licensed under a Creative Commons Attribution 3.0 License. 2 | 3 | Source URL: http://http://p.yusukekamiyamane.com/ 4 | Copyright: 5 | License: http://creativecommons.org/licenses/by/3.0/ -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Google Inc. 2 | Richard Warburton 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2014 Richard Warburton (richard.warburton@gmail.com), Google 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | honest-profiler 2 | =============== 3 | [![Build Status](https://travis-ci.org/jvm-profiling-tools/honest-profiler.svg?branch=master)](https://travis-ci.org/jvm-profiling-tools/honest-profiler) 4 | 5 | A usable and honest profiler for the JVM. For documentation please refer to 6 | [The Wiki](https://github.com/RichardWarburton/honest-profiler/wiki) 7 | 8 | * [Download the Binary](http://insightfullogic.com/honest-profiler.zip) 9 | * [How to Build](https://github.com/RichardWarburton/honest-profiler/wiki/How-to-build) 10 | -------------------------------------------------------------------------------- /src/assembly/zip.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | zip 6 | 7 | / 8 | 9 | 10 | zip 11 | 12 | 13 | 14 | 15 | 16 | ${basedir}/src/main/scripts 17 | / 18 | 19 | 20 | 21 | ${project.build.directory} 22 | 23 | honest-profiler.jar 24 | 25 | / 26 | 27 | 28 | 29 | ${basedir}/build 30 | 31 | liblagent.so 32 | liblagent.dylib 33 | 34 | / 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/main/cpp/circular_queue.h: -------------------------------------------------------------------------------- 1 | // Somewhat originally dervied from: 2 | // http://www.codeproject.com/Articles/43510/Lock-Free-Single-Producer-Single-Consumer-Circular 3 | 4 | // Multiple Producer, Single Consumer Queue 5 | 6 | #ifndef CIRCULAR_QUEUE_H 7 | #define CIRCULAR_QUEUE_H 8 | 9 | #include "thread_map.h" 10 | #include "stacktraces.h" 11 | #include 12 | #include 13 | #include 14 | 15 | const size_t Size = 1024; 16 | 17 | // Capacity is 1 larger than size to make sure 18 | // we can use input = output as our "can't read" invariant 19 | // and advance(output) = input as our "can't write" invariant 20 | // effective the gap acts as a sentinel 21 | const size_t Capacity = Size + 1; 22 | 23 | class QueueListener { 24 | public: 25 | virtual void record(const timespec &ts, const JVMPI_CallTrace &item, ThreadBucketPtr info = ThreadBucketPtr(nullptr)) = 0; 26 | 27 | virtual ~QueueListener() {} 28 | }; 29 | 30 | const int COMMITTED = 1; 31 | const int UNCOMMITTED = 0; 32 | 33 | struct TraceHolder { 34 | timespec tspec; 35 | std::atomic is_committed; 36 | JVMPI_CallTrace trace; 37 | ThreadBucketPtr info; 38 | 39 | TraceHolder() : info(nullptr) { 40 | } 41 | }; 42 | 43 | class CircularQueue { 44 | public: 45 | explicit CircularQueue(QueueListener &listener, int maxFrameSize) 46 | : listener_(listener), input(0), output(0) { 47 | memset(buffer, 0, sizeof(buffer)); 48 | for (int i = 0; i < Capacity; ++i) 49 | frame_buffer_[i] = new JVMPI_CallFrame[maxFrameSize](); 50 | } 51 | 52 | ~CircularQueue() { 53 | for (int i = 0; i < Capacity; ++i) 54 | delete[] frame_buffer_[i]; 55 | } 56 | 57 | bool push(const timespec &ts, const JVMPI_CallTrace &item, ThreadBucketPtr info = ThreadBucketPtr(nullptr)); 58 | 59 | bool push(const JVMPI_CallTrace &item, ThreadBucketPtr info = ThreadBucketPtr(nullptr)); 60 | 61 | bool pop(); 62 | 63 | private: 64 | 65 | QueueListener &listener_; 66 | 67 | std::atomic input; 68 | std::atomic output; 69 | 70 | TraceHolder buffer[Capacity]; 71 | JVMPI_CallFrame *frame_buffer_[Capacity]; 72 | 73 | size_t advance(size_t index) const; 74 | 75 | void write(const JVMPI_CallTrace &item, const size_t slot); 76 | }; 77 | 78 | #endif /* CIRCULAR_QUEUE_H */ 79 | -------------------------------------------------------------------------------- /src/main/cpp/common.cpp: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | jthread newThread(JNIEnv *jniEnv, const char *threadName) { 4 | jclass thrClass; 5 | jmethodID cid; 6 | jthread res; 7 | 8 | thrClass = jniEnv->FindClass("java/lang/Thread"); 9 | if (thrClass == NULL) { 10 | logError("WARN: Cannot find Thread class\n"); 11 | } 12 | cid = jniEnv->GetMethodID(thrClass, "", "()V"); 13 | if (cid == NULL) { 14 | logError("WARN: Cannot find Thread constructor method\n"); 15 | } 16 | res = jniEnv->NewObject(thrClass, cid); 17 | if (res == NULL) { 18 | logError("WARN: Cannot create new Thread object\n"); 19 | } else { 20 | jmethodID mid = jniEnv->GetMethodID(thrClass, "setName", "(Ljava/lang/String;)V"); 21 | jniEnv->CallObjectMethod(res, mid, jniEnv->NewStringUTF(threadName)); 22 | } 23 | return res; 24 | } 25 | 26 | JNIEnv *getJNIEnv(JavaVM *jvm) { 27 | JNIEnv *jniEnv = NULL; 28 | int getEnvStat = jvm->GetEnv((void **) &jniEnv, JNI_VERSION_1_6); 29 | // check for issues 30 | if (getEnvStat == JNI_EDETACHED || getEnvStat == JNI_EVERSION) { 31 | jniEnv = NULL; 32 | } 33 | return jniEnv; 34 | } 35 | -------------------------------------------------------------------------------- /src/main/cpp/common.h: -------------------------------------------------------------------------------- 1 | #ifndef HONEST_PROFILER_COMMON_H 2 | #define HONEST_PROFILER_COMMON_H 3 | 4 | #include 5 | #include "globals.h" 6 | 7 | jthread newThread(JNIEnv *jniEnv, const char *threadName); 8 | 9 | JNIEnv *getJNIEnv(JavaVM *jvm); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /src/main/cpp/concurrent_map.cpp: -------------------------------------------------------------------------------- 1 | #include "concurrent_map.h" 2 | 3 | namespace map { 4 | 5 | TRACE_DEFINE_BEGIN(LFMap, kTraceLFMapTotal) 6 | TRACE_DEFINE("[LockFreeMapPrimitives::find] Item not found") 7 | TRACE_DEFINE("[LockFreeMapPrimitives::find] Item found") 8 | TRACE_DEFINE("[LockFreeMapPrimitives::insertOrUpdate] Max number of jumps reached") 9 | TRACE_DEFINE("[LockFreeMapPrimitives::insertOrUpdate] Update bucket value") 10 | TRACE_DEFINE("[LockFreeMapPrimitives::insertOrUpdate] Update value race detected") 11 | TRACE_DEFINE("[LockFreeMapPrimitives::insertOrUpdate] Can't allocate a cell, map is too full") 12 | TRACE_DEFINE("[LockFreeMapPrimitives::insertOrUpdate] Allocate fresh bucket") 13 | TRACE_DEFINE("[LockFreeMapPrimitives::insertOrUpdate] Allocation race detected") 14 | TRACE_DEFINE("[LockFreeMapPrimitives::insertOrUpdate] Set bucket value") 15 | TRACE_DEFINE("[LockFreeMapPrimitives::insertOrUpdate] Set value race detected") 16 | TRACE_DEFINE("[LockFreeMapPrimitives::insertOrUpdate] No empty cell in the neighbourhood") 17 | TRACE_DEFINE("[LockFreeMapProvider::remove] Item not found") 18 | TRACE_DEFINE("[LockFreeMapProvider::remove] Remove bucket's value") 19 | TRACE_DEFINE("[LockFreeMapProvider::remove] Remove value race detected (giving up)") 20 | TRACE_DEFINE("[LockFreeMapProvider::migrationStart#1] Conflicting migration found") 21 | TRACE_DEFINE("[LockFreeMapProvider::migrationStart#2] Conflicting migration found") 22 | TRACE_DEFINE("[Migration::run] Can't participate in job that already ended") 23 | TRACE_DEFINE("[Migration::run] Migration interrupted by end of job") 24 | TRACE_DEFINE("[Migration::run] Overflow detected during migration") 25 | TRACE_DEFINE("[Migration::run] Data was migrated completely") 26 | TRACE_DEFINE("[Migration::run] No more blocks to migrate") 27 | TRACE_DEFINE("[Migration::run] Not the last thread") 28 | TRACE_DEFINE("[Migration::run] Publishing successful migration") 29 | TRACE_DEFINE("[Migration::run] Starting successful overflow migration") 30 | TRACE_DEFINE("[Migration::run] Overflow migration already started before") 31 | TRACE_DEFINE("[Migration::migrateRange] Unallocated cell migration flag") 32 | TRACE_DEFINE("[Migration::migrateRange] Unallocated cell insert race") 33 | TRACE_DEFINE("[Migration::migrateRange] Allocated cell value insert race") 34 | TRACE_DEFINE("[Migration::migrateRange] Allocated cell migration flag") 35 | TRACE_DEFINE("[Migration::migrateRange] Destination insert overflow when migrating a bucket") 36 | TRACE_DEFINE("[Migration::migrateRange] Racing erase when migrating allocated bucket") 37 | TRACE_DEFINE_END(LFMap, kTraceLFMapTotal); 38 | 39 | const GC::EpochType GC::kEpochInitial = -1; 40 | 41 | GC DefaultGC; 42 | } -------------------------------------------------------------------------------- /src/main/cpp/controller.h: -------------------------------------------------------------------------------- 1 | #ifndef HONEST_PROFILER_CONTROLLER_H 2 | #define HONEST_PROFILER_CONTROLLER_H 3 | 4 | #include "globals.h" 5 | #include "common.h" 6 | #include "profiler.h" 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #define MAX_DATA_SIZE 100 19 | 20 | class Controller { 21 | public: 22 | explicit Controller(JavaVM *jvm, jvmtiEnv *jvmti, Profiler *profiler, ConfigurationOptions &configuration) : 23 | jvm_(jvm), jvmti_(jvmti), profiler_(profiler), configuration_(configuration), isRunning_(false) { 24 | 25 | } 26 | 27 | void start(); 28 | 29 | void stop(); 30 | 31 | void run(); 32 | 33 | bool isRunning() const; 34 | 35 | private: 36 | JavaVM *const jvm_; 37 | jvmtiEnv *const jvmti_; 38 | Profiler *const profiler_; 39 | 40 | const ConfigurationOptions &configuration_; 41 | std::atomic_bool isRunning_; 42 | 43 | void startSampling(); 44 | 45 | void stopSampling(); 46 | 47 | void reportStatus(int clientConnection); 48 | 49 | void getProfilerParam(int clientConnection, char *param); 50 | 51 | void setProfilerParam(char *paramDesc); 52 | }; 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/main/cpp/processor.h: -------------------------------------------------------------------------------- 1 | #ifndef PROCESSOR_H 2 | #define PROCESSOR_H 3 | 4 | #include 5 | #include "common.h" 6 | #include "log_writer.h" 7 | #include "signal_handler.h" 8 | 9 | #include "trace.h" 10 | 11 | const int kTraceProcessorTotal = 3; 12 | 13 | const int kTraceProcessorStart = 0; 14 | const int kTraceProcessorStop = 1; 15 | const int kTraceProcessorRunning = 2; 16 | 17 | TRACE_DECLARE(Processor, kTraceProcessorTotal); 18 | 19 | class Processor { 20 | 21 | public: 22 | explicit Processor(jvmtiEnv* jvmti, LogWriter& logWriter, const ConfigurationOptions &conf) 23 | : jvmti_(jvmti), config(conf), logWriter_(logWriter), 24 | buffer(logWriter_, config.maxFramesToCapture), 25 | handler(config.samplingIntervalMin, config.samplingIntervalMax), 26 | isRunning_(false) { 27 | interval_ = Size * config.samplingIntervalMin / 1000 / 2; 28 | interval_ = interval_ > 0 ? interval_ : 1; 29 | } 30 | 31 | bool start(JNIEnv *jniEnv); 32 | 33 | void run(); 34 | 35 | void stop(); 36 | 37 | bool isRunning() const; 38 | 39 | void handle(JNIEnv *jni_env, const timespec& ts, ThreadBucketPtr threadInfo, void *context); 40 | 41 | private: 42 | jvmtiEnv *const jvmti_; 43 | 44 | const ConfigurationOptions &config; 45 | 46 | LogWriter& logWriter_; 47 | CircularQueue buffer; 48 | SignalHandler handler; 49 | 50 | std::atomic_bool isRunning_; 51 | std::atomic_flag workerDone; 52 | 53 | int interval_; 54 | 55 | void startCallback(jvmtiEnv *jvmti_env, JNIEnv *jni_env, void *arg); 56 | 57 | void sleep(uint period); 58 | 59 | DISALLOW_COPY_AND_ASSIGN(Processor); 60 | }; 61 | 62 | #endif // PROCESSOR_H 63 | -------------------------------------------------------------------------------- /src/main/cpp/signal_handler.cpp: -------------------------------------------------------------------------------- 1 | #include "signal_handler.h" 2 | 3 | namespace { 4 | 5 | // Helper class to store and reset errno when in a signal handler. 6 | class ErrnoRaii { 7 | public: 8 | ErrnoRaii() { 9 | stored_errno_ = errno; 10 | } 11 | 12 | ~ErrnoRaii() { 13 | errno = stored_errno_; 14 | } 15 | 16 | private: 17 | int stored_errno_; 18 | 19 | DISALLOW_COPY_AND_ASSIGN(ErrnoRaii); 20 | }; 21 | } // namespace 22 | 23 | bool SignalHandler::updateSigprofInterval() { 24 | bool res = updateSigprofInterval(timingIntervals[intervalIndex]); 25 | intervalIndex = (intervalIndex + 1) % NUMBER_OF_INTERVALS; 26 | return res; 27 | } 28 | 29 | bool SignalHandler::updateSigprofInterval(const int timingInterval) { 30 | if (timingInterval == currentInterval) 31 | return true; 32 | static struct itimerval timer; 33 | // timingInterval is in milliseconds, not seconds. 34 | timer.it_interval.tv_sec = timingInterval / 1000; 35 | timer.it_interval.tv_usec = (timingInterval * 1000) % 1000000; 36 | timer.it_value = timer.it_interval; 37 | if (setitimer(ITIMER_PROF, &timer, 0) == -1) { 38 | logError("Scheduling profiler interval failed with error %d\n", errno); 39 | return false; 40 | } 41 | currentInterval = timingInterval; 42 | return true; 43 | } 44 | 45 | struct sigaction SignalHandler::SetAction(void (*action)(int, siginfo_t *, void *)) { 46 | struct sigaction sa; 47 | #ifdef __clang__ 48 | #pragma clang diagnostic push 49 | #pragma clang diagnostic ignored "-Wdisabled-macro-expansion" 50 | #endif 51 | sa.sa_handler = NULL; 52 | sa.sa_sigaction = action; 53 | sa.sa_flags = SA_RESTART | SA_SIGINFO; 54 | #ifdef __clang__ 55 | #pragma clang diagnostic pop 56 | #endif 57 | 58 | sigemptyset(&sa.sa_mask); 59 | 60 | struct sigaction old_handler; 61 | if (sigaction(SIGPROF, &sa, &old_handler) != 0) { 62 | logError("Scheduling profiler action failed with error %d\n", errno); 63 | return old_handler; 64 | } 65 | 66 | return old_handler; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /src/main/cpp/signal_handler.h: -------------------------------------------------------------------------------- 1 | #ifndef SIGNAL_HANDLER_H 2 | #define SIGNAL_HANDLER_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include "globals.h" 16 | 17 | const int NUMBER_OF_INTERVALS = 1024; 18 | 19 | class SignalHandler { 20 | public: 21 | SignalHandler(const int samplingIntervalMin, const int samplingIntervalMax) 22 | : intervalIndex(0), currentInterval(-1), timingIntervals() { 23 | srand (time(NULL)); 24 | int range = samplingIntervalMax - samplingIntervalMin + 1; 25 | for (auto it = timingIntervals.begin(); it != timingIntervals.end(); ++it) { 26 | *it = samplingIntervalMin + rand() % range; 27 | } 28 | } 29 | 30 | struct sigaction SetAction(void (*sigaction)(int, siginfo_t *, void *)); 31 | 32 | bool updateSigprofInterval(); 33 | 34 | bool updateSigprofInterval(int); 35 | 36 | bool stopSigprof() { return updateSigprofInterval(0); } 37 | 38 | ~SignalHandler() {} 39 | 40 | private: 41 | int intervalIndex; 42 | int currentInterval; 43 | std::array timingIntervals; 44 | 45 | DISALLOW_COPY_AND_ASSIGN(SignalHandler); 46 | }; 47 | 48 | 49 | #endif // SIGNAL_HANDLER_H 50 | -------------------------------------------------------------------------------- /src/main/cpp/stacktraces.h: -------------------------------------------------------------------------------- 1 | #include "globals.h" 2 | 3 | #ifndef STACKTRACES_H 4 | #define STACKTRACES_H 5 | 6 | // To implement the profiler, we rely on an undocumented function called 7 | // AsyncGetCallTrace in the Java virtual machine, which is used by Sun 8 | // Studio Analyzer, and designed to get stack traces asynchronously. 9 | // It uses the old JVMPI interface, so we must reconstruct the 10 | // neccesary bits of that here. 11 | 12 | // For a Java frame, the lineno is the bci of the method, and the 13 | // method_id is the jmethodID. For a JNI method, the lineno is -3, 14 | // and the method_id is the jmethodID. 15 | typedef struct { 16 | jint lineno; 17 | jmethodID method_id; 18 | } JVMPI_CallFrame; 19 | 20 | typedef struct { 21 | // JNIEnv of the thread from which we grabbed the trace 22 | JNIEnv *env_id; 23 | // < 0 if the frame isn't walkable 24 | jint num_frames; 25 | // The frames, callee first. 26 | JVMPI_CallFrame *frames; 27 | } JVMPI_CallTrace; 28 | 29 | typedef void (*ASGCTType)(JVMPI_CallTrace *, jint, void *); 30 | 31 | const int kNumCallTraceErrors = 10; 32 | 33 | enum CallTraceErrors { 34 | // 0 is reserved for native stack traces. This includes JIT and GC threads. 35 | kNativeStackTrace = 0, 36 | // The JVMTI class load event is disabled (a prereq for AsyncGetCallTrace) 37 | kNoClassLoad = -1, 38 | // For traces in GC 39 | kGcTraceError = -2, 40 | // We can't figure out what the top (non-Java) frame is 41 | kUnknownNotJava = -3, 42 | // The frame is not Java and not walkable 43 | kNotWalkableFrameNotJava = -4, 44 | // We can't figure out what the top Java frame is 45 | kUnknownJava = -5, 46 | // The frame is Java and not walkable 47 | kNotWalkableFrameJava = -6, 48 | // Unknown thread state (not in Java or native or the VM) 49 | kUnknownState = -7, 50 | // The JNIEnv is bad - this likely means the thread has exited 51 | kTicksThreadExit = -8, 52 | // The thread is being deoptimized, so the stack is borked 53 | kDeoptHandler = -9, 54 | // We're in a safepoint, and can't do reporting 55 | kSafepoint = -10, 56 | }; 57 | 58 | // Wrapper to hold reference to AsyncGetCallTrace function 59 | class Asgct { 60 | public: 61 | static void SetAsgct(ASGCTType asgct) { 62 | asgct_ = asgct; 63 | } 64 | 65 | // AsyncGetCallTrace function, to be dlsym'd. 66 | static ASGCTType GetAsgct() { 67 | return asgct_; 68 | } 69 | 70 | private: 71 | static ASGCTType asgct_; 72 | 73 | DISALLOW_IMPLICIT_CONSTRUCTORS(Asgct); 74 | }; 75 | 76 | #endif // STACKTRACES_H 77 | -------------------------------------------------------------------------------- /src/main/cpp/thread_map.cpp: -------------------------------------------------------------------------------- 1 | #include "thread_map.h" 2 | 3 | #include 4 | #include 5 | 6 | #ifdef __APPLE__ 7 | #include 8 | #endif 9 | 10 | // taken from Wine's get_unix_tid 11 | int gettid() { 12 | int ret = -1; 13 | #if defined(__linux__) 14 | ret = syscall(SYS_gettid); 15 | #elif defined(__APPLE__) 16 | // ret = pthread_getthreadid_np(); 17 | ret = mach_thread_self(); 18 | mach_port_deallocate(mach_task_self(), ret); 19 | #elif defined(__NetBSD__) 20 | ret = _lwp_self(); 21 | #elif defined(__FreeBSD__) 22 | long lwpid; 23 | thr_self(&lwpid); 24 | ret = lwpid; 25 | #elif defined(__DragonFly__) 26 | ret = lwp_gettid(); 27 | #else 28 | ret = pthread_self(); 29 | #endif 30 | return ret; 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/Example.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 | 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 | *

31 | * @param source the {@link LeanThreadNode} being copied. 32 | */ 33 | private LeanThreadNode(LeanThreadNode source) 34 | { 35 | super(source, null); 36 | this.threadInfo = source.threadInfo; 37 | } 38 | 39 | // Instance Accessors 40 | 41 | @Override 42 | public boolean isThreadNode() 43 | { 44 | return true; 45 | } 46 | 47 | /** 48 | * Returns the {@link ThreadInfo} metadata for the represented thread. 49 | *

50 | * @return the {@link ThreadInfo} metadata for the represented thread 51 | */ 52 | public ThreadInfo getThreadInfo() 53 | { 54 | return threadInfo; 55 | } 56 | 57 | /** 58 | * Sets the {@link ThreadInfo} metadata for the represented thread. 59 | *

60 | * @param threadInfo the {@link ThreadInfo} metadata for the represented thread 61 | */ 62 | public void setThreadInfo(ThreadInfo threadInfo) 63 | { 64 | this.threadInfo = threadInfo; 65 | } 66 | 67 | // Copy Methods 68 | 69 | public LeanThreadNode copy() 70 | { 71 | return new LeanThreadNode(this); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/insightfullogic/honest_profiler/core/sources/CantReadFromSourceException.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.core.sources; 2 | 3 | public class CantReadFromSourceException extends RuntimeException 4 | { 5 | public CantReadFromSourceException(final Throwable cause) 6 | { 7 | super(cause); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/insightfullogic/honest_profiler/core/sources/LogSource.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 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 menu, String label, 26 | EventHandler handler) 27 | { 28 | MenuItem menuItem = new MenuItem(label); 29 | menuItem.setOnAction(handler); 30 | menu.add(menuItem); 31 | } 32 | 33 | // Instance Constructors 34 | 35 | /** 36 | * Empty Constructor for utility class. 37 | */ 38 | private MenuUtil() 39 | { 40 | // Empty Constructor for utility class 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/insightfullogic/honest_profiler/ports/javafx/util/extraction/FlatExtractor.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.ports.javafx.util.extraction; 2 | 3 | import java.util.function.Function; 4 | 5 | import com.insightfullogic.honest_profiler.core.aggregation.AggregationProfile; 6 | import com.insightfullogic.honest_profiler.core.aggregation.grouping.CombinedGrouping; 7 | import com.insightfullogic.honest_profiler.core.aggregation.result.straight.Flat; 8 | import com.insightfullogic.honest_profiler.ports.javafx.util.BindUtil; 9 | 10 | import javafx.beans.value.ObservableObjectValue; 11 | 12 | /** 13 | * {@link Function} which retrieves the {@link Flat} aggregation for the specified {@link CombinedGrouping} from an 14 | * {@link AggregationProfile}, for use in {@link BindUtil}. 15 | */ 16 | public class FlatExtractor implements Function 17 | { 18 | // Instance Properties 19 | 20 | private final ObservableObjectValue grouping; 21 | 22 | // Instance Constructors 23 | 24 | /** 25 | * Constructor specifying the {@link CombinedGrouping} to be used when aggregating. 26 | *

27 | * @param grouping the {@link CombinedGrouping} to be used when aggregating 28 | */ 29 | public FlatExtractor(ObservableObjectValue grouping) 30 | { 31 | super(); 32 | this.grouping = grouping; 33 | } 34 | 35 | @Override 36 | public Flat apply(Object t) 37 | { 38 | return t == null ? null : ((AggregationProfile)t).getFlat(grouping.get()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/insightfullogic/honest_profiler/ports/javafx/util/extraction/TreeExtractor.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.ports.javafx.util.extraction; 2 | 3 | import java.util.function.Function; 4 | 5 | import com.insightfullogic.honest_profiler.core.aggregation.AggregationProfile; 6 | import com.insightfullogic.honest_profiler.core.aggregation.grouping.CombinedGrouping; 7 | import com.insightfullogic.honest_profiler.core.aggregation.result.straight.Tree; 8 | import com.insightfullogic.honest_profiler.ports.javafx.util.BindUtil; 9 | 10 | import javafx.beans.value.ObservableObjectValue; 11 | 12 | /** 13 | * {@link Function} which retrieves the {@link Tree} aggregation for the specified {@link CombinedGrouping} from an 14 | * {@link AggregationProfile}, for use in {@link BindUtil}. 15 | */ 16 | public class TreeExtractor implements Function 17 | { 18 | // Instance Properties 19 | 20 | ObservableObjectValue grouping; 21 | 22 | // Instance Constructors 23 | 24 | /** 25 | * Constructor specifying the {@link CombinedGrouping} to be used when aggregating. 26 | *

27 | * @param grouping the {@link CombinedGrouping} to be used when aggregating 28 | */ 29 | public TreeExtractor(ObservableObjectValue grouping) 30 | { 31 | super(); 32 | this.grouping = grouping; 33 | } 34 | 35 | @Override 36 | public Tree apply(Object t) 37 | { 38 | return t == null ? null : ((AggregationProfile)t).getTree(grouping.get()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/insightfullogic/honest_profiler/ports/javafx/util/handle/ChangeListenerHandle.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.ports.javafx.util.handle; 2 | 3 | import javafx.beans.value.ChangeListener; 4 | import javafx.beans.value.ObservableValue; 5 | 6 | /** 7 | * Trivial {@link AbstractListenerHandle} implementation for {@link ChangeListener}s and {@link ObservableValue}s 8 | * encapsulating {@link Object}s of type T. 9 | *

10 | * @param the type of the {@link Object} encapsulated by the {@link ObservableValue} 11 | */ 12 | public class ChangeListenerHandle 13 | extends AbstractListenerHandle, ChangeListener> 14 | { 15 | // Instance Constructors 16 | 17 | /** 18 | * @see AbstractListenerHandle#AbstractListenerHandle(javafx.beans.Observable, Object) 19 | *

20 | * @param observable the {@link ObservableValue} the listener will be added to 21 | * @param listener the listener 22 | */ 23 | public ChangeListenerHandle(ObservableValue observable, ChangeListener listener) 24 | { 25 | super(observable, listener); 26 | } 27 | 28 | // AbstractListenerHandle Implementation 29 | 30 | @Override 31 | protected void addListener(ObservableValue observable, ChangeListener listener) 32 | { 33 | observable.addListener(listener); 34 | } 35 | 36 | @Override 37 | protected void removeListener(ObservableValue observable, ChangeListener listener) 38 | { 39 | observable.removeListener(listener); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/insightfullogic/honest_profiler/ports/javafx/util/handle/InvalidationListenerHandle.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.ports.javafx.util.handle; 2 | 3 | import javafx.beans.InvalidationListener; 4 | import javafx.beans.Observable; 5 | 6 | /** 7 | * Trivial {@link AbstractListenerHandle} implementation for {@link InvalidationListener}s and {@link Observable}s.. 8 | */ 9 | public class InvalidationListenerHandle 10 | extends AbstractListenerHandle 11 | { 12 | // Instance Constructors 13 | 14 | /** 15 | * @see AbstractListenerHandle#AbstractListenerHandle(javafx.beans.Observable, Object) 16 | *

17 | * @param observable the {@link Observable} the listener will be added to 18 | * @param listener the listener 19 | */ 20 | public InvalidationListenerHandle(Observable observable, InvalidationListener listener) 21 | { 22 | super(observable, listener); 23 | } 24 | 25 | // AbstractListenerHandle Implementation 26 | 27 | @Override 28 | protected void addListener(Observable observable, InvalidationListener listener) 29 | { 30 | observable.addListener(listener); 31 | } 32 | 33 | @Override 34 | protected void removeListener(Observable observable, InvalidationListener listener) 35 | { 36 | observable.removeListener(listener); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/insightfullogic/honest_profiler/ports/javafx/util/handle/ListenerHandle.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.ports.javafx.util.handle; 2 | 3 | import javafx.beans.InvalidationListener; 4 | import javafx.beans.Observable; 5 | import javafx.beans.value.ChangeListener; 6 | 7 | /** 8 | * Interface which facilitates binding {@link ChangeListener}s or {@link InvalidationListener}s to and unbinding them 9 | * from an {@link Observable}. 10 | *

11 | * Based on the pattern mentioned by "Don’t Remove 12 | * Listeners – Use ListenerHandles". A short quote : 13 | *

14 | * 15 | * The ListenerHandle holds on to the references to the observable and the listener. Upon calls to attach() or detach() 16 | * it either adds the listener to the observable or removes it. For this to be embedded in the language, all methods 17 | * which currently add listeners to observables should return a handle to that combination. 18 | * 19 | *

20 | * This was extended to allow reattaching the handle to a different {@link Observable}. 21 | *

22 | * @param T the type of Observable the handle can reattach the listener to 23 | */ 24 | public interface ListenerHandle 25 | { 26 | /** 27 | * Add the contained listener to the contained {@link Observable}. If the listener has already been added to an 28 | * {@link Observable}, {@link #detach()} will be called first. If the contained {@link Observable} is null the 29 | * method returns without doing anything. 30 | */ 31 | void attach(); 32 | 33 | /** 34 | * Remove the contained listener from the contained {@link Observable} if the handle is attached. 35 | */ 36 | void detach(); 37 | 38 | /** 39 | * Remove the contained listener from the currently contained {@link Observable}, switch the contained 40 | * {@link Observable} to the new, specified {@link Observable} and add the contained listener to it. 41 | *

42 | * @param observable the {@link Observable} the listener will be added to 43 | */ 44 | void reattach(T observable); 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/insightfullogic/honest_profiler/ports/javafx/view/Icon.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.ports.javafx.view; 2 | 3 | import javafx.scene.image.Image; 4 | import javafx.scene.image.ImageView; 5 | 6 | public final class Icon 7 | { 8 | private static final String ICON_16_DIR = "/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/"; 9 | 10 | public static final Image PLUS_16 = toImage(ICON_16_DIR + "plus-white.png"); 11 | public static final Image MINUS_16 = toImage(ICON_16_DIR + "minus-white.png"); 12 | 13 | public static final Image FUNNEL_16 = toImage(ICON_16_DIR + "funnel.png"); 14 | public static final Image FUNNEL_ACTIVE_16 = toImage(ICON_16_DIR + "funnel--exclamation.png"); 15 | 16 | public static final Image EXPAND_16 = toImage(ICON_16_DIR + "arrow-out.png"); 17 | public static final Image COLLAPSE_16 = toImage(ICON_16_DIR + "arrow-in.png"); 18 | 19 | public static final Image COMPARE_16 = toImage(ICON_16_DIR + "balance-unbalance.png"); 20 | 21 | public static final Image EXPORT_16 = toImage(ICON_16_DIR + "document-import.png"); 22 | 23 | public static final Image LIVE_16 = toImage(ICON_16_DIR + "monitor.png"); 24 | public static final Image LOG_16 = toImage(ICON_16_DIR + "document-binary.png"); 25 | 26 | public static final Image FREEZE_16 = toImage(ICON_16_DIR + "clock.png"); 27 | public static final Image UNFREEZE_16 = toImage(ICON_16_DIR + "clock--exclamation.png"); 28 | 29 | public static final Image VIEW_16 = toImage(ICON_16_DIR + "eye.png"); 30 | public static final Image VIEW_ACTIVE_16 = toImage(ICON_16_DIR + "eye--exclamation.png"); 31 | 32 | private static Image toImage(String resource) 33 | { 34 | return new Image(Icon.class.getResourceAsStream(resource)); 35 | } 36 | 37 | public static ImageView viewFor(Image image) 38 | { 39 | return new ImageView(image); 40 | } 41 | 42 | private Icon() 43 | { 44 | // Empty Utility Class Constructor 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/insightfullogic/honest_profiler/ports/javafx/view/Rendering.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.ports.javafx.view; 20 | 21 | import java.text.MessageFormat; 22 | 23 | import com.insightfullogic.honest_profiler.core.collector.Frame; 24 | import com.insightfullogic.honest_profiler.core.parser.Method; 25 | 26 | public final class Rendering 27 | { 28 | 29 | public static String renderPercentage(double percentage) 30 | { 31 | return MessageFormat.format("{0,number,0.00 %}", percentage); 32 | } 33 | 34 | public static String renderMethod(Frame method) 35 | { 36 | if (method == null) 37 | { 38 | return "unknown"; 39 | } 40 | 41 | return method.getClassName() + "." + method.getMethodName(); 42 | } 43 | 44 | public static String renderShortMethod(Method method) 45 | { 46 | String className = method.getClassName(); 47 | int index = className.lastIndexOf('.'); 48 | String shortClassName = index == -1 ? className : className.substring(index + 1); 49 | return shortClassName + "." + method.getMethodName(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/insightfullogic/honest_profiler/ports/javafx/view/cell/CountTableCell.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.ports.javafx.view.cell; 20 | 21 | import static javafx.geometry.Pos.CENTER_RIGHT; 22 | import static javafx.scene.text.TextAlignment.RIGHT; 23 | 24 | import java.util.function.Function; 25 | 26 | import javafx.scene.control.TableCell; 27 | 28 | public class CountTableCell extends TableCell 29 | { 30 | private Function styleFunction; 31 | 32 | public CountTableCell(Function styleFunction) 33 | { 34 | super(); 35 | 36 | setTextAlignment(RIGHT); 37 | setAlignment(CENTER_RIGHT); 38 | 39 | this.styleFunction = styleFunction; 40 | } 41 | 42 | @Override 43 | protected void updateItem(Number item, boolean isEmpty) 44 | { 45 | if (isEmpty || item == null) 46 | { 47 | setText(null); 48 | setStyle(null); 49 | return; 50 | } 51 | 52 | setText(item.toString()); 53 | setStyle(styleFunction == null ? null : styleFunction.apply(item)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/insightfullogic/honest_profiler/ports/javafx/view/cell/CountTreeTableCell.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.ports.javafx.view.cell; 20 | 21 | import static javafx.geometry.Pos.CENTER_RIGHT; 22 | import static javafx.scene.text.TextAlignment.RIGHT; 23 | 24 | import java.util.function.Function; 25 | 26 | import javafx.scene.control.TreeTableCell; 27 | 28 | public class CountTreeTableCell extends TreeTableCell 29 | { 30 | private Function styleFunction; 31 | 32 | public CountTreeTableCell(Function styleFunction) 33 | { 34 | super(); 35 | setTextAlignment(RIGHT); 36 | setAlignment(CENTER_RIGHT); 37 | 38 | this.styleFunction = styleFunction; 39 | } 40 | 41 | @Override 42 | protected void updateItem(Number number, boolean isEmpty) 43 | { 44 | if (isEmpty || number == null) 45 | { 46 | setText(null); 47 | setStyle(null); 48 | return; 49 | } 50 | 51 | setText(number.toString()); 52 | setStyle(styleFunction == null ? null : styleFunction.apply(number)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/insightfullogic/honest_profiler/ports/javafx/view/cell/GraphicalShareTableCell.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.ports.javafx.view.cell; 20 | 21 | import static javafx.scene.paint.Color.DARKRED; 22 | 23 | import javafx.scene.control.TableCell; 24 | import javafx.scene.paint.Color; 25 | import javafx.scene.shape.Rectangle; 26 | 27 | public class GraphicalShareTableCell extends TableCell 28 | { 29 | private static final double HEIGHT = 8; 30 | private static final Color COLOR = DARKRED; 31 | 32 | @Override 33 | protected void updateItem(Double share, boolean empty) 34 | { 35 | super.updateItem(share, empty); 36 | 37 | if (empty || share == null) 38 | { 39 | setText(null); 40 | setGraphic(null); 41 | return; 42 | } 43 | 44 | setGraphic(new Rectangle(share * getWidth(), HEIGHT, COLOR)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/insightfullogic/honest_profiler/ports/javafx/view/cell/MethodNameTableCell.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.ports.javafx.view.cell; 20 | 21 | import static com.insightfullogic.honest_profiler.ports.javafx.util.StyleUtil.STYLE_METHOD_NAME; 22 | 23 | import javafx.scene.control.TableCell; 24 | 25 | public class MethodNameTableCell extends TableCell 26 | { 27 | @Override 28 | protected void updateItem(String value, boolean isEmpty) 29 | { 30 | super.updateItem(value, isEmpty); 31 | 32 | if (isEmpty || value == null) 33 | { 34 | setText(null); 35 | setStyle(null); 36 | return; 37 | } 38 | 39 | setStyle(STYLE_METHOD_NAME); 40 | setText(value); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/insightfullogic/honest_profiler/ports/javafx/view/cell/MethodNameTreeTableCell.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.ports.javafx.view.cell; 2 | 3 | import static com.insightfullogic.honest_profiler.ports.javafx.util.ContextMenuUtil.bindContextMenuForTreeTableCell; 4 | import static com.insightfullogic.honest_profiler.ports.javafx.util.StyleUtil.STYLE_METHOD_NAME; 5 | 6 | import com.insightfullogic.honest_profiler.ports.javafx.model.ApplicationContext; 7 | 8 | import javafx.scene.control.TreeTableCell; 9 | 10 | public class MethodNameTreeTableCell extends TreeTableCell 11 | { 12 | public MethodNameTreeTableCell(ApplicationContext appCtx) 13 | { 14 | super(); 15 | bindContextMenuForTreeTableCell(appCtx, this); 16 | } 17 | 18 | @Override 19 | protected void updateItem(String item, boolean empty) 20 | { 21 | super.updateItem(item, empty); 22 | 23 | if (empty) 24 | { 25 | setText(null); 26 | setGraphic(null); 27 | return; 28 | } 29 | setStyle(STYLE_METHOD_NAME); 30 | setText(item); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/insightfullogic/honest_profiler/ports/javafx/view/cell/PercentageTableCell.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.ports.javafx.view.cell; 20 | 21 | import static com.insightfullogic.honest_profiler.ports.javafx.view.Rendering.renderPercentage; 22 | import static javafx.geometry.Pos.CENTER_RIGHT; 23 | import static javafx.scene.text.TextAlignment.RIGHT; 24 | 25 | import java.util.function.Function; 26 | 27 | import javafx.scene.control.TableCell; 28 | 29 | public class PercentageTableCell extends TableCell 30 | { 31 | private Function styleFunction; 32 | 33 | public PercentageTableCell(Function styleFunction) 34 | { 35 | super(); 36 | 37 | setTextAlignment(RIGHT); 38 | setAlignment(CENTER_RIGHT); 39 | 40 | this.styleFunction = styleFunction; 41 | } 42 | 43 | @Override 44 | protected void updateItem(Number item, boolean isEmpty) 45 | { 46 | if (isEmpty || item == null) 47 | { 48 | setText(null); 49 | setStyle(null); 50 | return; 51 | } 52 | 53 | setText(renderPercentage(item.doubleValue())); 54 | setStyle(this.styleFunction == null ? null : this.styleFunction.apply(item)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/insightfullogic/honest_profiler/ports/javafx/view/cell/PercentageTreeTableCell.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.ports.javafx.view.cell; 20 | 21 | import static com.insightfullogic.honest_profiler.ports.javafx.view.Rendering.renderPercentage; 22 | import static javafx.geometry.Pos.CENTER_RIGHT; 23 | import static javafx.scene.text.TextAlignment.RIGHT; 24 | 25 | import java.util.function.Function; 26 | 27 | import javafx.scene.control.TreeTableCell; 28 | 29 | public class PercentageTreeTableCell extends TreeTableCell 30 | { 31 | private Function styleFunction; 32 | 33 | public PercentageTreeTableCell(Function styleFunction) 34 | { 35 | super(); 36 | 37 | setTextAlignment(RIGHT); 38 | setAlignment(CENTER_RIGHT); 39 | 40 | this.styleFunction = styleFunction; 41 | } 42 | 43 | @Override 44 | protected void updateItem(Number number, boolean isEmpty) 45 | { 46 | if (isEmpty || number == null) 47 | { 48 | setText(null); 49 | setStyle(null); 50 | return; 51 | } 52 | 53 | setText(renderPercentage(number.doubleValue())); 54 | setStyle(styleFunction == null ? null : styleFunction.apply(number)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/insightfullogic/honest_profiler/ports/javafx/view/cell/TimeTableCell.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.ports.javafx.view.cell; 20 | 21 | import static com.insightfullogic.honest_profiler.ports.javafx.util.ConversionUtil.toMillis; 22 | import static javafx.geometry.Pos.CENTER_RIGHT; 23 | import static javafx.scene.text.TextAlignment.RIGHT; 24 | 25 | import java.util.function.Function; 26 | 27 | import javafx.scene.control.TableCell; 28 | 29 | public class TimeTableCell extends TableCell 30 | { 31 | private Function styleFunction; 32 | 33 | public TimeTableCell(Function styleFunction) 34 | { 35 | super(); 36 | 37 | setTextAlignment(RIGHT); 38 | setAlignment(CENTER_RIGHT); 39 | 40 | this.styleFunction = styleFunction; 41 | } 42 | 43 | @Override 44 | protected void updateItem(Number item, boolean isEmpty) 45 | { 46 | if (isEmpty || item == null) 47 | { 48 | setText(null); 49 | setStyle(null); 50 | return; 51 | } 52 | 53 | setText(Long.toString(toMillis(item.longValue()))); 54 | setStyle(styleFunction == null ? null : styleFunction.apply(item)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/insightfullogic/honest_profiler/ports/javafx/view/cell/TimeTreeTableCell.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.ports.javafx.view.cell; 20 | 21 | import static com.insightfullogic.honest_profiler.ports.javafx.util.ConversionUtil.toMillis; 22 | import static javafx.geometry.Pos.CENTER_RIGHT; 23 | import static javafx.scene.text.TextAlignment.RIGHT; 24 | 25 | import java.util.function.Function; 26 | 27 | import javafx.scene.control.TreeTableCell; 28 | 29 | public class TimeTreeTableCell extends TreeTableCell 30 | { 31 | private Function styleFunction; 32 | 33 | public TimeTreeTableCell(Function styleFunction) 34 | { 35 | super(); 36 | setTextAlignment(RIGHT); 37 | setAlignment(CENTER_RIGHT); 38 | 39 | this.styleFunction = styleFunction; 40 | } 41 | 42 | @Override 43 | protected void updateItem(Number item, boolean isEmpty) 44 | { 45 | if (isEmpty || item == null) 46 | { 47 | setText(null); 48 | setStyle(null); 49 | return; 50 | } 51 | 52 | setText(Long.toString(toMillis(item.longValue()))); 53 | setStyle(styleFunction == null ? null : styleFunction.apply(item)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/insightfullogic/honest_profiler/ports/javafx/view/menu/ColumnGroupMenuItem.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.ports.javafx.view.menu; 2 | 3 | import static java.util.Arrays.asList; 4 | 5 | import java.util.Collection; 6 | import java.util.List; 7 | 8 | import javafx.scene.control.MenuItem; 9 | import javafx.scene.control.TableColumn; 10 | import javafx.scene.control.TableColumnBase; 11 | import javafx.scene.control.TreeTableColumn; 12 | import javafx.scene.text.Text; 13 | 14 | /** 15 | * This {@link MenuItem} subclass changes the visibility of a set of {@link TableColumn}s or {@link TreeTableColumn}s. 16 | * Selecting the item renders all columns visible or invisible. 17 | */ 18 | public class ColumnGroupMenuItem extends MenuItem 19 | { 20 | // Instance Constructors 21 | 22 | /** 23 | * Simple Constructor specifying the menu item text, the visibility and the columns. 24 | * 25 | * @param title the menu item text 26 | * @param visible the visibility of the columns after the menu item has been selected 27 | * @param columns the columns managed by the item 28 | */ 29 | public ColumnGroupMenuItem(String title, boolean visible, TableColumnBase... columns) 30 | { 31 | super(); 32 | 33 | this.setGraphic(new Text(title)); 34 | 35 | List> columnList = asList(columns); 36 | setOnAction(event -> columnList.forEach(column -> column.setVisible(visible))); 37 | } 38 | 39 | /** 40 | * Simple Constructor specifying the menu item text, the visibility and collection of columns. 41 | * 42 | * @param title the menu item text 43 | * @param visible the visibility of the columns after the menu item has been selected 44 | * @param columns the columns managed by the item 45 | */ 46 | public ColumnGroupMenuItem(String title, 47 | boolean visible, 48 | Collection> columns) 49 | { 50 | super(); 51 | 52 | this.setGraphic(new Text(title)); 53 | 54 | setOnAction(event -> columns.forEach(column -> column.setVisible(visible))); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/insightfullogic/honest_profiler/ports/javafx/view/tree/DiffNodeTreeItem.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.ports.javafx.view.tree; 2 | 3 | import com.insightfullogic.honest_profiler.core.aggregation.result.diff.DiffNode; 4 | import com.insightfullogic.honest_profiler.core.aggregation.result.diff.TreeDiff; 5 | 6 | import javafx.scene.control.TreeItem; 7 | 8 | public class DiffNodeTreeItem extends TreeItem 9 | { 10 | public DiffNodeTreeItem(TreeDiff profileDiff) 11 | { 12 | super(null); 13 | for (DiffNode child : profileDiff.getData()) 14 | { 15 | getChildren().add(new DiffNodeTreeItem(child)); 16 | } 17 | } 18 | 19 | public DiffNodeTreeItem(DiffNode diff) 20 | { 21 | super(diff); 22 | for (DiffNode child : diff.getChildren()) 23 | { 24 | getChildren().add(new DiffNodeTreeItem(child)); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/main/java/com/insightfullogic/honest_profiler/ports/javafx/view/tree/NodeTreeItem.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.ports.javafx.view.tree; 2 | 3 | import com.insightfullogic.honest_profiler.core.aggregation.result.Aggregation; 4 | import com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node; 5 | 6 | import javafx.scene.control.TreeItem; 7 | 8 | public class NodeTreeItem extends TreeItem 9 | { 10 | public NodeTreeItem(Aggregation profile) 11 | { 12 | super(null); 13 | profile.getData().forEach(child -> getChildren().add(new NodeTreeItem(child))); 14 | } 15 | 16 | public NodeTreeItem(Node node) 17 | { 18 | super(node); 19 | node.getChildren().forEach(child -> getChildren().add(new NodeTreeItem(child))); 20 | } 21 | } -------------------------------------------------------------------------------- /src/main/java/com/insightfullogic/honest_profiler/ports/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 | * Infrastructure for methods of discovering machines and sources of logs. 23 | *

24 | * Infrastructure for methods of discovering machines and sources of logs. 25 | *

26 | * Infrastructure for methods of discovering machines and sources of logs. 27 | */ 28 | /** 29 | * Infrastructure for methods of discovering machines and sources of logs. 30 | */ 31 | package com.insightfullogic.honest_profiler.ports.sources; 32 | 33 | -------------------------------------------------------------------------------- /src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/css/HPUI.css: -------------------------------------------------------------------------------- 1 | .root { 2 | -fx-font-family: "Open Sans"; 3 | -fx-font-size: 10px; 4 | -fx-font-smoothing-type: lcd; 5 | } 6 | 7 | /* Fix cell heights. Improves performance, and also allows UI calculations. 8 | .table-cell { 9 | -fx-fixed-cell-size: 20px; 10 | } 11 | */ 12 | 13 | /* Fix cell heights. Improves performance, and also allows UI calculations. 14 | .list-cell { 15 | -fx-cell-size: 20px; 16 | } 17 | */ 18 | 19 | .menu-bar { 20 | -fx-font-weight: bold; 21 | } 22 | 23 | .monoSpace { 24 | -fx-font-family: "Open Sans", Consolas, monospace; 25 | -fx-font-size: 11px; 26 | -fx-size: 11px; 27 | -fx-font-smoothing-type: lcd; 28 | } 29 | 30 | .flame { 31 | -fx-font-size: 8px; 32 | } 33 | 34 | .tab-pane:top *.tab-header-area { 35 | -fx-background-insets: 0, 0 0 1 0; 36 | -fx-padding: 0.416667em 0.166667em 0.0em 0.0em; 37 | /* overridden as 5 2 0 0 */ 38 | } 39 | 40 | .tab-pane:left *.tab-header-area { 41 | -fx-background-insets: 0, 0 0 1 0; 42 | -fx-padding: 0px 0px 0px 0px; 43 | /* -fx-padding: 0.416667em 0.166667em 0.0em 0.0em;*/ 44 | /* overridden as 5 2 0 0 */ 45 | } 46 | 47 | .tab-pane:left { 48 | -fx-tab-max-width: 12px; 49 | } 50 | 51 | .tab-content-area { 52 | -fx-padding: 0.0em; /* 0 */ 53 | } 54 | 55 | .tab:selected { 56 | -fx-base: #7eaacc 57 | } 58 | 59 | .tooltip { 60 | /* -fx-font-size: 0.95em; */ 61 | -fx-font-size: 8px; 62 | } -------------------------------------------------------------------------------- /src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/font/OpenSans-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-profiling-tools/honest-profiler/5783ffab6690807783521a1b6dca6e74e77ba853/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/font/OpenSans-Bold.ttf -------------------------------------------------------------------------------- /src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/font/OpenSans-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-profiling-tools/honest-profiler/5783ffab6690807783521a1b6dca6e74e77ba853/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/font/OpenSans-Regular.ttf -------------------------------------------------------------------------------- /src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/fxml/FilterCreationDialog.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |

16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/fxml/FilterDialog.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/fxml/Root.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 |
37 | 38 |
39 | 40 | 41 | 42 | 43 | 44 | 45 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/arrow-in.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-profiling-tools/honest-profiler/5783ffab6690807783521a1b6dca6e74e77ba853/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/arrow-in.png -------------------------------------------------------------------------------- /src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/arrow-out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-profiling-tools/honest-profiler/5783ffab6690807783521a1b6dca6e74e77ba853/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/arrow-out.png -------------------------------------------------------------------------------- /src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/balance-unbalance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-profiling-tools/honest-profiler/5783ffab6690807783521a1b6dca6e74e77ba853/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/balance-unbalance.png -------------------------------------------------------------------------------- /src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/clock--exclamation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-profiling-tools/honest-profiler/5783ffab6690807783521a1b6dca6e74e77ba853/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/clock--exclamation.png -------------------------------------------------------------------------------- /src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/clock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-profiling-tools/honest-profiler/5783ffab6690807783521a1b6dca6e74e77ba853/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/clock.png -------------------------------------------------------------------------------- /src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/document-binary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-profiling-tools/honest-profiler/5783ffab6690807783521a1b6dca6e74e77ba853/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/document-binary.png -------------------------------------------------------------------------------- /src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/document-import.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-profiling-tools/honest-profiler/5783ffab6690807783521a1b6dca6e74e77ba853/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/document-import.png -------------------------------------------------------------------------------- /src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/eye--exclamation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-profiling-tools/honest-profiler/5783ffab6690807783521a1b6dca6e74e77ba853/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/eye--exclamation.png -------------------------------------------------------------------------------- /src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/eye.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-profiling-tools/honest-profiler/5783ffab6690807783521a1b6dca6e74e77ba853/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/eye.png -------------------------------------------------------------------------------- /src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/funnel--exclamation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-profiling-tools/honest-profiler/5783ffab6690807783521a1b6dca6e74e77ba853/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/funnel--exclamation.png -------------------------------------------------------------------------------- /src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/funnel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-profiling-tools/honest-profiler/5783ffab6690807783521a1b6dca6e74e77ba853/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/funnel.png -------------------------------------------------------------------------------- /src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/minus-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-profiling-tools/honest-profiler/5783ffab6690807783521a1b6dca6e74e77ba853/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/minus-white.png -------------------------------------------------------------------------------- /src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/monitor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-profiling-tools/honest-profiler/5783ffab6690807783521a1b6dca6e74e77ba853/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/monitor.png -------------------------------------------------------------------------------- /src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/plus-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-profiling-tools/honest-profiler/5783ffab6690807783521a1b6dca6e74e77ba853/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/icon/icon16/plus-white.png -------------------------------------------------------------------------------- /src/main/scripts/console: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -eu 4 | 5 | java_path=$(readlink -f $(which javac)) 6 | [ -f /usr/libexec/java_home ] && java_home=`/usr/libexec/java_home` || java_home=$(echo ${java_path} | sed 's/javac$//') 7 | tools_path="$java_home/../lib/tools.jar" 8 | [ -f ${tools_path} ] || tools_path="$java_home/lib/tools.jar" 9 | [ -f ${tools_path} ] || (echo "Could not find tools.jar at $java_home/../lib/tools.jar" && exit 1) 10 | 11 | java -cp $tools_path:honest-profiler.jar com.insightfullogic.honest_profiler.ports.console.ConsoleApplication $@ 12 | -------------------------------------------------------------------------------- /src/main/scripts/dump-flamegraph: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -eu 4 | 5 | java_path=$(readlink -f $(which javac)) 6 | [ -f /usr/libexec/java_home ] && java_home=`/usr/libexec/java_home` || java_home=$(echo ${java_path} | sed 's/javac$//') 7 | tools_path="$java_home/../lib/tools.jar" 8 | [ -f ${tools_path} ] || tools_path="$java_home/lib/tools.jar" 9 | [ -f ${tools_path} ] || (echo "Could not find tools.jar at $java_home/../lib/tools.jar" && exit 1) 10 | 11 | java -cp $tools_path:honest-profiler.jar com.insightfullogic.honest_profiler.ports.console.FlameGraphDumperApplication $@ 12 | -------------------------------------------------------------------------------- /src/main/scripts/gui: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -eu 4 | 5 | java_path=$(readlink -f $(which javac)) 6 | [ -f /usr/libexec/java_home ] && java_home=`/usr/libexec/java_home` || java_home=$(echo ${java_path} | sed 's/javac$//') 7 | tools_path="$java_home/../lib/tools.jar" 8 | [ -f ${tools_path} ] || tools_path="$java_home/lib/tools.jar" 9 | [ -f ${tools_path} ] || (echo "Could not find tools.jar at $java_home/../lib/tools.jar" && exit 1) 10 | 11 | java -cp $tools_path:honest-profiler.jar com.insightfullogic.honest_profiler.ports.javafx.JavaFXApplication 12 | 13 | -------------------------------------------------------------------------------- /src/test/cpp/fixtures.h: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | #include "../../main/cpp/circular_queue.h" 3 | 4 | #ifndef FIXTURES_H 5 | #define FIXTURES_H 6 | 7 | class ItemHolder : public QueueListener { 8 | public: 9 | explicit ItemHolder() {} 10 | 11 | void record(const JVMPI_CallTrace &trace, ThreadBucketPtr info) { 12 | timespec spec; 13 | TimeUtils::current_utc_time(&spec); 14 | 15 | record(spec, trace, std::move(info)); 16 | } 17 | 18 | virtual void record(const timespec &ts, const JVMPI_CallTrace &trace, ThreadBucketPtr info) { 19 | CHECK_EQUAL(2, trace.num_frames); 20 | CHECK_EQUAL((JNIEnv *)envId, trace.env_id); 21 | 22 | JVMPI_CallFrame frame0 = trace.frames[0]; 23 | CHECK_EQUAL(52, frame0.lineno); 24 | CHECK_EQUAL((jmethodID)1, frame0.method_id); 25 | } 26 | 27 | long envId; 28 | }; 29 | 30 | // Queue too big to stack allocate, 31 | // So we use a fixture 32 | struct GivenQueue { 33 | GivenQueue() : holder(), queue(holder, DEFAULT_MAX_FRAMES_TO_CAPTURE) { 34 | } 35 | 36 | ~GivenQueue() {} 37 | 38 | ItemHolder holder; 39 | CircularQueue queue; 40 | 41 | // wrap an easy to test api around the queue 42 | bool pop(const long envId) { 43 | holder.envId = envId; 44 | return queue.pop(); 45 | } 46 | }; 47 | 48 | #endif /* FIXTURES_H */ 49 | -------------------------------------------------------------------------------- /src/test/cpp/ostreambuf.h: -------------------------------------------------------------------------------- 1 | #ifndef OSTREAMBUF_H 2 | #define OSTREAMBUF_H 3 | 4 | // based on http://stackoverflow.com/a/1495582/382079 5 | #include 6 | 7 | template 8 | struct ostreambuf : public std::basic_streambuf > 9 | { 10 | ostreambuf(char_type *buffer, std::streamsize bufferLength) 11 | { 12 | // set the "put" pointer the start of the buffer and record its length. 13 | this->setp(buffer, buffer + bufferLength); 14 | } 15 | }; 16 | 17 | #endif /* OSTREAMBUF_H */ 18 | -------------------------------------------------------------------------------- /src/test/cpp/test.cpp: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | 3 | int main() { return UnitTest::RunAllTests(); } 4 | -------------------------------------------------------------------------------- /src/test/cpp/test.h: -------------------------------------------------------------------------------- 1 | #ifndef HONEST_PROFILER_TEST_H 2 | #define HONEST_PROFILER_TEST_H 3 | 4 | #ifdef __APPLE__ 5 | # include 6 | #else 7 | # include 8 | #endif 9 | 10 | #if !defined(__clang__) && ((__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)) 11 | # define DISABLE_CPP11 12 | #endif 13 | 14 | #endif -------------------------------------------------------------------------------- /src/test/cpp/test_agent.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "fixtures.h" 5 | #include "test.h" 6 | #include "../../main/cpp/agent.cpp" 7 | 8 | TEST(ParseSetsDefaultOptions) { 9 | ConfigurationOptions options; 10 | parseArguments((char*) NULL, options); 11 | CHECK_EQUAL(DEFAULT_SAMPLING_INTERVAL, options.samplingIntervalMin); 12 | CHECK_EQUAL(DEFAULT_SAMPLING_INTERVAL, options.samplingIntervalMax); 13 | CHECK_EQUAL("", options.logFilePath); 14 | } 15 | 16 | TEST(ParsesSamplingInterval) { 17 | ConfigurationOptions options; 18 | parseArguments((char *) "interval=10", options); 19 | CHECK_EQUAL(10, options.samplingIntervalMin); 20 | CHECK_EQUAL(10, options.samplingIntervalMax); 21 | 22 | parseArguments((char *) "intervalMin=12,intervalMax=17", options); 23 | CHECK_EQUAL(12, options.samplingIntervalMin); 24 | CHECK_EQUAL(17, options.samplingIntervalMax); 25 | } 26 | 27 | TEST(ParsesLogPath) { 28 | ConfigurationOptions options; 29 | char* string = (char *) "logPath=/home/richard/log.hpl"; 30 | parseArguments(string, options); 31 | CHECK_EQUAL("/home/richard/log.hpl", options.logFilePath); 32 | } 33 | 34 | TEST(ParsesMultipleArguments) { 35 | ConfigurationOptions options; 36 | char* string = (char *) "interval=10,logPath=/home/richard/log.hpl"; 37 | parseArguments(string, options); 38 | CHECK_EQUAL(10, options.samplingIntervalMin); 39 | CHECK_EQUAL(10, options.samplingIntervalMax); 40 | CHECK_EQUAL("/home/richard/log.hpl", options.logFilePath); 41 | 42 | string = (char *) "logPath=/home/richard/log.hpl,interval=10"; 43 | parseArguments(string, options); 44 | CHECK_EQUAL(10, options.samplingIntervalMin); 45 | CHECK_EQUAL(10, options.samplingIntervalMax); 46 | CHECK_EQUAL("/home/richard/log.hpl", options.logFilePath); 47 | } 48 | 49 | TEST(SafelyTerminatesStrings) { 50 | char* string = (char *) "/home/richard/log.hpl"; 51 | char* result = safe_copy_string(string, NULL); 52 | 53 | CHECK_EQUAL(std::string("/home/richard/log.hpl"), result); 54 | CHECK_EQUAL('\0', result[21]); 55 | 56 | free(result); 57 | 58 | string = (char *) "/home/richard/log.hpl,interval=10"; 59 | char* next = string + 21; 60 | result = safe_copy_string(string, next); 61 | 62 | CHECK_EQUAL(std::string("/home/richard/log.hpl"), result); 63 | CHECK_EQUAL('\0', result[21]); 64 | 65 | free(result); 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/com/insightfullogic/honest_profiler/core/Util.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.ports.sources.FileLogSource; 25 | 26 | import java.io.File; 27 | import java.io.IOException; 28 | import java.net.URISyntaxException; 29 | import java.net.URL; 30 | import java.util.ArrayList; 31 | import java.util.Arrays; 32 | import java.util.List; 33 | 34 | public class Util 35 | { 36 | private Util(){ } 37 | 38 | public static File log0() 39 | { 40 | return logFile("log0.hpl"); 41 | } 42 | 43 | public static FileLogSource log0Source() throws IOException 44 | { 45 | return new FileLogSource(logFile("log0.hpl")); 46 | } 47 | 48 | public static File logFile(String file) 49 | { 50 | URL url = Util.class.getResource("../../../../" + file); 51 | return urlToFile(url); 52 | } 53 | 54 | private static File urlToFile(URL url) 55 | { 56 | try 57 | { 58 | return new File(url.toURI()); 59 | } 60 | catch (URISyntaxException e) 61 | { 62 | return new File(url.getPath()); 63 | } 64 | } 65 | 66 | public static List list(T... values) 67 | { 68 | return new ArrayList<>(Arrays.asList(values)); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/com/insightfullogic/honest_profiler/core/aggregation/aggregator/FlatDiffAggregatorTest.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.core.aggregation.aggregator; 2 | 3 | import java.util.Collection; 4 | 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.junit.runners.Parameterized; 8 | import org.junit.runners.Parameterized.Parameters; 9 | 10 | import com.insightfullogic.honest_profiler.core.aggregation.grouping.FrameGrouping; 11 | import com.insightfullogic.honest_profiler.core.aggregation.grouping.ThreadGrouping; 12 | import com.insightfullogic.honest_profiler.core.aggregation.result.diff.FlatDiff; 13 | import com.insightfullogic.honest_profiler.framework.ParameterUtil; 14 | import com.insightfullogic.honest_profiler.framework.checker.FlatDiffCheckAdapter; 15 | import com.insightfullogic.honest_profiler.framework.generator.FlatGenerator; 16 | import com.insightfullogic.honest_profiler.framework.scenario.SimplifiedLogScenario; 17 | 18 | @RunWith(Parameterized.class) 19 | public class FlatDiffAggregatorTest 20 | { 21 | @Parameters(name = "{0} <-> {1} : <{1},{2}>") 22 | public static Collection data() 23 | { 24 | return ParameterUtil.getDiffScenariosAndGroupings(); 25 | } 26 | 27 | // Instance Properties 28 | 29 | private SimplifiedLogScenario baseScenario; 30 | private SimplifiedLogScenario newScenario; 31 | private ThreadGrouping threadGrouping; 32 | private FrameGrouping frameGrouping; 33 | 34 | // Instance Constructors 35 | 36 | public FlatDiffAggregatorTest(SimplifiedLogScenario baseScenario, 37 | SimplifiedLogScenario newScenario, 38 | ThreadGrouping threadGrouping, 39 | FrameGrouping frameGrouping) 40 | { 41 | this.baseScenario = baseScenario; 42 | this.newScenario = newScenario; 43 | this.threadGrouping = threadGrouping; 44 | this.frameGrouping = frameGrouping; 45 | } 46 | 47 | // Actual Test Method 48 | 49 | @Test 50 | public void testScenario() 51 | { 52 | FlatGenerator baseGen; 53 | FlatGenerator newGen; 54 | 55 | baseGen = new FlatGenerator(threadGrouping, frameGrouping); 56 | baseScenario.executeAndEnd(baseGen); 57 | 58 | newGen = new FlatGenerator(threadGrouping, frameGrouping); 59 | newScenario.executeAndEnd(newGen); 60 | 61 | FlatDiff diff = new FlatDiff(); 62 | diff.set(baseGen.getFlat(), newGen.getFlat()); 63 | 64 | baseScenario.checkFlatDiffAggregation(newScenario, new FlatDiffCheckAdapter(diff)); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/com/insightfullogic/honest_profiler/core/aggregation/aggregator/FlatProfileAggregatorTest.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.core.aggregation.aggregator; 2 | 3 | import static com.insightfullogic.honest_profiler.framework.ParameterUtil.getScenariosAndGroupings; 4 | 5 | import java.util.Collection; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.junit.runners.Parameterized; 10 | import org.junit.runners.Parameterized.Parameters; 11 | 12 | import com.insightfullogic.honest_profiler.core.aggregation.grouping.FrameGrouping; 13 | import com.insightfullogic.honest_profiler.core.aggregation.grouping.ThreadGrouping; 14 | import com.insightfullogic.honest_profiler.framework.checker.FlatCheckAdapter; 15 | import com.insightfullogic.honest_profiler.framework.generator.FlatGenerator; 16 | import com.insightfullogic.honest_profiler.framework.scenario.SimplifiedLogScenario; 17 | 18 | @RunWith(Parameterized.class) 19 | public class FlatProfileAggregatorTest 20 | { 21 | @Parameters(name = "{0} : <{1},{2}>") 22 | public static Collection data() 23 | { 24 | return getScenariosAndGroupings(); 25 | } 26 | 27 | // Instance Properties 28 | 29 | private SimplifiedLogScenario scenario; 30 | private ThreadGrouping threadGrouping; 31 | private FrameGrouping frameGrouping; 32 | 33 | // Instance Constructors 34 | 35 | public FlatProfileAggregatorTest(SimplifiedLogScenario scenario, 36 | ThreadGrouping threadGrouping, 37 | FrameGrouping frameGrouping) 38 | { 39 | this.scenario = scenario; 40 | this.threadGrouping = threadGrouping; 41 | this.frameGrouping = frameGrouping; 42 | } 43 | 44 | // Actual Test Method 45 | 46 | @Test 47 | public void testScenario() 48 | { 49 | FlatGenerator gen; 50 | 51 | gen = new FlatGenerator(threadGrouping, frameGrouping); 52 | scenario.executeAndEnd(gen); 53 | scenario.checkFlatAggregation(new FlatCheckAdapter(gen.getFlat())); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/com/insightfullogic/honest_profiler/core/aggregation/aggregator/TreeDiffAggregatorTest.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.core.aggregation.aggregator; 2 | 3 | import java.util.Collection; 4 | 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.junit.runners.Parameterized; 8 | import org.junit.runners.Parameterized.Parameters; 9 | 10 | import com.insightfullogic.honest_profiler.core.aggregation.grouping.FrameGrouping; 11 | import com.insightfullogic.honest_profiler.core.aggregation.grouping.ThreadGrouping; 12 | import com.insightfullogic.honest_profiler.core.aggregation.result.diff.TreeDiff; 13 | import com.insightfullogic.honest_profiler.framework.ParameterUtil; 14 | import com.insightfullogic.honest_profiler.framework.checker.TreeDiffCheckAdapter; 15 | import com.insightfullogic.honest_profiler.framework.generator.TreeGenerator; 16 | import com.insightfullogic.honest_profiler.framework.scenario.SimplifiedLogScenario; 17 | 18 | @RunWith(Parameterized.class) 19 | public class TreeDiffAggregatorTest 20 | { 21 | @Parameters(name = "{0} <-> {1} : <{1},{2}>") 22 | public static Collection data() 23 | { 24 | return ParameterUtil.getDiffScenariosAndGroupings(); 25 | } 26 | 27 | // Instance Properties 28 | 29 | private SimplifiedLogScenario baseScenario; 30 | private SimplifiedLogScenario newScenario; 31 | private ThreadGrouping threadGrouping; 32 | private FrameGrouping frameGrouping; 33 | 34 | // Instance Constructors 35 | 36 | public TreeDiffAggregatorTest(SimplifiedLogScenario baseScenario, 37 | SimplifiedLogScenario newScenario, 38 | ThreadGrouping threadGrouping, 39 | FrameGrouping frameGrouping) 40 | { 41 | this.baseScenario = baseScenario; 42 | this.newScenario = newScenario; 43 | this.threadGrouping = threadGrouping; 44 | this.frameGrouping = frameGrouping; 45 | } 46 | 47 | // Actual Test Method 48 | 49 | @Test 50 | public void testScenario() 51 | { 52 | TreeGenerator baseGen; 53 | TreeGenerator newGen; 54 | 55 | baseGen = new TreeGenerator(threadGrouping, frameGrouping); 56 | baseScenario.executeAndEnd(baseGen); 57 | 58 | newGen = new TreeGenerator(threadGrouping, frameGrouping); 59 | newScenario.executeAndEnd(newGen); 60 | 61 | TreeDiff diff = new TreeDiff(); 62 | diff.set(baseGen.getTree(), newGen.getTree()); 63 | 64 | baseScenario.checkTreeDiffAggregation(newScenario, new TreeDiffCheckAdapter(diff)); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/com/insightfullogic/honest_profiler/core/aggregation/aggregator/TreeProfileAggregatorTest.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.core.aggregation.aggregator; 2 | 3 | import static com.insightfullogic.honest_profiler.framework.ParameterUtil.getScenariosAndGroupings; 4 | 5 | import java.util.Collection; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.junit.runners.Parameterized; 10 | import org.junit.runners.Parameterized.Parameters; 11 | 12 | import com.insightfullogic.honest_profiler.core.aggregation.grouping.FrameGrouping; 13 | import com.insightfullogic.honest_profiler.core.aggregation.grouping.ThreadGrouping; 14 | import com.insightfullogic.honest_profiler.framework.checker.TreeCheckAdapter; 15 | import com.insightfullogic.honest_profiler.framework.generator.TreeGenerator; 16 | import com.insightfullogic.honest_profiler.framework.scenario.SimplifiedLogScenario; 17 | 18 | @RunWith(Parameterized.class) 19 | public class TreeProfileAggregatorTest 20 | { 21 | @Parameters(name = "{0} : <{1},{2}>") 22 | public static Collection data() 23 | { 24 | return getScenariosAndGroupings(); 25 | } 26 | 27 | // Instance Properties 28 | 29 | private SimplifiedLogScenario scenario; 30 | private ThreadGrouping threadGrouping; 31 | private FrameGrouping frameGrouping; 32 | 33 | // Instance Constructors 34 | 35 | public TreeProfileAggregatorTest(SimplifiedLogScenario scenario, 36 | ThreadGrouping threadGrouping, 37 | FrameGrouping frameGrouping) 38 | { 39 | this.scenario = scenario; 40 | this.threadGrouping = threadGrouping; 41 | this.frameGrouping = frameGrouping; 42 | } 43 | 44 | // Actual Test Method 45 | 46 | @Test 47 | public void testScenario() 48 | { 49 | TreeGenerator gen; 50 | 51 | gen = new TreeGenerator(threadGrouping, frameGrouping); 52 | scenario.executeAndEnd(gen); 53 | scenario.checkTreeAggregation(new TreeCheckAdapter(gen.getTree())); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/com/insightfullogic/honest_profiler/core/collector/FakeProfileListener.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 | import com.insightfullogic.honest_profiler.core.profiles.Profile; 25 | import com.insightfullogic.honest_profiler.core.profiles.ProfileListener; 26 | 27 | public class FakeProfileListener implements ProfileListener 28 | { 29 | 30 | private Profile profile; 31 | 32 | @Override 33 | public void accept(Profile profile) 34 | { 35 | this.profile = profile; 36 | } 37 | 38 | public Profile getProfile() 39 | { 40 | return profile; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/com/insightfullogic/honest_profiler/core/filters/ThreadSampleFilterTest.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.ProfileTree; 26 | import com.insightfullogic.lambdabehave.JunitSuiteRunner; 27 | import org.junit.runner.RunWith; 28 | 29 | import static com.insightfullogic.honest_profiler.core.Util.list; 30 | import static com.insightfullogic.lambdabehave.Suite.describe; 31 | 32 | @RunWith(JunitSuiteRunner.class) 33 | public class ThreadSampleFilterTest 34 | { 35 | { 36 | 37 | describe("the thread sample filter", it -> { 38 | 39 | ThreadSampleFilter filter = new ThreadSampleFilter(); 40 | 41 | it.should("not remove trees with as many samples as sampled in total", expect -> { 42 | ProfileTree tree = new ProfileTree(0L, null, 100); 43 | Profile profile = new Profile(100, null, null, list(tree)); 44 | filter.filter(profile); 45 | 46 | expect.that(profile.getTrees()).contains(tree); 47 | }); 48 | 49 | it.should("remove trees with very few samples", expect -> { 50 | ProfileTree tree = new ProfileTree(0L, null, 1); 51 | Profile profile = new Profile(150, null, null, list(tree)); 52 | filter.filter(profile); 53 | 54 | expect.that(profile.getTrees()).isEmpty(); 55 | }); 56 | 57 | }); 58 | 59 | }} 60 | -------------------------------------------------------------------------------- /src/test/java/com/insightfullogic/honest_profiler/framework/generator/ProfileContextGenerator.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.framework.generator; 2 | 3 | import static com.insightfullogic.honest_profiler.ports.javafx.model.ProfileContext.ProfileMode.LOG; 4 | 5 | import java.io.File; 6 | 7 | import com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfile; 8 | import com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfileListener; 9 | import com.insightfullogic.honest_profiler.framework.LeanLogCollectorDriver; 10 | import com.insightfullogic.honest_profiler.framework.scenario.LogScenario; 11 | import com.insightfullogic.honest_profiler.ports.javafx.JavaFXApplication; 12 | import com.insightfullogic.honest_profiler.ports.javafx.model.ProfileContext; 13 | import com.insightfullogic.honest_profiler.ports.javafx.model.ProfileContext.ProfileMode; 14 | 15 | public class ProfileContextGenerator extends LeanLogCollectorDriver 16 | { 17 | private JavaFXApplication application; 18 | private ProfileContext context; 19 | private LeanProfileListener wrappedListener; 20 | 21 | public ProfileContextGenerator(JavaFXApplication application, String name, ProfileMode mode) 22 | { 23 | super(); 24 | 25 | this.application = application; 26 | 27 | reset(); 28 | 29 | context = application.getContextForFile(new File(name), LOG); 30 | wrappedListener = context.getProfileListener(); 31 | } 32 | 33 | public ProfileContext getProfileContext() 34 | { 35 | return context; 36 | } 37 | 38 | public void createNewProfile(LogScenario scenario) 39 | { 40 | scenario.executeAndEnd(this); 41 | application.testNewProfile(getProfileContext()); 42 | } 43 | 44 | @Override 45 | public void accept(LeanProfile newProfile) 46 | { 47 | wrappedListener.accept(newProfile); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/com/insightfullogic/honest_profiler/framework/scenario/Scenario01.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.framework.scenario; 2 | 3 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.F_01; 4 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.M_01; 5 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.T_01; 6 | 7 | /** 8 | * One stack trace consisting of one frame is emitted on one thread. 9 | */ 10 | public class Scenario01 extends SimplifiedLogScenario 11 | { 12 | public Scenario01() 13 | { 14 | super("Scenario 01"); 15 | 16 | addThreads(T_01); 17 | addMethods(M_01); 18 | addStack(1, F_01); 19 | end(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/com/insightfullogic/honest_profiler/framework/scenario/Scenario02.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.framework.scenario; 2 | 3 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.F_01; 4 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.F_02; 5 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.F_03; 6 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.F_04; 7 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.F_05; 8 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.M_01; 9 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.M_02; 10 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.M_03; 11 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.M_04; 12 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.M_05; 13 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.T_01; 14 | 15 | /** 16 | * One stack trace consisting of five frames is emitted on one thread. 17 | */ 18 | public class Scenario02 extends SimplifiedLogScenario 19 | { 20 | public Scenario02() 21 | { 22 | super("Scenario 02"); 23 | 24 | addThreads(T_01); 25 | addMethods(M_01, M_02, M_03, M_04, M_05); 26 | addStack(1, F_01, F_02, F_03, F_04, F_05); 27 | end(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/com/insightfullogic/honest_profiler/framework/scenario/Scenario03.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.framework.scenario; 2 | 3 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.F_01; 4 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.F_02; 5 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.F_03; 6 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.F_04; 7 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.F_05; 8 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.M_01; 9 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.M_02; 10 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.M_03; 11 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.M_04; 12 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.M_05; 13 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.T_01; 14 | 15 | public class Scenario03 extends SimplifiedLogScenario 16 | { 17 | /** 18 | * Two identical stack traces consisting of five frames are emitted on one thread. 19 | */ 20 | public Scenario03() 21 | { 22 | super("Scenario 03"); 23 | 24 | addThreads(T_01); 25 | addMethods(M_01, M_02, M_03, M_04, M_05); 26 | addStack(1, F_01, F_02, F_03, F_04, F_05); 27 | addStack(1, F_01, F_02, F_03, F_04, F_05); 28 | end(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/com/insightfullogic/honest_profiler/framework/scenario/Scenario04.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.framework.scenario; 2 | 3 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.F_01; 4 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.F_02; 5 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.F_03; 6 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.F_04; 7 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.F_05; 8 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.M_01; 9 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.M_02; 10 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.M_03; 11 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.M_04; 12 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.M_05; 13 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.T_01; 14 | 15 | public class Scenario04 extends SimplifiedLogScenario 16 | { 17 | /** 18 | * Two stack traces consisting of five frames are emitted on one thread. One stack trace is the inverse of the 19 | * other. 20 | */ 21 | public Scenario04() 22 | { 23 | super("Scenario 04"); 24 | 25 | addThreads(T_01); 26 | addMethods(M_01, M_02, M_03, M_04, M_05); 27 | addStack(1, F_01, F_02, F_03, F_04, F_05); 28 | addStack(1, F_05, F_04, F_03, F_02, F_01); 29 | end(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/insightfullogic/honest_profiler/framework/scenario/Scenario05.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.framework.scenario; 2 | 3 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.F_01; 4 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.M_01; 5 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.T_01; 6 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.T_02; 7 | 8 | public class Scenario05 extends SimplifiedLogScenario 9 | { 10 | /** 11 | * One stack trace consisting of one frame is emitted on two threads. 12 | */ 13 | public Scenario05() 14 | { 15 | super("Scenario 05"); 16 | 17 | addThreads(T_01, T_02); 18 | addMethods(M_01); 19 | addStack(1, F_01); 20 | addStack(2, F_01); 21 | end(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/insightfullogic/honest_profiler/framework/scenario/Scenario06.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.framework.scenario; 2 | 3 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.F_01; 4 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.F_02; 5 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.F_03; 6 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.F_04; 7 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.F_05; 8 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.M_01; 9 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.M_02; 10 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.M_03; 11 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.M_04; 12 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.M_05; 13 | import static com.insightfullogic.honest_profiler.framework.LogEventFactory.T_01; 14 | 15 | import com.insightfullogic.honest_profiler.core.parser.ThreadMeta; 16 | 17 | public class Scenario06 extends SimplifiedLogScenario 18 | { 19 | /** 20 | * One stack trace consisting of five frames is emitted on two threads. No {@link ThreadMeta} is emitted for the 21 | * second stack in order to test {@link ThreadMeta} absence logic. 22 | */ 23 | public Scenario06() 24 | { 25 | super("Scenario 06"); 26 | 27 | addThreads(T_01); 28 | addMethods(M_01, M_02, M_03, M_04, M_05); 29 | addStack(1, F_01, F_02, F_03, F_04, F_05); 30 | addStack(2, F_01, F_02, F_03, F_04, F_05); 31 | end(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/insightfullogic/honest_profiler/ports/javafx/controller/SampleCountTest.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.ports.javafx.controller; 2 | 3 | import static com.insightfullogic.honest_profiler.framework.ParameterUtil.getScenarios; 4 | import static com.insightfullogic.honest_profiler.ports.javafx.framework.HPFXUtil.newProfileTab; 5 | import static com.insightfullogic.honest_profiler.ports.javafx.framework.HPFXUtil.waitUntil; 6 | import static com.insightfullogic.honest_profiler.ports.javafx.model.ProfileContext.ProfileMode.LOG; 7 | import static org.junit.Assert.assertEquals; 8 | 9 | import java.util.Collection; 10 | 11 | import org.junit.Test; 12 | import org.junit.runner.RunWith; 13 | import org.junit.runners.Parameterized; 14 | import org.junit.runners.Parameterized.Parameters; 15 | import org.testfx.api.FxRobot; 16 | 17 | import com.insightfullogic.honest_profiler.framework.scenario.SimplifiedLogScenario; 18 | import com.insightfullogic.honest_profiler.ports.javafx.framework.AbstractJavaFxTest; 19 | 20 | import javafx.scene.control.Label; 21 | 22 | @RunWith(Parameterized.class) 23 | public class SampleCountTest extends AbstractJavaFxTest 24 | { 25 | // Class Methods 26 | 27 | @Parameters(name = "{0}") 28 | public static Collection data() 29 | { 30 | return getScenarios(); 31 | } 32 | 33 | // Instance Properties 34 | 35 | private SimplifiedLogScenario scenario; 36 | 37 | // Instance Constructors 38 | 39 | public SampleCountTest(SimplifiedLogScenario scenario) 40 | { 41 | this.scenario = scenario; 42 | } 43 | 44 | // Actual Test Method 45 | 46 | @Test 47 | public void testSampleCount() 48 | { 49 | FxRobot robot = new FxRobot(); 50 | 51 | newProfileTab(robot, app(), 0, scenario.getName(), scenario, LOG); 52 | 53 | Label label = robot.lookup("#profileSampleCount").query(); 54 | waitUntil(() -> label.getText() != null && !label.getText().isEmpty()); 55 | 56 | assertEquals(scenario.getTraceCount() + " samples", label.getText()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/insightfullogic/honest_profiler/ports/javafx/framework/AbstractJavaFxTest.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.ports.javafx.framework; 2 | 3 | import static com.insightfullogic.honest_profiler.ports.javafx.framework.HPFXUtil.isHeadless; 4 | import static java.lang.System.gc; 5 | import static org.junit.Assert.assertNotNull; 6 | import static org.testfx.api.FxToolkit.registerPrimaryStage; 7 | import static org.testfx.api.FxToolkit.setupApplication; 8 | import static org.testfx.api.FxToolkit.setupStage; 9 | 10 | import org.junit.After; 11 | import org.junit.AfterClass; 12 | import org.junit.Before; 13 | import org.junit.BeforeClass; 14 | 15 | import com.insightfullogic.honest_profiler.ports.javafx.JavaFXApplication; 16 | 17 | import javafx.stage.Stage; 18 | 19 | public abstract class AbstractJavaFxTest 20 | { 21 | // Class properties 22 | 23 | private static Stage mainStage; 24 | 25 | // Class Accessors 26 | 27 | public static Stage getMainStage() 28 | { 29 | return mainStage; 30 | } 31 | 32 | // Instance Properties 33 | 34 | private JavaFXApplication app; 35 | 36 | // Instance Accessors 37 | 38 | public JavaFXApplication app() 39 | { 40 | return app; 41 | } 42 | 43 | // Setup and Teardown 44 | 45 | @BeforeClass 46 | public static void setupSpec() throws Exception 47 | { 48 | if (isHeadless()) 49 | { 50 | System.setProperty("testfx.robot", "glass"); 51 | System.setProperty("testfx.headless", "true"); 52 | System.setProperty("prism.order", "sw"); 53 | System.setProperty("prism.text", "t2k"); 54 | System.setProperty("java.awt.headless", "true"); 55 | } 56 | 57 | registerPrimaryStage(); 58 | setupStage(stage -> 59 | { 60 | mainStage = stage; 61 | stage.show(); 62 | }); 63 | } 64 | 65 | @AfterClass 66 | public static void teardownSpec() throws Exception 67 | { 68 | mainStage = null; 69 | } 70 | 71 | @Before 72 | public void setup() throws Exception 73 | { 74 | app = (JavaFXApplication)setupApplication(JavaFXApplication.class); 75 | assertNotNull(app); 76 | } 77 | 78 | @After 79 | public void teardown() throws Exception 80 | { 81 | app.stop(); 82 | app = null; 83 | gc(); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/test/java/com/insightfullogic/honest_profiler/ports/sources/LocalMachineSourceTest.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.ports.sources; 2 | 3 | import com.insightfullogic.honest_profiler.core.MachineListener; 4 | import com.insightfullogic.honest_profiler.core.sources.VirtualMachine; 5 | import com.insightfullogic.honest_profiler.testing_utilities.AgentRunner; 6 | import com.insightfullogic.lambdabehave.JunitSuiteRunner; 7 | import org.junit.runner.RunWith; 8 | import org.slf4j.Logger; 9 | 10 | import static com.insightfullogic.lambdabehave.Suite.describe; 11 | import static org.mockito.Mockito.mock; 12 | 13 | @RunWith(JunitSuiteRunner.class) 14 | public class LocalMachineSourceTest 15 | { 16 | { 17 | 18 | describe("Local Machine Sources", it -> { 19 | 20 | Logger logger = mock(Logger.class); 21 | 22 | 23 | it.should("detect local machines", expect -> { 24 | AgentRunner.run("InfiniteExample", AgentRunner.DEFAULT_AGENT_INTERVAL, runner -> { 25 | final int expectedProcessId = runner.getProcessId(); 26 | new LocalMachineSource(logger, new MachineListener() 27 | { 28 | @Override 29 | public void onNewMachine(final VirtualMachine machine) 30 | { 31 | int machineProcessId = Integer.parseInt(machine.getId()); 32 | expect.that(machine.isAgentLoaded()).is(machineProcessId == expectedProcessId); 33 | } 34 | 35 | @Override 36 | public void onClosedMachine(final VirtualMachine machine) 37 | { 38 | expect.failure("Should never close VM " + machine); 39 | } 40 | }).discoverVirtualMachines(); 41 | }); 42 | }); 43 | 44 | it.should("detect no local machines if none are running", expect -> { 45 | new LocalMachineSource(logger, new MachineListener() 46 | { 47 | @Override 48 | public void onNewMachine(final VirtualMachine machine) 49 | { 50 | expect.that(machine.isAgentLoaded()).is(false); 51 | } 52 | 53 | @Override 54 | public void onClosedMachine(final VirtualMachine machine) 55 | { 56 | expect.failure("Should never close VM " + machine); 57 | } 58 | }).discoverVirtualMachines(); 59 | }); 60 | 61 | }); 62 | 63 | }} 64 | -------------------------------------------------------------------------------- /src/test/java/com/insightfullogic/honest_profiler/testing_utilities/LargeStacktracesExample.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.testing_utilities; 23 | 24 | import java.util.Calendar; 25 | import java.util.concurrent.ExecutorService; 26 | import java.util.concurrent.Executors; 27 | import java.util.stream.IntStream; 28 | 29 | public class LargeStacktracesExample implements Runnable 30 | { 31 | 32 | public static void main(String[] args) throws Exception 33 | { 34 | int processors = Runtime.getRuntime().availableProcessors() * 2; 35 | 36 | ExecutorService threadPool = Executors.newFixedThreadPool(processors); 37 | IntStream.range(0, processors) 38 | .forEach(x -> threadPool.submit(new LargeStacktracesExample())); 39 | } 40 | 41 | @Override 42 | public void run() 43 | { 44 | while (true) 45 | { 46 | String value = null; 47 | for (int i = 0; i < 100_000; i++) 48 | { 49 | value = someSillyMethod(); 50 | try 51 | { 52 | Thread.sleep(5); 53 | } 54 | catch (InterruptedException e) 55 | { 56 | e.printStackTrace(); 57 | } 58 | } 59 | System.out.println(value); 60 | } 61 | } 62 | 63 | private String someSillyMethod() 64 | { 65 | Calendar cal = Calendar.getInstance(); 66 | return cal.toString(); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/test/java/com/insightfullogic/honest_profiler/testing_utilities/ProfileFixtures.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.testing_utilities; 23 | 24 | import com.insightfullogic.honest_profiler.core.parser.Method; 25 | 26 | public class ProfileFixtures 27 | { 28 | private ProfileFixtures(){ } 29 | 30 | public static final long printlnId = 5; 31 | public static final long appendId = 6; 32 | public static final long printfId = 7; 33 | 34 | public static final Method println = new Method(printlnId, "PrintStream.java", "Ljava/io/PrintStream;", "println"); 35 | public static final Method append = new Method(appendId, "PrintStream.java", "Ljava/io/PrintStream;", "append"); 36 | public static final Method printf = new Method(printfId, "PrintStream.java", "Ljava/io/PrintStream;", "printf"); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/insightfullogic/honest_profiler/testing_utilities/SleepingThreadExample.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.testing_utilities; 23 | 24 | public class SleepingThreadExample 25 | { 26 | 27 | public static void main(String[] args) throws Exception 28 | { 29 | while (true) 30 | { 31 | long time = System.currentTimeMillis(); 32 | Thread.sleep(500); 33 | if ((System.currentTimeMillis() - time) < 500) 34 | { 35 | System.out.println("Sleep has been broken"); 36 | } 37 | for (int i = 0; i < 1000; i++) 38 | { 39 | subMethod(); 40 | } 41 | } 42 | } 43 | 44 | private static void subMethod() 45 | { 46 | System.out.println("calling some code, lalala"); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/com/insightfullogic/honest_profiler/testing_utilities/VirtualMachineFixtures.java: -------------------------------------------------------------------------------- 1 | package com.insightfullogic.honest_profiler.testing_utilities; 2 | 3 | import com.insightfullogic.honest_profiler.core.sources.VirtualMachine; 4 | 5 | import java.io.File; 6 | 7 | public class VirtualMachineFixtures 8 | { 9 | private VirtualMachineFixtures(){ } 10 | 11 | public static final VirtualMachine vmNoAgent = new VirtualMachine("0", "vm without agent", false, "", ""); 12 | public static final VirtualMachine vmWithAgent = new VirtualMachine("1", "vm with agent", true, new File(".").getAbsolutePath(), "foobar-agentpath=blahblahlogPath=" + new File(".").getAbsolutePath()); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/test/resources/alex_log_16_07_2014.hpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-profiling-tools/honest-profiler/5783ffab6690807783521a1b6dca6e74e77ba853/src/test/resources/alex_log_16_07_2014.hpl.gz -------------------------------------------------------------------------------- /src/test/resources/example.hpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-profiling-tools/honest-profiler/5783ffab6690807783521a1b6dca6e74e77ba853/src/test/resources/example.hpl -------------------------------------------------------------------------------- /src/test/resources/log0.hpl: -------------------------------------------------------------------------------- 1 | 4PrintStream.javaLjava/io/PrintStream;printf*PrintStream.javaLjava/io/PrintStream;append4* --------------------------------------------------------------------------------