diff options
author | Jakub Berkop <jakub.berkop@gmail.com> | 2021-12-04 13:26:13 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-14 11:38:13 +0100 |
commit | 4916c892b2d3332e4af28be8aa2889f05e139199 (patch) | |
tree | 8d774e1fc2f3d1085d93cbfcd9fc682188baab91 /Kernel/Syscalls/read.cpp | |
parent | bd821982e0161752e6d3d8fbc4ccd485e5ed5b61 (diff) | |
download | serenity-4916c892b2d3332e4af28be8aa2889f05e139199.zip |
Kernel/Profiling: Add profiling to read syscall
Syscalls to read can now be profiled, allowing us to monitor
filesystem usage by different applications.
Diffstat (limited to 'Kernel/Syscalls/read.cpp')
-rw-r--r-- | Kernel/Syscalls/read.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Kernel/Syscalls/read.cpp b/Kernel/Syscalls/read.cpp index 935daf1206..3e8e7e094f 100644 --- a/Kernel/Syscalls/read.cpp +++ b/Kernel/Syscalls/read.cpp @@ -6,6 +6,7 @@ #include <Kernel/Debug.h> #include <Kernel/FileSystem/OpenFileDescription.h> +#include <Kernel/PerformanceManager.h> #include <Kernel/Process.h> namespace Kernel { @@ -73,6 +74,20 @@ ErrorOr<FlatPtr> Process::sys$readv(int fd, Userspace<const struct iovec*> iov, ErrorOr<FlatPtr> Process::sys$read(int fd, Userspace<u8*> buffer, size_t size) { + const auto start_timestamp = TimeManagement::the().uptime_ms(); + const auto result = read_impl(fd, buffer, size); + + if (Thread::current()->is_profiling_suppressed()) + return result; + + auto description = TRY(open_readable_file_description(fds(), fd)); + PerformanceManager::add_read_event(*Thread::current(), fd, size, description, start_timestamp, result); + + return result; +} + +ErrorOr<FlatPtr> Process::read_impl(int fd, Userspace<u8*> buffer, size_t size) +{ VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this) TRY(require_promise(Pledge::stdio)); if (size == 0) @@ -81,6 +96,7 @@ ErrorOr<FlatPtr> Process::sys$read(int fd, Userspace<u8*> buffer, size_t size) return EINVAL; dbgln_if(IO_DEBUG, "sys$read({}, {}, {})", fd, buffer.ptr(), size); auto description = TRY(open_readable_file_description(fds(), fd)); + TRY(check_blocked_read(description)); auto user_buffer = TRY(UserOrKernelBuffer::for_user_buffer(buffer, size)); return TRY(description->read(user_buffer, size)); |