metrics.py

Go to the documentation of this file.
00001 """\
00002 @file metrics.py
00003 @author Phoenix
00004 @date 2007-11-27
00005 @brief simple interface for logging metrics
00006 
00007 $LicenseInfo:firstyear=2007&license=mit$
00008 
00009 Copyright (c) 2007-2008, Linden Research, Inc.
00010 
00011 Permission is hereby granted, free of charge, to any person obtaining a copy
00012 of this software and associated documentation files (the "Software"), to deal
00013 in the Software without restriction, including without limitation the rights
00014 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00015 copies of the Software, and to permit persons to whom the Software is
00016 furnished to do so, subject to the following conditions:
00017 
00018 The above copyright notice and this permission notice shall be included in
00019 all copies or substantial portions of the Software.
00020 
00021 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00022 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00023 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00024 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00025 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00026 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00027 THE SOFTWARE.
00028 $/LicenseInfo$
00029 """
00030 
00031 import sys
00032 from indra.base import llsd
00033 
00034 _sequence_id = 0
00035 
00036 def record_metrics(table, stats, dest=None):
00037     "Write a standard metrics log"
00038     _log("LLMETRICS", table, stats, dest)
00039 
00040 def record_event(table, data, dest=None):
00041     "Write a standard logmessage log"
00042     _log("LLLOGMESSAGE", table, data, dest)
00043 
00044 def _log(header, table, data, dest):
00045     if dest is None:
00046         # do this check here in case sys.stdout changes at some
00047         # point. as a default parameter, it will never be
00048         # re-evaluated.
00049         dest = sys.stdout
00050     global _sequence_id
00051     print >>dest, header, "(" + str(_sequence_id) + ")",
00052     print >>dest, table, llsd.format_notation(data)
00053     _sequence_id += 1

Generated on Fri May 16 08:31:53 2008 for SecondLife by  doxygen 1.5.5