LCOV - code coverage report
Current view: top level - gjs - profiler-private.h (source / functions) Coverage Total Hit
Test: gjs-1.89.90 Code Coverage Lines: 77.8 % 9 7
Test Date: 2026-11-08 19:38:12 Functions: 100.0 % 2 2
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 50.0 % 4 2

             Branch data     Line data    Source code
       1                 :             : /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
       2                 :             : // SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
       3                 :             : // SPDX-FileCopyrightText: 2018 Endless Mobile, Inc.
       4                 :             : 
       5                 :             : #pragma once
       6                 :             : 
       7                 :             : #include <config.h>
       8                 :             : 
       9                 :             : #include <stdint.h>
      10                 :             : 
      11                 :             : #include <chrono>
      12                 :             : #include <ratio>  // for nano
      13                 :             : #include <string>
      14                 :             : 
      15                 :             : #include <js/GCAPI.h>  // for JSFinalizeStatus, JSGCStatus, GCReason
      16                 :             : #include <js/ProfilingCategory.h>
      17                 :             : #include <js/ProfilingStack.h>
      18                 :             : #include <js/RootingAPI.h>
      19                 :             : #include <js/TypeDecls.h>
      20                 :             : 
      21                 :             : #include "gjs/context.h"
      22                 :             : #include "gjs/profiler.h"
      23                 :             : #include "util/misc.h"
      24                 :             : 
      25                 :             : #define GJS_PROFILER_DYNAMIC_STRING(cx, str) \
      26                 :             :     js::GetContextProfilingStackIfEnabled(cx) ? (str) : ""
      27                 :             : 
      28                 :             : class AutoProfilerLabel {
      29                 :             :  public:
      30                 :             :     // This dynamicString parameter looks like a prime candidate for conversion
      31                 :             :     // into a format string, which would enable formatting into a buffer to
      32                 :             :     // avoid allocations, but benchmark it first, particularly in the
      33                 :             :     // profiler-disabled case. The current code is basically a no-op with
      34                 :             :     // profiling disabled and using GJS_PROFILER_DYNAMIC_STRING.
      35                 :       87083 :     explicit AutoProfilerLabel(JSContext* cx, const char* label,
      36                 :             :                                const std::string& dynamicString,
      37                 :             :                                JS::ProfilingCategoryPair categoryPair =
      38                 :             :                                    JS::ProfilingCategoryPair::OTHER,
      39                 :             :                                uint32_t flags = 0)
      40                 :       87083 :         : m_stack(js::GetContextProfilingStackIfEnabled(cx)) {
      41         [ -  + ]:       87083 :         if (m_stack)
      42                 :           0 :             m_stack->pushLabelFrame(label, dynamicString.c_str(), this,
      43                 :             :                                     categoryPair, flags);
      44                 :       87083 :     }
      45                 :             : 
      46                 :       87080 :     ~AutoProfilerLabel() {
      47         [ -  + ]:       87080 :         if (m_stack)
      48                 :           0 :             m_stack->pop();
      49                 :       87080 :     }
      50                 :             : 
      51                 :             :  private:
      52                 :             :     ProfilingStack* m_stack;
      53                 :             : };
      54                 :             : 
      55                 :             : namespace Gjs {
      56                 :             : enum GCCounters : uint8_t { GC_HEAP_BYTES, MALLOC_HEAP_BYTES, N_COUNTERS };
      57                 :             : }  // namespace Gjs
      58                 :             : 
      59                 :             : GjsProfiler* gjs_profiler_new(GjsContext*);
      60                 :             : void gjs_profiler_free(GjsProfiler*);
      61                 :             : 
      62                 :             : using ProfilerTimePoint =
      63                 :             :     std::chrono::time_point<GLib::MonotonicClock, std::chrono::nanoseconds>;
      64                 :             : using ProfilerDuration = std::chrono::duration<uint64_t, std::nano>;
      65                 :             : 
      66                 :             : void gjs_profiler_add_mark(GjsProfiler*, ProfilerTimePoint, ProfilerDuration,
      67                 :             :                            const char* group, const char* name,
      68                 :             :                            const char* message);
      69                 :             : 
      70                 :             : [[nodiscard]]
      71                 :             : bool gjs_profiler_sample_gc_memory_info(
      72                 :             :     GjsProfiler*, const int64_t gc_counters[Gjs::GCCounters::N_COUNTERS]);
      73                 :             : 
      74                 :             : [[nodiscard]] bool gjs_profiler_is_running(GjsProfiler*);
      75                 :             : 
      76                 :             : void gjs_profiler_setup_signals(GjsProfiler*, GjsContext*);
      77                 :             : 
      78                 :             : void gjs_profiler_set_finalize_status(GjsProfiler*, JSFinalizeStatus);
      79                 :             : void gjs_profiler_set_gc_status(GjsProfiler*, JSGCStatus, JS::GCReason);
        

Generated by: LCOV version 2.0-1