diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-07 18:21:37 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-07 22:16:25 +0200 |
commit | 905065f8c8dd4459f843fc8eb5faa87b64e42b2e (patch) | |
tree | f4bdbf01dc519338be6542babce0c0163784f2d7 | |
parent | 6f992d784f986d8ecf95eb3ac455310fa2222eb3 (diff) | |
download | serenity-905065f8c8dd4459f843fc8eb5faa87b64e42b2e.zip |
Kernel: Make PerformanceEventBuffer::to_json() return a KResult
There's a ton of things inside to_json() that could go wrong but we
don't know about it yet. One step at a time.
-rw-r--r-- | Kernel/GlobalProcessExposed.cpp | 6 | ||||
-rw-r--r-- | Kernel/PerformanceEventBuffer.cpp | 6 | ||||
-rw-r--r-- | Kernel/PerformanceEventBuffer.h | 4 | ||||
-rw-r--r-- | Kernel/Process.cpp | 2 | ||||
-rw-r--r-- | Kernel/ProcessSpecificExposed.cpp | 2 |
5 files changed, 8 insertions, 12 deletions
diff --git a/Kernel/GlobalProcessExposed.cpp b/Kernel/GlobalProcessExposed.cpp index 4f06fe18b3..ef4abe4799 100644 --- a/Kernel/GlobalProcessExposed.cpp +++ b/Kernel/GlobalProcessExposed.cpp @@ -721,11 +721,7 @@ private: { if (!g_global_perf_events) return ENOENT; - - // FIXME: to_json() should return a better error. - if (!g_global_perf_events->to_json(builder)) - return ENOMEM; - + TRY(g_global_perf_events->to_json(builder)); return KSuccess; } }; diff --git a/Kernel/PerformanceEventBuffer.cpp b/Kernel/PerformanceEventBuffer.cpp index 09f01eb62f..17380fd3d2 100644 --- a/Kernel/PerformanceEventBuffer.cpp +++ b/Kernel/PerformanceEventBuffer.cpp @@ -164,7 +164,7 @@ PerformanceEvent& PerformanceEventBuffer::at(size_t index) } template<typename Serializer> -bool PerformanceEventBuffer::to_json_impl(Serializer& object) const +KResult PerformanceEventBuffer::to_json_impl(Serializer& object) const { { auto strings = object.add_array("strings"); @@ -263,10 +263,10 @@ bool PerformanceEventBuffer::to_json_impl(Serializer& object) const } array.finish(); object.finish(); - return true; + return KSuccess; } -bool PerformanceEventBuffer::to_json(KBufferBuilder& builder) const +KResult PerformanceEventBuffer::to_json(KBufferBuilder& builder) const { JsonObjectSerializer object(builder); return to_json_impl(object); diff --git a/Kernel/PerformanceEventBuffer.h b/Kernel/PerformanceEventBuffer.h index dd2d830c4e..a217f99ad5 100644 --- a/Kernel/PerformanceEventBuffer.h +++ b/Kernel/PerformanceEventBuffer.h @@ -116,7 +116,7 @@ public: return const_cast<PerformanceEventBuffer&>(*this).at(index); } - bool to_json(KBufferBuilder&) const; + KResult to_json(KBufferBuilder&) const; void add_process(const Process&, ProcessEventType event_type); @@ -126,7 +126,7 @@ private: explicit PerformanceEventBuffer(NonnullOwnPtr<KBuffer>); template<typename Serializer> - bool to_json_impl(Serializer&) const; + KResult to_json_impl(Serializer&) const; PerformanceEvent& at(size_t index); diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index a1ce03fe9d..fb512ea546 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -581,7 +581,7 @@ bool Process::dump_perfcore() return false; } auto builder = builder_or_error.release_value(); - if (!m_perf_event_buffer->to_json(builder)) { + if (m_perf_event_buffer->to_json(builder).is_error()) { dbgln("Failed to generate perfcore for pid {}: Could not serialize performance events to JSON.", pid().value()); return false; } diff --git a/Kernel/ProcessSpecificExposed.cpp b/Kernel/ProcessSpecificExposed.cpp index 4439b593b6..be8014f8e4 100644 --- a/Kernel/ProcessSpecificExposed.cpp +++ b/Kernel/ProcessSpecificExposed.cpp @@ -166,7 +166,7 @@ KResult Process::procfs_get_perf_events(KBufferBuilder& builder) const dbgln("ProcFS: No perf events for {}", pid()); return KResult(ENOBUFS); } - return perf_events()->to_json(builder) ? KSuccess : KResult(EINVAL); + return perf_events()->to_json(builder); } KResult Process::procfs_get_fds_stats(KBufferBuilder& builder) const |