| 1 | /* |
| 2 | * Copyright (c) 2019, Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included |
| 12 | * in all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSNextE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 | * OTHER DEALINGS IN THE SOFTWARE. |
| 21 | */ |
| 22 | //! \file mos_os_next.cpp |
| 23 | //! \brief Unified OS Formats |
| 24 | //! \details Unified OS Formats |
| 25 | //! |
| 26 | |
| 27 | #include "mos_os_next.h" |
| 28 | #include "mos_interface.h" |
| 29 | #include "mos_gpucontext_specific_next.h" |
| 30 | |
| 31 | #if MOS_COMMAND_RESINFO_DUMP_SUPPORTED |
| 32 | |
| 33 | std::shared_ptr<GpuCmdResInfoDumpNext> GpuCmdResInfoDumpNext::m_instance = nullptr; |
| 34 | |
| 35 | const GpuCmdResInfoDumpNext *GpuCmdResInfoDumpNext::GetInstance(PMOS_CONTEXT mosCtx) |
| 36 | { |
| 37 | if (m_instance == nullptr) |
| 38 | { |
| 39 | m_instance = std::make_shared<GpuCmdResInfoDumpNext>(mosCtx); |
| 40 | } |
| 41 | return m_instance.get(); |
| 42 | } |
| 43 | |
| 44 | GpuCmdResInfoDumpNext::GpuCmdResInfoDumpNext(PMOS_CONTEXT mosCtx) |
| 45 | { |
| 46 | MediaUserSettingSharedPtr userSettingPtr = nullptr; |
| 47 | MediaUserSetting::Value value; |
| 48 | |
| 49 | userSettingPtr = MosInterface::MosGetUserSettingInstance(mosCtx); |
| 50 | |
| 51 | ReadUserSetting( |
| 52 | userSettingPtr, |
| 53 | m_dumpEnabled, |
| 54 | __MEDIA_USER_FEATURE_VALUE_DUMP_COMMAND_INFO_ENABLE, |
| 55 | MediaUserSetting::Group::Device); |
| 56 | |
| 57 | if (!m_dumpEnabled) |
| 58 | { |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | ReadUserSetting( |
| 63 | userSettingPtr, |
| 64 | value, |
| 65 | __MEDIA_USER_FEATURE_VALUE_DUMP_COMMAND_INFO_PATH, |
| 66 | MediaUserSetting::Group::Device); |
| 67 | |
| 68 | auto path = value.ConstString(); |
| 69 | if(path.size() > 0) |
| 70 | { |
| 71 | m_path = path; |
| 72 | if (path.back() != '/' && path.back() != '\\') |
| 73 | { |
| 74 | m_path += '/'; |
| 75 | } |
| 76 | } |
| 77 | m_path = m_path + "gpuCmdResInfo_" + std::to_string(MosUtilities::MosGetPid()) + ".txt"; |
| 78 | } |
| 79 | |
| 80 | void GpuCmdResInfoDumpNext::Dump(PMOS_INTERFACE pOsInterface) const |
| 81 | { |
| 82 | if (!m_dumpEnabled) |
| 83 | { |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | using std::endl; |
| 88 | |
| 89 | std::ofstream outputFile; |
| 90 | outputFile.open(m_path, std::ios_base::app); |
| 91 | if(!outputFile.is_open()) |
| 92 | { |
| 93 | MOS_OS_ASSERTMESSAGE("file open failed"); |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | auto &cmdResInfoPtrs = GetCmdResPtrs(pOsInterface); |
| 98 | |
| 99 | outputFile << "--PerfTag: " << std::to_string(pOsInterface->pfnGetPerfTag(pOsInterface)) << " --Cmd Num: " |
| 100 | << cmdResInfoPtrs.size() << " --Dump Count: " << ++m_cnt << endl; |
| 101 | |
| 102 | outputFile << "********************************CMD Paket Begin********************************" << endl; |
| 103 | for (auto e : cmdResInfoPtrs) |
| 104 | { |
| 105 | Dump(e, outputFile); |
| 106 | } |
| 107 | outputFile << "********************************CMD Paket End**********************************" << endl << endl; |
| 108 | |
| 109 | outputFile.close(); |
| 110 | } |
| 111 | |
| 112 | const char *GpuCmdResInfoDumpNext::GetResType(MOS_GFXRES_TYPE resType) const |
| 113 | { |
| 114 | switch (resType) |
| 115 | { |
| 116 | case MOS_GFXRES_INVALID: |
| 117 | return "MOS_GFXRES_INVALID"; |
| 118 | case MOS_GFXRES_BUFFER: |
| 119 | return "MOS_GFXRES_BUFFER"; |
| 120 | case MOS_GFXRES_2D: |
| 121 | return "MOS_GFXRES_2D"; |
| 122 | case MOS_GFXRES_VOLUME: |
| 123 | return "MOS_GFXRES_VOLUME"; |
| 124 | default: |
| 125 | return ""; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | const char *GpuCmdResInfoDumpNext::GetTileType(MOS_TILE_TYPE tileType) const |
| 130 | { |
| 131 | switch (tileType) |
| 132 | { |
| 133 | case MOS_TILE_X: |
| 134 | return "MOS_TILE_X"; |
| 135 | case MOS_TILE_Y: |
| 136 | return "MOS_TILE_Y"; |
| 137 | case MOS_TILE_YF: |
| 138 | return "MOS_TILE_YF"; |
| 139 | case MOS_TILE_YS: |
| 140 | return "MOS_TILE_YS"; |
| 141 | case MOS_TILE_LINEAR: |
| 142 | return "MOS_TILE_LINEAR"; |
| 143 | case MOS_TILE_INVALID: |
| 144 | return "MOS_TILE_INVALID"; |
| 145 | default: |
| 146 | return ""; |
| 147 | } |
| 148 | } |
| 149 | #endif // MOS_COMMAND_RESINFO_DUMP_SUPPORTED |