How to find TPS of a server

Discussion in 'Plugin Development' started by Techtony96, Aug 19, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Techtony96

    I know there are plugins out there that give you the TPS of a server, but i'm making my own custom plugin.

    Could someone crate a quick class file for me that will determine the TPS of the server? Thanks
     
  2. It's the same logic as you'd find something per time, you'll need to gather how many "somethings" you got in a "time" period and when the time period has passed you add it to the previous result and make an average...

    I belive you can just schedule a Sync task each tick to monitor ticks.
    Then check if it's the same second then increment a variable... otherwise just set tps to ((tps + currentticks) / 2).

    EDIT:
    Here, I've wrote this, I'm not sure how good it is but it's a start :p
    Code:
    private int	tps = 0;
    private long second = 0;
    
    // in onEnable()
    		getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
    		{
    			long sec;
    			int ticks;
    			
    			@Override
    			public void run()
    			{
    				sec = (System.currentTimeMillis() / 1000);
    				
    				if(second == sec)
    				{
    					ticks++;
    				}
    				else
    				{
    					second = sec;
    					tps = (tps == 0 ? ticks : ((tps + ticks) / 2));
    					ticks = 0;
    					
    					System.out.print("TPS = " + tps);
    				}
    			}
    		}, 20, 1);
     
  3. Offline

    Techtony96

    how would i use this in another class?
     
  4. Bukkit. instead of getServer() ?
    I'm unsure what exacly you need.
     
  5. Offline

    Techtony96

    This is what im hoping to do: When someone types "LAG" in the chat, the plugin checks the TPS of the server, and if it is below 15, run some commands Using:

    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "kill all");
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "remove drops");
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "remove xp");


    I just dont want it to calculate the TPS of the server every second, as that is unneeded.
     
  6. You can start the task and let it run for a few secods then inform of the TPS.... but if you want instant response you'd have to keep it runing.
    It will not produce any lag tough, it should be very fast.
     
Thread Status:
Not open for further replies.

Share This Page