mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 19:22:45 +00:00 
			
		
		
		
	Kernel+Profiler: Make profiling per-process and without core dumps
This patch merges the profiling functionality in the kernel with the performance events mechanism. A profiler sample is now just another perf event, rather than a dedicated thing. Since perf events were already per-process, this now makes profiling per-process as well. Processes with perf events would already write out a perfcore.PID file to the current directory on death, but since we may want to profile a process and then let it continue running, recorded perf events can now be accessed at any time via /proc/PID/perf_events. This patch also adds information about process memory regions to the perfcore JSON format. This removes the need to supply a core dump to the Profiler app for symbolication, and so the "profiler coredump" mechanism is removed entirely. There's still a hard limit of 4MB worth of perf events per process, so this is by no means a perfect final design, but it's a nice step forward for both simplicity and stability. Fixes #4848 Fixes #4849
This commit is contained in:
		
							parent
							
								
									f259d96871
								
							
						
					
					
						commit
						5dafb72370
					
				
					 20 changed files with 195 additions and 310 deletions
				
			
		|  | @ -1,5 +1,5 @@ | |||
| /*
 | ||||
|  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> | ||||
|  * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> | ||||
|  * All rights reserved. | ||||
|  * | ||||
|  * Redistribution and use in source and binary forms, with or without | ||||
|  | @ -28,8 +28,8 @@ | |||
| #include <AK/ScopeGuard.h> | ||||
| #include <AK/TemporaryChange.h> | ||||
| #include <AK/Time.h> | ||||
| #include <Kernel/PerformanceEventBuffer.h> | ||||
| #include <Kernel/Process.h> | ||||
| #include <Kernel/Profiling.h> | ||||
| #include <Kernel/RTC.h> | ||||
| #include <Kernel/Scheduler.h> | ||||
| #include <Kernel/Time/TimeManagement.h> | ||||
|  | @ -477,15 +477,9 @@ void Scheduler::timer_tick(const RegisterState& regs) | |||
|     if (!is_bsp) | ||||
|         return; // TODO: This prevents scheduling on other CPUs!
 | ||||
|     if (current_thread->process().is_profiling()) { | ||||
|         SmapDisabler disabler; | ||||
|         auto backtrace = current_thread->raw_backtrace(regs.ebp, regs.eip); | ||||
|         auto& sample = Profiling::next_sample_slot(); | ||||
|         sample.pid = current_thread->process().pid(); | ||||
|         sample.tid = current_thread->tid(); | ||||
|         sample.timestamp = TimeManagement::the().uptime_ms(); | ||||
|         for (size_t i = 0; i < min(backtrace.size(), Profiling::max_stack_frame_count); ++i) { | ||||
|             sample.frames[i] = backtrace[i]; | ||||
|         } | ||||
|         ASSERT(current_thread->process().perf_events()); | ||||
|         auto& perf_events = *current_thread->process().perf_events(); | ||||
|         [[maybe_unused]] auto rc = perf_events.append(PERF_EVENT_SAMPLE, 0, 0); | ||||
|     } | ||||
| 
 | ||||
|     if (current_thread->tick((regs.cs & 3) == 0)) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling