mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:47:35 +00:00
Kernel+SystemMonitor: Log amounts of I/O per thread
This patch adds these I/O counters to each thread: - (Inode) file read bytes - (Inode) file write bytes - Unix socket read bytes - Unix socket write bytes - IPv4 socket read bytes - IPv4 socket write bytes These are then exposed in /proc/all and seen in SystemMonitor.
This commit is contained in:
parent
a18aa8fd5f
commit
5a45376180
10 changed files with 171 additions and 17 deletions
|
@ -206,7 +206,10 @@ ssize_t IPv4Socket::sendto(FileDescription&, const void* data, size_t data_lengt
|
|||
return data_length;
|
||||
}
|
||||
|
||||
return protocol_send(data, data_length);
|
||||
int nsent = protocol_send(data, data_length);
|
||||
if (nsent > 0)
|
||||
current->did_ipv4_socket_write(nsent);
|
||||
return nsent;
|
||||
}
|
||||
|
||||
ssize_t IPv4Socket::recvfrom(FileDescription& description, void* buffer, size_t buffer_length, int flags, sockaddr* addr, socklen_t* addr_length)
|
||||
|
@ -285,7 +288,10 @@ ssize_t IPv4Socket::recvfrom(FileDescription& description, void* buffer, size_t
|
|||
return ipv4_packet.payload_size();
|
||||
}
|
||||
|
||||
return protocol_receive(packet.data.value(), buffer, buffer_length, flags);
|
||||
int nreceived = protocol_receive(packet.data.value(), buffer, buffer_length, flags);
|
||||
if (nreceived > 0)
|
||||
current->did_ipv4_socket_read(nreceived);
|
||||
return nreceived;
|
||||
}
|
||||
|
||||
bool IPv4Socket::did_receive(const IPv4Address& source_address, u16 source_port, KBuffer&& packet)
|
||||
|
|
|
@ -222,15 +222,13 @@ ssize_t LocalSocket::sendto(FileDescription& description, const void* data, size
|
|||
{
|
||||
if (!has_attached_peer(description))
|
||||
return -EPIPE;
|
||||
auto role = this->role(description);
|
||||
if (role == Role::Accepted)
|
||||
return m_for_client.write((const u8*)data, data_size);
|
||||
if (role == Role::Connected)
|
||||
return m_for_server.write((const u8*)data, data_size);
|
||||
ASSERT_NOT_REACHED();
|
||||
ssize_t nwritten = send_buffer_for(description).write((const u8*)data, data_size);
|
||||
if (nwritten > 0)
|
||||
current->did_unix_socket_write(nwritten);
|
||||
return nwritten;
|
||||
}
|
||||
|
||||
DoubleBuffer& LocalSocket::buffer_for(FileDescription& description)
|
||||
DoubleBuffer& LocalSocket::receive_buffer_for(FileDescription& description)
|
||||
{
|
||||
auto role = this->role(description);
|
||||
if (role == Role::Accepted)
|
||||
|
@ -240,9 +238,19 @@ DoubleBuffer& LocalSocket::buffer_for(FileDescription& description)
|
|||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
DoubleBuffer& LocalSocket::send_buffer_for(FileDescription& description)
|
||||
{
|
||||
auto role = this->role(description);
|
||||
if (role == Role::Connected)
|
||||
return m_for_server;
|
||||
if (role == Role::Accepted)
|
||||
return m_for_client;
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
ssize_t LocalSocket::recvfrom(FileDescription& description, void* buffer, size_t buffer_size, int, sockaddr*, socklen_t*)
|
||||
{
|
||||
auto& buffer_for_me = buffer_for(description);
|
||||
auto& buffer_for_me = receive_buffer_for(description);
|
||||
if (!description.is_blocking()) {
|
||||
if (buffer_for_me.is_empty()) {
|
||||
if (!has_attached_peer(description))
|
||||
|
@ -257,7 +265,10 @@ ssize_t LocalSocket::recvfrom(FileDescription& description, void* buffer, size_t
|
|||
if (!has_attached_peer(description) && buffer_for_me.is_empty())
|
||||
return 0;
|
||||
ASSERT(!buffer_for_me.is_empty());
|
||||
return buffer_for_me.read((u8*)buffer, buffer_size);
|
||||
int nread = buffer_for_me.read((u8*)buffer, buffer_size);
|
||||
if (nread > 0)
|
||||
current->did_unix_socket_read(nread);
|
||||
return nread;
|
||||
}
|
||||
|
||||
StringView LocalSocket::socket_path() const
|
||||
|
|
|
@ -36,7 +36,8 @@ private:
|
|||
virtual bool is_local() const override { return true; }
|
||||
bool has_attached_peer(const FileDescription&) const;
|
||||
static Lockable<InlineLinkedList<LocalSocket>>& all_sockets();
|
||||
DoubleBuffer& buffer_for(FileDescription&);
|
||||
DoubleBuffer& receive_buffer_for(FileDescription&);
|
||||
DoubleBuffer& send_buffer_for(FileDescription&);
|
||||
|
||||
// An open socket file on the filesystem.
|
||||
RefPtr<FileDescription> m_file;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue