GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — async-profiler/src/profiler.h at jonoffcpu-dev · jonoffcpu/async-profiler Expand file tree/ Copy pathprofiler.hMore file actions 259 lines (217 loc) · 8.12 KB / Copy pathprofiler.hFile metadata and controls259 lines (217 loc) · 8.12 KB 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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 /* * Copyright The async-profiler authors * SPDX-License-Identifier: Apache-2.0 */ #ifndef _PROFILER_H #define _PROFILER_H #include <map> #include <string> #include "arch.h" #include "arguments.h" #include "callTraceStorage.h" #include "codeCache.h" #include "dictionary.h" #include "engine.h" #include "event.h" #include "flightRecorder.h" #include "log.h" #include "mutex.h" #include "spinLock.h" #include "threadFilter.h" #include "trap.h" #include "vmEntry.h" #include "writer.h" const int MAX_NATIVE_FRAMES = 128; const int RESERVED_FRAMES = 10; // for synthetic frames const int CONCURRENCY_LEVEL = 16; union CallTraceBuffer { ASGCT_CallFrame _asgct_frames[1]; jvmtiFrameInfo _jvmti_frames[1]; }; class NMethod; class StackContext; enum State { NEW, IDLE, RUNNING, TERMINATED }; class Profiler { private: Mutex _state_lock; State _state; Trap _begin_trap; Trap _end_trap; bool _nostop; Mutex _thread_names_lock; // TODO: single map? std::map<int, std::string> _thread_names; std::map<int, jlong> _thread_ids; Dictionary _class_map; ThreadFilter _thread_filter; CallTraceStorage _call_trace_storage; FlightRecorder _jfr; Engine* _engine; Engine* _alloc_engine; int _event_mask; u64 _start_time; u64 _stop_time; u64 _loop_time; int _epoch; u32 _gc_id; WaitableMutex _timer_lock; void* _timer_id; u64 _total_samples; u64 _total_stack_walk_time; u64 _failures[ASGCT_FAILURE_TYPES]; SpinLock _locks[CONCURRENCY_LEVEL]; CallTraceBuffer* _calltrace_buffer[CONCURRENCY_LEVEL]; int _max_stack_depth; int _truncated_stack_depth; StackWalkFeatures _features; CStack _cstack; bool _add_event_frame; bool _add_thread_frame; bool _add_sched_frame; bool _add_cpu_frame; bool _update_thread_names; volatile jvmtiEventMode _thread_events_state; SpinLock _stubs_lock; CodeCache _runtime_stubs; CodeCacheArray _native_libs; // dlopen() hook support void** _dlopen_entry; static void* dlopen_hook(const char* filename, int flags); // pthread_setspecific() hook support void** _pthread_setspecific_entry; static int pthread_setspecific_hook(pthread_key_t key, const void* value); void switchLibcHooks(bool enable); Error installTraps(const char* begin, const char* end, bool nostop); void uninstallTraps(); void addJavaMethod(const void* address, int length, jmethodID method); void addRuntimeStub(const void* address, int length, const char* name); void onThreadStart(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread); void onThreadEnd(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread); void onGarbageCollectionFinish(); const char* asgctError(int code); int tryLock(int tid); void unlock(int lock_index); int getNativeTrace(void* ucontext, ASGCT_CallFrame* frames, EventType event_type, int tid, u64* cpu); int getJavaTraceAsync(void* ucontext, ASGCT_CallFrame* frames, int max_depth); int getJavaTraceJvmti(jvmtiFrameInfo* jvmti_frames, ASGCT_CallFrame* frames, int start_depth, int max_depth); void setThreadInfo(int tid, const char* name, jlong java_thread_id); void updateThreadName(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread); void updateJavaThreadNames(); void updateNativeThreadNames(); void mangle(const char* name, char* buf, size_t size); Engine* selectEngine(Arguments& args); Engine* selectAllocEngine(bool tlab); Engine* activeEngine(); Error checkJvmCapabilities(); u64 addTimeout(u64 start_micros, int timeout); void startTimer(); void stopTimer(); void timerLoop(void* timer_id); void logEmptyOutput(Arguments& args, u64 printed_samples_count, Writer& out); bool hasEvent(EventCategory category) const { return (_event_mask & (1 << category)) != 0; } static void jvmtiTimerEntry(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { instance()->timerLoop(arg); } static void* pthreadTimerEntry(void* arg) { instance()->timerLoop(arg); return NULL; } void lockAll(); void unlockAll(); void dumpCollapsed(Writer& out, Arguments& args); void dumpFlameGraph(Writer& out, Arguments& args); void dumpText(Writer& out, Arguments& args); void dumpOtlp(Writer& out, Arguments& args); static Profiler* const _instance; public: Profiler() : _state(NEW), _begin_trap(2), _end_trap(3), _thread_filter(), _call_trace_storage(), _jfr(), _start_time(0), _epoch(0), _gc_id(0), _timer_id(NULL), _max_stack_depth(0), _truncated_stack_depth(0), _thread_events_state(JVMTI_DISABLE), _stubs_lock(), _runtime_stubs("[stubs]"), _native_libs(), _dlopen_entry(NULL), _pthread_setspecific_entry(NULL) { for (int i = 0; i < CONCURRENCY_LEVEL; i++) { _calltrace_buffer[i] = NULL; } } static Profiler* instance() { return _instance; } u64 total_samples() { return _total_samples; } long uptime() { return (OS::micros() - _start_time) / 1000000ULL; } Dictionary* classMap() { return &_class_map; } ThreadFilter* threadFilter() { return &_thread_filter; } CodeCacheArray* nativeLibs() { return &_native_libs; } FlightRecorder* jfr() { return &_jfr; } Error run(Arguments& args); Error runInternal(Arguments& args, Writer& out); Error expire(Arguments& args, bool restart); void shutdown(Arguments& args); Error start(Arguments& args, bool reset); Error stop(bool restart = false, const char* reason = NULL); Error flushJfr(); Error dump(Writer& out, Arguments& args); void logStats(); void writeMetrics(Writer& out); void switchThreadEvents(jvmtiEventMode mode); int convertNativeTrace(int native_frames, const void** callchain, ASGCT_CallFrame* frames, EventType event_type); u64 recordSample(void* ucontext, u64 counter, EventType event_type, Event* event); void recordExternalSample(u64 counter, int tid, EventType event_type, Event* event, int num_frames, ASGCT_CallFrame* frames); void recordExternalSamples(u64 samples, u64 counter, int tid, u32 call_trace_id, EventType event_type, Event* event); void recordEventOnly(EventType event_type, Event* event); void tryResetCounters(); void updateSymbols(bool kernel_symbols); const void* resolveSymbol(const char* name); const char* getLibraryName(const char* native_symbol); CodeCache* findJvmLibrary(const char* lib_name); CodeCache* findLibraryByName(const char* lib_name); CodeCache* findLibraryByAddress(const void* address); const char* findNativeMethod(const void* address); CodeBlob* findRuntimeStub(const void* address); void trapHandler(int signo, siginfo_t* siginfo, void* ucontext); static void crashHandler(int signo, siginfo_t* siginfo, void* ucontext); static void wakeupHandler(int signo); static void setupSignalHandlers(); // CompiledMethodLoad is also needed to enable DebugNonSafepoints info by default static void JNICALL CompiledMethodLoad(jvmtiEnv* jvmti, jmethodID method, jint code_size, const void* code_addr, jint map_length, const jvmtiAddrLocationMap* map, const void* compile_info) { instance()->addJavaMethod(code_addr, code_size, method); } static void JNICALL DynamicCodeGenerated(jvmtiEnv* jvmti, const char* name, const void* address, jint length) { instance()->addRuntimeStub(address, length, name); } static void JNICALL ThreadStart(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) { instance()->onThreadStart(jvmti, jni, thread); } static void JNICALL ThreadEnd(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) { instance()->onThreadEnd(jvmti, jni, thread); } static void JNICALL GarbageCollectionFinish(jvmtiEnv* jvmti) { instance()->onGarbageCollectionFinish(); } friend class Recording; }; #endif // _PROFILER_H |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |