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 : : #include <string>
11 : :
12 : : #include <js/GCAPI.h> // for JSFinalizeStatus, JSGCStatus, GCReason
13 : : #include <js/ProfilingCategory.h>
14 : : #include <js/ProfilingStack.h>
15 : : #include <js/RootingAPI.h>
16 : : #include <js/TypeDecls.h>
17 : :
18 : : #include "gjs/context.h"
19 : : #include "gjs/profiler.h"
20 : :
21 : : #define GJS_PROFILER_DYNAMIC_STRING(cx, str) \
22 : : js::GetContextProfilingStackIfEnabled(cx) ? str : ""
23 : :
24 : : class AutoProfilerLabel {
25 : : public:
26 : 82896 : explicit inline AutoProfilerLabel(JSContext* cx, const char* label,
27 : : const std::string& dynamicString,
28 : : JS::ProfilingCategoryPair categoryPair =
29 : : JS::ProfilingCategoryPair::OTHER,
30 : : uint32_t flags = 0)
31 : 82896 : : m_stack(js::GetContextProfilingStackIfEnabled(cx)) {
32 [ - + ]: 82896 : if (m_stack)
33 : 0 : m_stack->pushLabelFrame(label, dynamicString.c_str(), this,
34 : : categoryPair, flags);
35 : 82896 : }
36 : :
37 : 82893 : inline ~AutoProfilerLabel() {
38 [ - + ]: 82893 : if (m_stack)
39 : 0 : m_stack->pop();
40 : 82893 : }
41 : :
42 : : private:
43 : : ProfilingStack* m_stack;
44 : : };
45 : :
46 : : namespace Gjs {
47 : : enum GCCounters { GC_HEAP_BYTES, MALLOC_HEAP_BYTES, N_COUNTERS };
48 : : } // namespace Gjs
49 : :
50 : : GjsProfiler* _gjs_profiler_new(GjsContext*);
51 : : void _gjs_profiler_free(GjsProfiler*);
52 : :
53 : : void _gjs_profiler_add_mark(GjsProfiler*, int64_t time, int64_t duration,
54 : : const char* group, const char* name,
55 : : const char* message);
56 : :
57 : : [[nodiscard]]
58 : : bool _gjs_profiler_sample_gc_memory_info(
59 : : GjsProfiler*, int64_t gc_counters[Gjs::GCCounters::N_COUNTERS]);
60 : :
61 : : [[nodiscard]] bool _gjs_profiler_is_running(GjsProfiler*);
62 : :
63 : : void _gjs_profiler_setup_signals(GjsProfiler*, GjsContext*);
64 : :
65 : : void _gjs_profiler_set_finalize_status(GjsProfiler*, JSFinalizeStatus);
66 : : void _gjs_profiler_set_gc_status(GjsProfiler*, JSGCStatus, JS::GCReason);
|