source: trunk/src/testing/ui/sageAppPerfInfo.py @ 4

Revision 4, 6.0 KB checked in by ajaworski, 13 years ago (diff)

Added modified SAGE sources

Line 
1############################################################################
2#
3# SAGE UI - A Graphical User Interface for SAGE
4# Copyright (C) 2005 Electronic Visualization Laboratory,
5# University of Illinois at Chicago
6#
7# All rights reserved.
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions are met:
11#
12#  * Redistributions of source code must retain the above copyright
13#    notice, this list of conditions and the following disclaimer.
14#  * Redistributions in binary form must reproduce the above
15#    copyright notice, this list of conditions and the following disclaimer
16#    in the documentation and/or other materials provided with the distribution.
17#  * Neither the name of the University of Illinois at Chicago nor
18#    the names of its contributors may be used to endorse or promote
19#    products derived from this software without specific prior written permission.
20#
21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32#
33# Direct questions, comments etc about SAGE UI to www.evl.uic.edu/cavern/forum
34#
35# Author: Ratko Jagodic
36#       
37############################################################################
38
39import sys, string
40
41### Class to hold all the performace information
42### Instance of this class has to be created for every app instance ID on SAGE
43class sageAppPerfInfo:
44
45    def __init__(self) :
46        self.displayArray = {}
47        self.renderArray = {}
48        self.dataArray = {}
49       
50        self.displayArray['bandWidth'] = self.__zerosHash(30)
51        self.displayArray['frameRate'] = self.__zerosHash(30)
52        self.displayArray['nodes'] = self.__zerosHash(30)
53        self.displayArray['cpu'] = self.__zerosHash(30)
54        self.displayArrayIndex = 0
55
56        self.renderArray['bandWidth'] = self.__zerosHash(30)
57        self.renderArray['frameRate'] = self.__zerosHash(30)
58        self.renderArray['nodes'] = self.__zerosHash(30)
59        self.renderArray['cpu'] = self.__zerosHash(30)
60        self.renderArrayIndex = 0
61
62        self.dataArray['bandWidth'] = self.__zerosHash(30)
63        self.dataArray['nodes'] = self.__zerosHash(30)
64        self.dataArray['cpu'] = self.__zerosHash(30)
65        self.dataArrayIndex = 0
66
67    #### Set the display performance Info
68    #### @arg bandwidth Bandwidth
69    #### @arg frameRate Frame rate
70    #### @arg nodes Number of nodes
71    #### @arg cpuUsage CPU utilisation
72    def setDisplayPerfInfo(self, bandWidth, frameRate, nodes, cpuUsage):
73        if (self.displayArrayIndex >= 30):
74            self.displayArrayIndex = 0
75
76        self.displayArray['bandWidth'][self.displayArrayIndex % 30] = bandWidth
77        self.displayArray['frameRate'][self.displayArrayIndex % 30] = frameRate
78        self.displayArray['nodes'][self.displayArrayIndex % 30] = nodes
79        self.displayArray['cpu'][self.displayArrayIndex % 30] = cpuUsage
80
81        self.displayArrayIndex = self.displayArrayIndex + 1
82
83
84
85    #### Set the rendering performance Info
86    #### @arg bandwidth Bandwidth
87    #### @arg frameRate Frame rate
88    #### @arg nodes Number of nodes
89    #### @arg cpuUsage CPU utilisation
90    def setRenderPerfInfo(self, bandWidth, frameRate, nodes, cpuUsage):
91        if (self.renderArrayIndex >= 30):
92            self.renderArrayIndex = 0
93
94        self.renderArray['bandWidth'][self.renderArrayIndex] = bandWidth
95        self.renderArray['frameRate'][self.renderArrayIndex] = frameRate
96        self.renderArray['nodes'][self.renderArrayIndex] = nodes
97        self.renderArray['cpu'][self.renderArrayIndex] = cpuUsage
98
99        self.renderArrayIndex = self.renderArrayIndex + 1
100
101
102
103    #### Get display information based on the specified item
104    #### @arg interval No of values required (max = 30)
105    #### @return Returns an array
106    def getDisplayInformation(self, stItemName, interval):
107
108        if (interval > 30 or interval < 0):
109            print ('Out of bound range specified')
110            return 0
111        newArray = self.__zerosHash(interval)    #zeros(type='Float32', shape=interval)
112        newArrayIndex = self.displayArrayIndex - 1
113
114        for x in range(0, interval):
115            if newArrayIndex < 0:
116                newArrayIndex = 29
117
118            newArray[x] = self.displayArray[ stItemName ][newArrayIndex]
119            newArrayIndex = newArrayIndex - 1
120
121        return newArray
122
123
124
125    #### Get rendering information based on the specified item
126    #### @arg interval No of values required (max = 30)
127    #### @return Returns an array
128    def getRenderInformation(self, stItemName, interval):
129
130        if (interval > 30 or interval < 0):
131            print ('Out of bound range specified')
132            return 0
133        newArray = self.__zerosHash(interval)   #zeros(type='Float32', shape=interval)
134        newArrayIndex = self.renderArrayIndex - 1
135
136        for x in range(0, interval):
137
138            if newArrayIndex < 0:
139                newArrayIndex = 29
140
141            newArray[x] = self.renderArray[ stItemName ][newArrayIndex]
142            newArrayIndex = newArrayIndex - 1
143 
144        return newArray
145
146
147    # creates a hash of size "size" and initializes all the values to 0
148    def __zerosHash(self, size):
149        h = {}
150        for i in range(0, size):
151            h[i] = 0
152        return h
Note: See TracBrowser for help on using the repository browser.