001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.functions.system; 020 021import lucee.commons.io.SystemUtil; 022import lucee.commons.lang.StringUtil; 023import lucee.runtime.PageContext; 024import lucee.runtime.exp.FunctionException; 025import lucee.runtime.exp.PageException; 026import lucee.runtime.ext.function.Function; 027import lucee.runtime.type.Query; 028 029public final class GetMemoryUsage implements Function { 030 031 private static final long serialVersionUID = -7937791531186794443L; 032 033 public static Query call(PageContext pc) throws PageException { 034 return call(pc, null); 035 } 036 public static Query call(PageContext pc,String type) throws PageException { 037 if(StringUtil.isEmpty(type)) 038 return SystemUtil.getMemoryUsageAsQuery(SystemUtil.MEMORY_TYPE_ALL); 039 040 type=type.trim().toLowerCase(); 041 if("heap".equalsIgnoreCase(type)) 042 return SystemUtil.getMemoryUsageAsQuery(SystemUtil.MEMORY_TYPE_HEAP); 043 if("non_heap".equalsIgnoreCase(type) || "nonheap".equalsIgnoreCase(type) || "non-heap".equalsIgnoreCase(type) || 044 "none_heap".equalsIgnoreCase(type) || "noneheap".equalsIgnoreCase(type) || "none-heap".equalsIgnoreCase(type)) 045 return SystemUtil.getMemoryUsageAsQuery(SystemUtil.MEMORY_TYPE_NON_HEAP); 046 047 throw new FunctionException(pc, "GetMemoryUsage", 1, "type", "invalid value ["+type+"], valid values are [heap,non_heap]"); 048 } 049}