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 : 85008 : explicit AutoProfilerLabel(JSContext* cx, const char* label,
31 : : const std::string& dynamicString,
32 : : JS::ProfilingCategoryPair categoryPair =
33 : : JS::ProfilingCategoryPair::OTHER,
34 : : uint32_t flags = 0)
35 : 85008 : : m_stack(js::GetContextProfilingStackIfEnabled(cx)) {
36 [ - + ]: 85008 : if (m_stack)
37 : 0 : m_stack->pushLabelFrame(label, dynamicString.c_str(), this,
38 : : categoryPair, flags);
39 : 85008 : }
40 : :
41 : 85005 : ~AutoProfilerLabel() {
42 [ - + ]: 85005 : if (m_stack)
43 : 0 : m_stack->pop();
44 : 85005 : }
45 : :
46 : : private:
47 : : ProfilingStack* m_stack;
48 : : };
49 : :
50 : : namespace Gjs {
51 : : enum GCCounters : uint8_t { GC_HEAP_BYTES, MALLOC_HEAP_BYTES, N_COUNTERS };
52 : : } // namespace Gjs
53 : :
54 : : GjsProfiler* gjs_profiler_new(GjsContext*);
55 : : void gjs_profiler_free(GjsProfiler*);
56 : :
57 : : using ProfilerTimePoint =
58 : : std::chrono::time_point<GLib::MonotonicClock, std::chrono::nanoseconds>;
59 : : using ProfilerDuration = std::chrono::duration<uint64_t, std::nano>;
60 : :
61 : : void gjs_profiler_add_mark(GjsProfiler*, ProfilerTimePoint, ProfilerDuration,
62 : : const char* group, const char* name,
63 : : const char* message);
64 : :
65 : : [[nodiscard]]
66 : : bool gjs_profiler_sample_gc_memory_info(
67 : : GjsProfiler*, const int64_t gc_counters[Gjs::GCCounters::N_COUNTERS]);
68 : :
69 : : [[nodiscard]] bool gjs_profiler_is_running(GjsProfiler*);
70 : :
71 : : void gjs_profiler_setup_signals(GjsProfiler*, GjsContext*);
72 : :
73 : : void gjs_profiler_set_finalize_status(GjsProfiler*, JSFinalizeStatus);
74 : : void gjs_profiler_set_gc_status(GjsProfiler*, JSGCStatus, JS::GCReason);
|