File: thk_wrapper.h

package info (click to toggle)
intel-compute-runtime 25.44.36015.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,632 kB
  • sloc: cpp: 931,547; lisp: 2,074; sh: 719; makefile: 162; python: 21
file content (80 lines) | stat: -rw-r--r-- 2,326 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * Copyright (C) 2018-2024 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#pragma once
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/helpers/options.h"
#include "shared/source/os_interface/windows/d3dkmthk_wrapper.h"
#include "shared/source/os_interface/windows/gdi_interface_logging.h"
#include "shared/source/os_interface/windows/gdi_profiling.h"
#include "shared/source/os_interface/windows/windows_wrapper.h"
#include "shared/source/utilities/api_intercept.h"

#include <chrono>
#include <iostream>
#include <string>

namespace NEO {

template <typename Param>
class ThkWrapper {
    typedef NTSTATUS(APIENTRY *Func)(Param);
    GdiProfiler &profiler;
    const std::string name{};
    const uint32_t id{};

  public:
    ThkWrapper(GdiProfiler &profiler, const char *name, uint32_t id) : profiler(profiler), name(name), id(id){};

    Func mFunc = nullptr;

    inline NTSTATUS operator()(Param param) const {
        if constexpr (GdiLogging::gdiLoggingSupport) {
            GdiLogging::logEnter<Param>(param);

            auto measureTime = debugManager.flags.PrintKmdTimes.get();
            std::chrono::steady_clock::time_point start;
            std::chrono::steady_clock::time_point end;

            if (measureTime) {
                start = std::chrono::steady_clock::now();
            }

            auto ret = mFunc(param);

            if (measureTime) {
                end = std::chrono::steady_clock::now();
                long long elapsedTime = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();

                profiler.recordElapsedTime(elapsedTime, this->name.c_str(), this->id);
            }

            GdiLogging::logExit<Param>(ret, param);

            return ret;
        } else {
            return mFunc(param);
        }
    }

    ThkWrapper &operator=(void *func) {
        mFunc = reinterpret_cast<decltype(mFunc)>(func);
        return *this;
    }

    ThkWrapper &operator=(Func func) {
        mFunc = func;
        return *this;
    }

    // This operator overload is for implicit casting ThkWrapper struct to Function Pointer in GetPfn methods like GetEscapePfn() or for comparing against NULL function pointer
    operator Func() const {
        return mFunc;
    }
};

} // namespace NEO