Path: blob/21.2-virgl/src/gallium/drivers/swr/rasterizer/common/rdtsc_buckets_shared.h
4574 views
/****************************************************************************1* Copyright (C) 2014-2015 Intel Corporation. All Rights Reserved.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*22* @file rdtsc_buckets.h23*24* @brief declaration for rdtsc buckets.25*26* Notes:27*28******************************************************************************/29#pragma once3031#include <vector>32#include <cassert>3334struct BUCKET35{36uint32_t id{0};37uint64_t start{0};38uint64_t elapsed{0};39uint32_t count{0};4041BUCKET* pParent{nullptr};42std::vector<BUCKET> children;43};4445struct BUCKET_DESC46{47// name of bucket, used in reports48std::string name;4950// description of bucket, used in threadviz51std::string description;5253// enable for threadviz dumping54bool enableThreadViz;5556// threadviz color of bucket, in RGBA8_UNORM format57uint32_t color;58};596061struct BUCKET_THREAD62{63// name of thread, used in reports64std::string name;6566// id for this thread, assigned by the thread manager67uint32_t id{0};6869// root of the bucket hierarchy for this thread70BUCKET root;7172// currently executing bucket somewhere in the hierarchy73BUCKET* pCurrent{nullptr};7475// currently executing hierarchy level76uint32_t level{0};7778// threadviz file object79FILE* vizFile{nullptr};808182BUCKET_THREAD() {}83BUCKET_THREAD(const BUCKET_THREAD& that)84{85name = that.name;86id = that.id;87root = that.root;88pCurrent = &root;89vizFile = that.vizFile;90}91};9293enum VIZ_TYPE94{95VIZ_START = 0,96VIZ_STOP = 1,97VIZ_DATA = 298};99100struct VIZ_START_DATA101{102uint8_t type;103uint32_t bucketId;104uint64_t timestamp;105};106107struct VIZ_STOP_DATA108{109uint8_t type;110uint64_t timestamp;111};112113inline void Serialize(FILE* f, const VIZ_START_DATA& data)114{115fwrite(&data, sizeof(VIZ_START_DATA), 1, f);116}117118inline void Deserialize(FILE* f, VIZ_START_DATA& data)119{120fread(&data, sizeof(VIZ_START_DATA), 1, f);121assert(data.type == VIZ_START);122}123124inline void Serialize(FILE* f, const VIZ_STOP_DATA& data)125{126fwrite(&data, sizeof(VIZ_STOP_DATA), 1, f);127}128129inline void Deserialize(FILE* f, VIZ_STOP_DATA& data)130{131fread(&data, sizeof(VIZ_STOP_DATA), 1, f);132assert(data.type == VIZ_STOP);133}134135inline void Serialize(FILE* f, const std::string& string)136{137assert(string.size() <= 256);138139uint8_t length = (uint8_t)string.size();140fwrite(&length, sizeof(length), 1, f);141fwrite(string.c_str(), string.size(), 1, f);142}143144inline void Deserialize(FILE* f, std::string& string)145{146char cstr[256];147uint8_t length;148fread(&length, sizeof(length), 1, f);149fread(cstr, length, 1, f);150cstr[length] = 0;151string.assign(cstr);152}153154inline void Serialize(FILE* f, const BUCKET_DESC& desc)155{156Serialize(f, desc.name);157Serialize(f, desc.description);158fwrite(&desc.enableThreadViz, sizeof(desc.enableThreadViz), 1, f);159fwrite(&desc.color, sizeof(desc.color), 1, f);160}161162inline void Deserialize(FILE* f, BUCKET_DESC& desc)163{164Deserialize(f, desc.name);165Deserialize(f, desc.description);166fread(&desc.enableThreadViz, sizeof(desc.enableThreadViz), 1, f);167fread(&desc.color, sizeof(desc.color), 1, f);168}169170171