private static void Start() { lastFrameCounter = Engine.FrameCounter; watch.Restart(); $"Benchmark Start: {InputController.TasFilePath}".Log(); MeasureProfiler.StartCollectingData(); }
private void LoadModels(IProgressReceiver progressReceiver, McResourcePack resourcePack, bool replaceModels, bool reportMissingModels) { Stopwatch sw = Stopwatch.StartNew(); var modelRegistry = RegistryManager.GetRegistry <ResourcePackModelBase>(); int imported = 0; if (modelRegistry is BlockModelRegistry bmr) { imported = bmr.LoadResourcePack(progressReceiver, resourcePack); } Log.Info($"Imported {imported} block models from resourcepack in {sw.ElapsedMilliseconds}ms!"); sw.Restart(); MeasureProfiler.StartCollectingData(); imported = BlockFactory.LoadBlockstates(RegistryManager, this, resourcePack, replaceModels, reportMissingModels, progressReceiver); MeasureProfiler.SaveData(); MeasureProfiler.StopCollectingData(); Log.Info($"Imported {imported} blockstates from resourcepack in {sw.ElapsedMilliseconds}ms!"); }
private static Session RunProfiler(Config config) { Trace.Verbose("DotTrace.RunConsole: Looking for runner..."); var runnerPath = ConsoleRunnerPackage.GetRunnerPath(); var commandLine = new StringBuilder(); commandLine.Append($"attach {Process.GetCurrentProcess().Id}"); commandLine.Append($" --profiling-type={config.Type}"); commandLine.Append(" --service-input=stdin --service-output=On"); commandLine.Append(" --collect-data-from-start=Off"); commandLine.Append(" --use-api"); if (config.LogFile != null) { commandLine.Append($" \"--log-file={config.LogFile}\" --debug-logging"); } if (config.IsOverwriteSnapshot) { commandLine.Append(" --overwrite"); } if (config.SnapshotDir != null) { commandLine.Append($" \"--save-to={config.SnapshotDir}\""); } if (config.SnapshotFile != null) { commandLine.Append($" \"--save-to={config.SnapshotFile}\""); } if (config.AskUacElevationIfRequired && config.Type == Config.ProfilingType.Timeline) { commandLine.Append(" --ask-uac-elevation"); } if (config.OtherArguments != null) { commandLine.Append(' ').Append(config.OtherArguments); } Trace.Info("DotTrace.RunConsole:\n runner = `{0}`\n arguments = `{1}`", runnerPath, commandLine); var collectedSnapshots = new CollectedSnapshots(); var consoleProfiler = new ConsoleProfiler( runnerPath, commandLine.ToString(), MessageServicePrefix, CltPresentableName, () => (MeasureProfiler.GetFeatures() & MeasureFeatures.Ready) == MeasureFeatures.Ready, collectedSnapshots); Trace.Verbose("DotTrace.RunConsole: Runner started."); return(new Session(consoleProfiler, collectedSnapshots)); }
private static void Stop() { MeasureProfiler.SaveData(); ulong frames = Engine.FrameCounter - lastFrameCounter; float framesPerSecond = (int)Math.Round(1 / Engine.RawDeltaTime); $"Benchmark Stop: frames={frames} time={watch.ElapsedMilliseconds}ms avg_speed={frames / framesPerSecond / watch.ElapsedMilliseconds * 1000f}" .Log(); watch.Stop(); }
static void VwSalesByCategoryContainsPerf() { var benchmark = new QueryGenerationBenchmark(); benchmark.DataProvider = ProviderName.Access; #if JETBRAINS MeasureProfiler.StartCollectingData(); #endif benchmark.VwSalesByCategoryContains(); for (int i = 0; i < 100; i++) { benchmark.VwSalesByCategoryContains(); } #if JETBRAINS MeasureProfiler.StopCollectingData(); // MeasureProfiler.StopCollectingData(); MeasureProfiler.SaveData(); #endif }
private void HandleChunk(byte[] chunkData, int cx, int cz, Action <ChunkColumn> callback) { MeasureProfiler.StartCollectingData(); var profiler = MiniProfiler.StartNew("BEToJavaColumn"); try { using (MemoryStream stream = new MemoryStream(chunkData)) { NbtBinaryReader defStream = new NbtBinaryReader(stream, true); int count = defStream.ReadByte(); if (count < 1) { Log.Warn("Nothing to read"); return; } ChunkColumn chunkColumn = new ChunkColumn(); chunkColumn.IsDirty = true; chunkColumn.X = cx; chunkColumn.Z = cz; for (int s = 0; s < count; s++) { var section = chunkColumn.Sections[s] as ChunkSection; if (section == null) { section = new ChunkSection(s, true); } int version = defStream.ReadByte(); if (version == 1 || version == 8) { int storageSize = defStream.ReadByte(); for (int storage = 0; storage < storageSize; storage++) { int paletteAndFlag = defStream.ReadByte(); bool isRuntime = (paletteAndFlag & 1) != 0; int bitsPerBlock = paletteAndFlag >> 1; int blocksPerWord = (int)Math.Floor(32f / bitsPerBlock); int wordCount = (int)Math.Ceiling(4096.0f / blocksPerWord); uint[] words = new uint[wordCount]; for (int w = 0; w < wordCount; w++) { int word = defStream.ReadInt32(); words[w] = SwapBytes((uint)word); } uint[] pallete = new uint[0]; if (isRuntime) { int palleteSize = VarInt.ReadSInt32(stream); pallete = new uint[palleteSize]; for (int pi = 0; pi < pallete.Length; pi++) { var ui = (uint)VarInt.ReadSInt32(stream); pallete[pi] = ui; } if (palleteSize == 0) { Log.Warn($"Pallete size is 0"); continue; } } int position = 0; for (int w = 0; w < wordCount; w++) { uint word = words[w]; for (int block = 0; block < blocksPerWord; block++) { if (position >= 4096) { break; // padding bytes } uint state = (uint)((word >> ((position % blocksPerWord) * bitsPerBlock)) & ((1 << bitsPerBlock) - 1)); int x = (position >> 8) & 0xF; int y = position & 0xF; int z = (position >> 4) & 0xF; if (storage == 0) { if (state >= pallete.Length) { continue; } IBlockState translated = _convertedStates.GetOrAdd(pallete[state], u => { if (_blockStateMap.TryGetValue(pallete[state], out var bs)) { var result = BlockFactory.RuntimeIdTable.FirstOrDefault(xx => xx.Name == bs.Name); if (result != null && result.Id >= 0) { var reverseMap = MiNET.Worlds.AnvilWorldProvider.Convert.FirstOrDefault(map => map.Value.Item1 == result.Id); var id = result.Id; if (reverseMap.Value != null) { id = reverseMap.Key; } var res = BlockFactory.GetBlockStateID( (int)id, (byte)bs.Data); if (AnvilWorldProvider.BlockStateMapper.TryGetValue( res, out var res2)) { var t = BlockFactory.GetBlockState(res2); t = TranslateBlockState(t, id, bs.Data); return(t); } else { Log.Info( $"Did not find anvil statemap: {result.Name}"); return(TranslateBlockState( BlockFactory.GetBlockState(result.Name), id, bs.Data)); } } return(TranslateBlockState( BlockFactory.GetBlockState(bs.Name), -1, bs.Data)); } return(null); }); if (translated != null) { section.Set(x, y, z, translated); } } else { //TODO. } position++; } if (position >= 4096) { break; } } } } else { #region OldFormat byte[] blockIds = new byte[4096]; defStream.Read(blockIds, 0, blockIds.Length); NibbleArray data = new NibbleArray(4096); defStream.Read(data.Data, 0, data.Data.Length); for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { for (int y = 0; y < 16; y++) { int idx = (x << 8) + (z << 4) + y; var id = blockIds[idx]; var meta = data[idx]; IBlockState result = null; if (id > 0 && result == null) { var res = BlockFactory.GetBlockStateID(id, meta); if (AnvilWorldProvider.BlockStateMapper.TryGetValue(res, out var res2)) { var t = BlockFactory.GetBlockState(res2); t = TranslateBlockState(t, id, meta); result = t; } else { Log.Info($"Did not find anvil statemap: {result.Name}"); result = TranslateBlockState(BlockFactory.GetBlockState(res), id, meta); } } if (result == null) { var results = BlockFactory.RuntimeIdTable.Where(xx => xx.Id == id && xx.Data == meta).ToArray(); if (results.Length > 0) { result = TranslateBlockState( BlockFactory.GetBlockState((uint)results[0].RuntimeId), id, meta); } } if (result != null) { section.Set(x, y, z, result); } } } } #endregion } if (UseAlexChunks) { // Log.Info($"Alex chunk!"); var rawSky = new Utils.NibbleArray(4096); defStream.Read(rawSky.Data, 0, rawSky.Data.Length); var rawBlock = new Utils.NibbleArray(4096); defStream.Read(rawBlock.Data, 0, rawBlock.Data.Length); for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { var peIndex = (x * 256) + (z * 16) + y; var sky = rawSky[peIndex]; var block = rawBlock[peIndex]; var idx = y << 8 | z << 4 | x; section.SkyLight[idx] = sky; section.BlockLight[idx] = block; } } } } section.RemoveInvalidBlocks(); section.IsDirty = true; //Make sure the section is saved. chunkColumn.Sections[s] = section; } byte[] ba = new byte[512]; if (defStream.Read(ba, 0, 256 * 2) != 256 * 2) { Log.Error($"Out of data height"); } Buffer.BlockCopy(ba, 0, chunkColumn.Height, 0, 512); int[] biomeIds = new int[256]; for (int i = 0; i < biomeIds.Length; i++) { biomeIds[i] = defStream.ReadByte(); } chunkColumn.BiomeId = biomeIds; if (stream.Position >= stream.Length - 1) { callback?.Invoke(chunkColumn); return; } int borderBlock = VarInt.ReadSInt32(stream); if (borderBlock > 0) { byte[] buf = new byte[borderBlock]; int len = defStream.Read(buf, 0, borderBlock); } if (stream.Position < stream.Length - 1) { while (stream.Position < stream.Length) { NbtFile file = new NbtFile() { BigEndian = false, UseVarInt = true }; file.LoadFromStream(stream, NbtCompression.None); } } if (stream.Position < stream.Length - 1) { Log.Warn( $"Still have data to read\n{Packet.HexDump(defStream.ReadBytes((int) (stream.Length - stream.Position)))}"); } //Done processing this chunk, send to world callback?.Invoke(chunkColumn); } } catch (Exception ex) { Log.Error($"Exception in chunk loading: {ex.ToString()}"); } finally { profiler?.Stop(); MeasureProfiler.SaveData(); } }
public Session StopCollectingData() { MeasureProfiler.StopCollectingData(); return(this); }
public Session DropData() { MeasureProfiler.DropData(); return(this); }
public Session SaveData() { MeasureProfiler.SaveData(); _consoleProfiler.AwaitResponse("(?:snapshot-saved|get-snapshot-error)", -1); return(this); }
public Session Detach() { MeasureProfiler.Detach(); return(this); }
private void LoadResourcePacks(GraphicsDevice device, IProgressReceiver progress, string[] resourcePacks) { var countBefore = ActiveResourcePacks.Count; var first = ActiveResourcePacks.First.Value; var before = ActiveResourcePacks.ToArray(); foreach (var item in before.Skip(1)) { item.Dispose(); } ActiveResourcePacks.Clear(); ActiveResourcePacks.AddFirst(first); if (_hasInit) { PreloadCallback?.Invoke(first.FontBitmap, McResourcePack.BitmapFontCharacters.ToList()); Atlas.Reset(); } foreach (string file in resourcePacks) { try { string resourcePackPath = Path.Combine(ResourcePackDirectory.FullName, file); if (File.Exists(resourcePackPath)) { //Log.Info($"Loading resourcepack {file}..."); //using (FileStream stream = new FileStream(resourcePackPath, FileMode.Open)) { // using (ZipFileSystem zipFileSystem = ) { var pack = LoadResourcePack(progress, new ZipFileSystem(new FileStream(resourcePackPath, FileMode.Open), Path.GetFileNameWithoutExtension(resourcePackPath)), null); if (pack is McResourcePack javaPack) { if (pack.Info != null && string.IsNullOrWhiteSpace(pack.Info.Name)) { pack.Info.Name = Path.GetFileNameWithoutExtension(file); } ActiveResourcePacks.AddLast(javaPack); } else if (pack is BedrockResourcePack bedrockPack) { ActiveBedrockResourcePacks.AddLast(bedrockPack); } } } } } catch (Exception e) { Log.Warn(e, $"Could not load resourcepack {file}: {e.ToString()}"); } } var active = ActiveResourcePacks.ToArray(); bool isFirst = true; foreach (var resourcePack in active) { Alex.GuiRenderer.LoadLanguages(resourcePack, progress); LoadModels(progress, resourcePack, !isFirst, isFirst); if (isFirst) { //Only load models for vanilla until above we fix blockstate replacement issues. isFirst = false; // break; } } Stopwatch sw = Stopwatch.StartNew(); MeasureProfiler.StartCollectingData(); var imported = BlockFactory.LoadBlockstates(RegistryManager, this, false, false, progress); MeasureProfiler.SaveData(); MeasureProfiler.StopCollectingData(); Log.Info($"Imported {imported} blockstates from resourcepack in {sw.ElapsedMilliseconds}ms!"); var textures = new Dictionary <ResourceLocation, AtlasGenerator.ImageEntry>(); for (var index = 0; index < active.Length; index++) { var resourcePack = active[index]; progress?.UpdateProgress(0, $"Loading textures: {resourcePack.Info?.Name ?? "Unknown"}"); Atlas.LoadResourcePackOnTop(device, textures, resourcePack, progress, index == active.Length - 1); //LoadTextures(device, progress, resourcePack, ref textures, index == active.Length - 1); } foreach (var resourcePack in ActiveBedrockResourcePacks) { LoadEntityModels(resourcePack, progress); int modelCount = EntityFactory.LoadModels(resourcePack, this, device, true, progress); Log.Info($"Imported {modelCount} entity models..."); } progress?.UpdateProgress(0, $"Loading UI textures..."); Alex.GuiRenderer.LoadResourcePackTextures(this, progress); progress?.UpdateProgress(50, "Loading language..."); if (!Alex.GuiRenderer.SetLanguage(Options.AlexOptions.MiscelaneousOptions.Language.Value)) { Alex.GuiRenderer.SetLanguage(CultureInfo.InstalledUICulture.Name); } progress?.UpdateProgress(100, "Loading language..."); var f = ActiveResourcePacks.LastOrDefault(x => x.FontBitmap != null); if (f != null) { PreloadCallback?.Invoke(f.FontBitmap, McResourcePack.BitmapFontCharacters.ToList()); } }