Package nallar.tickthreading.minecraft.profiling

Examples of nallar.tickthreading.minecraft.profiling.EntityTickProfiler


    } else {
      worlds.add(world);
    }
    final int hashCode = x != null ? TickManager.getHashCode(x * 16, z * 16) : 0;
    if (entity) {
      final EntityTickProfiler entityTickProfiler = EntityTickProfiler.ENTITY_TICK_PROFILER;
      if (location) {
        if (!world.getChunkProvider().chunkExists(x, z)) {
          sendChat(commandSender, "The chunk coords " + x + ',' + z + " are not loaded, can not profile.");
          return;
        }
      }
      if (!entityTickProfiler.startProfiling(new Runnable() {
        @Override
        public void run() {
          if (location) {
            TickRegion tickRegion = manager.getEntityRegion(hashCode);
            if (tickRegion != null) {
              tickRegion.profilingEnabled = false;
            }
            tickRegion = manager.getTileEntityRegion(hashCode);
            if (tickRegion != null) {
              tickRegion.profilingEnabled = false;
            }
          }
          sendChat(commandSender, entityTickProfiler.writeStringData(new TableFormatter(commandSender)).toString());
        }
      }, location ? ProfilingState.CHUNK : ProfilingState.GLOBAL, time, worlds)) {
        sendChat(commandSender, "Someone else is currently profiling.");
      }
      if (location) {
View Full Code Here


      return profilingInterval * 60 * 20;
    }

    @Override
    public void tickStart(final EnumSet<TickType> type, final Object... tickData) {
      final EntityTickProfiler entityTickProfiler = EntityTickProfiler.ENTITY_TICK_PROFILER;
      entityTickProfiler.startProfiling(new Runnable() {
        @Override
        public void run() {
          try {
            TableFormatter tf = new TableFormatter(MinecraftServer.getServer());
            tf.tableSeparator = "\n";
            if (json) {
              entityTickProfiler.writeJSONData(profilingFile);
            } else {
              Files.write(entityTickProfiler.writeStringData(tf, 6).toString(), profilingFile, Charsets.UTF_8);
            }
          } catch (Throwable t) {
            Log.severe("Failed to save periodic profiling data to " + profilingFile, t);
          }
        }
View Full Code Here

  @Override
  public void doTick() {
    ChunkProviderServer chunkProvider = (ChunkProviderServer) world.getChunkProvider();
    boolean profilingEnabled = manager.profilingEnabled || this.profilingEnabled;
    EntityTickProfiler entityTickProfiler = profilingEnabled ? EntityTickProfiler.ENTITY_TICK_PROFILER : null;
    long startTime = 0;
    Iterator<Entity> entitiesIterator = entitySet.startIteration();
    try {
      while (entitiesIterator.hasNext()) {
        if (profilingEnabled) {
          startTime = System.nanoTime();
        }
        Entity entity = entitiesIterator.next();
        try {
          Entity ridingEntity = entity.ridingEntity;
          if (ridingEntity != null) {
            if (!ridingEntity.isDead && ridingEntity.riddenByEntity == entity) {
              continue;
            }

            ridingEntity.riddenByEntity = null;
            entity.ridingEntity = null;
          }

          if (!entity.isDead) {
            if (entity instanceof EntityPlayerMP) {
              Unsafe $ = UnsafeAccess.$;
              Object lock = ((EntityPlayerMP) entity).playerNetServerHandler;
              if ($.tryMonitorEnter(lock)) {
                try {
                  world.updateEntity(entity);
                } finally {
                  $.monitorExit(lock);
                }
              }
            } else {
              world.updateEntity(entity);
            }
          }

          if (entity.isDead) {
            int entityX = entity.chunkCoordX;
            int entityZ = entity.chunkCoordZ;

            synchronized (entity) {
              if (entity.addedToChunk) {
                Chunk chunk = entity.chunk;
                if (chunk == null) {
                  chunkProvider.getChunkIfExists(entityX, entityZ);
                }
                if (chunk != null) {
                  chunk.removeEntity(entity);
                }
              }
            }

            entitiesIterator.remove();
            manager.removed(entity);
            world.onEntityRemoved(entity);
          } else if (TickManager.getHashCode(entity) != hashCode) {
            entitiesIterator.remove();
            manager.add(entity, false);
            //Log.severe("Inconsistent state: " + entity + " is in the wrong TickRegion.");
            // Note to self for when I decide this is wrong later:
            // Entities are supposed to move, of course this will happen!
          }
        } catch (Throwable throwable) {
          Log.severe("Exception ticking entity " + entity + " in " + toString() + '/' + Log.name(entity.worldObj) + ':', throwable);
          if (entity.worldObj != world) {
            Log.severe("Seems to be caused by an entity being in a broken state, set to an impossible/incorrect world. Killing this entity.");
            entity.setDead();
          }
        }
        if (profilingEnabled) {
          entityTickProfiler.record(entity, System.nanoTime() - startTime);
        }
      }
    } finally {
      entitySet.done();
    }
View Full Code Here

  @Override
  public void doTick() {
    final TickManager manager = this.manager;
    final boolean check = checkTime++ % 60 == 0;
    final boolean profilingEnabled = manager.profilingEnabled || this.profilingEnabled;
    EntityTickProfiler entityTickProfiler = profilingEnabled ? EntityTickProfiler.ENTITY_TICK_PROFILER : null;
    long startTime = profilingEnabled ? System.nanoTime() : 0;
    final Iterator<TileEntity> tileEntitiesIterator = tileEntitySet.startIteration();
    try {
      while (tileEntitiesIterator.hasNext()) {
        final TileEntity tileEntity = tileEntitiesIterator.next();
        if (check && check(tileEntity, tileEntitiesIterator)) {
          continue;
        }
        try {
          if (tileEntity.isInvalid()) {
            tileEntitiesIterator.remove();
            invalidate(tileEntity);
          } else if (tileEntity.worldObj != null) {
            tileEntity.updateEntity();
          }
        } catch (Throwable throwable) {
          Log.severe("Exception ticking TileEntity " + Log.toString(tileEntity), throwable);
        } finally {
          if (profilingEnabled) {
            long oldStartTime = startTime;
            entityTickProfiler.record(tileEntity, (startTime = System.nanoTime()) - oldStartTime);
          }
        }
      }
    } finally {
      tileEntitySet.done();
View Full Code Here

TOP

Related Classes of nallar.tickthreading.minecraft.profiling.EntityTickProfiler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.