com.google.appengine.tools.appstats.MiniProfilerAppstats Maven / Gradle / Ivy
Show all versions of gae-mini-profiler Show documentation
/**
* Copyright (C) 2011 by Jim Riecken
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.google.appengine.tools.appstats;
import java.util.*;
import com.google.appengine.api.memcache.MemcacheServiceFactory;
import com.google.appengine.tools.appstats.StatsProtos.*;
/**
* Utility for programmatically getting Appstats data.
*
* It is in this {@code com.google} package so we get access to the
* package-private {@code MemcacheWriter} which is used to load the Appstats
* data from memcache.
*/
public class MiniProfilerAppstats
{
/**
* Get the Appstats data for the specified id.
*
* @param appstatsId
* The id of the Appstats request.
* @param maxStackFrames
* The maximum number of stack frames to include in each RPC stack
* trace.
* @return The appstats data.
*/
public static Map getAppstatsDataFor(String appstatsId, Integer maxStackFrames)
{
Map appstatsMap = null;
MemcacheWriter writer = new MemcacheWriter(null, MemcacheServiceFactory.getMemcacheService("__appstats__"));
StatsProtos.RequestStatProto appstats = writer.getFull(Long.parseLong(appstatsId));
if (appstats != null)
{
appstatsMap = new HashMap();
appstatsMap.put("totalTime", appstats.getDurationMilliseconds());
Map> rpcInfoMap = new LinkedHashMap>();
for (AggregateRpcStatsProto rpcStat : appstats.getRpcStatsList())
{
Map rpcInfo = rpcInfoMap.get(rpcStat.getServiceCallName());
if (rpcInfo == null)
{
rpcInfo = new LinkedHashMap();
rpcInfoMap.put(rpcStat.getServiceCallName(), rpcInfo);
}
rpcInfo.put("totalCalls", rpcStat.getTotalAmountOfCalls());
rpcInfo.put("totalTime", Long.valueOf(0));
}
List