MCPcopy Create free account
hub / github.com/async-profiler/async-profiler / start

Method start

src/profiler.cpp:830–1065  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

828}
829
830Error Profiler::start(Arguments& args, bool reset) {
831 MutexLocker ml(_state_lock);
832 if (_state > IDLE) {
833 return Error("Profiler already started");
834 }
835
836 // If profiler is started from a native app, try to detect a running JVM and attach to it
837 if (!VM::loaded()) {
838 VM::tryAttach();
839 }
840
841 Error error = checkJvmCapabilities();
842 if (error) {
843 return error;
844 }
845
846 _event_mask = args.eventMask();
847
848 if (_event_mask == 0) {
849 return Error("No profiling events specified");
850 } else if ((_event_mask & (_event_mask - 1)) && args._output != OUTPUT_JFR) {
851 return Error("Only JFR output supports multiple events");
852 } else if (!VM::loaded() && (_event_mask & (EM_ALLOC | EM_LOCK | EM_METHOD_TRACE))) {
853 return Error("Profiling event is not supported with non-Java processes");
854 }
855
856 if (args._jfr_sync && !VM::loaded()) {
857 return Error("jfrsync is not supported with non-Java processes");
858 }
859
860 if (args._fdtransfer) {
861 if (!FdTransferClient::connectToServer(args._fdtransfer_path)) {
862 return Error("Failed to initialize FdTransferClient");
863 }
864 }
865
866 if (args._proc > 0) {
867 if (!OS::isLinux()) {
868 return Error("Process sampling is not supported on the platform");
869 } else if (args._output != OUTPUT_JFR) {
870 return Error("Process sampling requires JFR output format");
871 }
872 }
873
874 // Save the arguments for shutdown or restart
875 args.save();
876
877 if (reset || _start_time == 0) {
878 // Reset counters
879 _total_samples = 0;
880 _total_stack_walk_time = 0;
881 memset(_failures, 0, sizeof(_failures));
882
883 // Reset dictionaries and bitmaps
884 lockAll();
885 _class_map.clear();
886 _thread_filter.clear();
887 _call_trace_storage.clear(args._mem_limit);

Callers

nothing calls this directly

Calls 8

ErrorClass · 0.85
eventMaskMethod · 0.80
saveMethod · 0.80
emptyMethod · 0.80
startMethod · 0.65
stopMethod · 0.65
clearMethod · 0.45
initMethod · 0.45

Tested by

no test coverage detected