Example #1
0
    def index(self):
        """Home page with the latest test results"""

        # Migration (harstorage v1.0)
        migration_handler = MongoDB(collection = "migration")
        if hasattr(c, "message"): return render("/error.html")

        status = migration_handler.collection.find_one({"status": "ok"})
        if status is None: redirect("/migration/status")

        # MongoDB handler
        mdb_handler = MongoDB()
        if hasattr(c, "message"): return render("/error.html")

        # Read aggregated data from database
        # Aggregation is based on unique labels, urls and latest timestamps
        latest_results = mdb_handler.collection.group(
            key = ["label", "url"],
            condition = None,
            initial = {"timestamp": "1970-01-01 01:00:00"},
            reduce = "\
                function(doc, prev) {                     \
                    if (doc.timestamp > prev.timestamp) { \
                        prev.timestamp = doc.timestamp;   \
                    }                                     \
                }")

        key = lambda timestamp: timestamp["timestamp"]
        latest_results = sorted(latest_results, key = key, reverse = True)

        # Numner of records
        c.rowcount = len(latest_results)

        # Populate data table with the latest test results
        c.metrics_table = [[], [], [], [], [], []]

        fields = ["timestamp", "label", "url", "total_size", "requests",
                    "full_load_time"]

        for group in latest_results:
            condition = {"label": group["label"], "timestamp": group["timestamp"]}

            result = mdb_handler.collection.find_one(condition, fields = fields)

            c.metrics_table[0].append(result["timestamp"])
            c.metrics_table[1].append(result["label"])
            c.metrics_table[2].append(result["url"])
            c.metrics_table[3].append(result["total_size"])
            c.metrics_table[4].append(result["requests"])
            c.metrics_table[5].append(round(result["full_load_time"]/1000.0, 1))

        return render("/home/core.html")
    def create(self):
        """Render form with list of labels and timestamps"""

        # MongoDB handler
        md_handler = MongoDB()
        if hasattr(c, "message"): return render("/error.html")
        
        # List of labels
        c.labels = list()
        
        for label in md_handler.collection.distinct("label"):
            c.labels.append(label)
        
        return render("/create/core.html")
Example #3
0
    def document(self):
        """Render the error document"""

        resp = request.environ.get("pylons.original_response")
        c.message = literal(resp.status)

        return render("/error.html")
Example #4
0
    def details(self):
        """Page with test results"""

        # Try to fetch data for selecetor box
        try:
            c.label = request.GET["url"]
            c.mode = "url"
        # Use label parameter instead of URL parameter
        except:
            c.label = request.GET["label"]
            c.mode = "label"

        # Generate context for selector
        self._set_options_in_selector(c.mode, c.label)

        # Define url for data aggregation
        if c.mode == "label":
            c.query = "/superposed/display?" + \
                      "step_1_label=" + c.label + \
                      "&step_1_start_ts=" + min(c.timestamp) + \
                      "&step_1_end_ts=" + max(c.timestamp)
            c.histo = "true"
        else:
            c.histo = "false"
            c.query = "None"
 
        return render("/details/core.html")
Example #5
0
        def wrapper(*args):
            result, ext = function(*args)

            if result == True:
                try:
                    if request.headers["automated"] == "true":
                        return "Successful"
                except KeyError:
                    redirect("/results/details?label=" + ext)
            else:
                try:
                    if request.headers["automated"] == "true":
                        return ext
                except KeyError:
                    c.error = ext
                    return render("/upload.html")
Example #6
0
    def migration(self):
        # MongoDB handler
        mdb_handler = MongoDB()
        if hasattr(c, "message"): return render("/error.html")

        for document in mdb_handler.collection.find(fields=["_id", "har"]):
            id = document["_id"]

            har = HAR(document["har"], True)

            har.analyze()

            domains_req_ratio = dict()
            domains_weight_ratio = dict()

            for key, value in har.domains.items():
                domains_req_ratio[key] = value[0]
                domains_weight_ratio[key] = value[1]

            data = {"full_load_time":       har.full_load_time,
                    "onload_event":         har.onload_event,
                    "start_render_time":    har.start_render_time,
                    "time_to_first_byte":   har.time_to_first_byte,
                    "total_dns_time":       har.total_dns_time,
                    "total_transfer_time":  har.total_transfer_time,
                    "total_server_time":    har.total_server_time,
                    "avg_connecting_time":  har.avg_connecting_time,
                    "avg_blocking_time":    har.avg_blocking_time,
                    "total_size":           har.total_size,
                    "text_size":            har.text_size,
                    "media_size":           har.media_size,
                    "cache_size":           har.cache_size,
                    "requests":             har.requests,
                    "redirects":            har.redirects,
                    "bad_requests":         har.bad_requests,
                    "domains":              len(har.domains),
                    "weights_ratio":        har.weight_ratio(),
                    "requests_ratio":       har.req_ratio(),
                    "domains_ratio":        har.domains}

            mdb_handler.collection.update({"_id": id}, {"$set": data})

        migration_handler = MongoDB(collection = "migration")
        migration_handler.collection.insert({"status": "ok"})

        redirect("/")
Example #7
0
 def loadWraithForm(self):
     return render('/home/casperForms/wraithForm.html')
Example #8
0
    def harviewer(self):
        """HAR Viewer iframe"""

        # HAR Viewer customization via cookie
        response.set_cookie("phaseInterval", "-1", max_age=365*24*3600 )
        return render("/harviewer.html")
Example #9
0
    def exeScript(self):
        
        
        reqParams = json.loads(request.body)
        
        #setup which script to run
        if reqParams['script']== None or reqParams['timesToExe'] == None :
            return render("/error.html")
        
        #har script
        if reqParams['script']=='1':
            self.scriptName ="performanceHarRepo.js "
            
            if reqParams['urls'] != None:
                if portManager.indexCount != None:
                    fIndex = int(portManager.serverPort) + portManager.indexCount + 1
                    self.jsonFile = "TestLinks"+str(fIndex)+".json"
                else:
                    fIndex = int(self.defaultProxyPort)
                    fIndex += 1
                    if fIndex < 1000:
                        fIndex = 8081
                    self.jsonFile = "TestLinks"+str(fIndex)+".json" 
                self._writeUrlsToFile(reqParams)
            else:
                self.scriptOutput = "<div> Please Enter in Urls to Test </div></br>"
                return self.scriptOutput
        
        if reqParams['waitTime'] != None:
            self.waitTime = reqParams['waitTime']
            
        if reqParams['timesToExe'] != None:
            self.timesToExe = reqParams['timesToExe']
            
        if reqParams['testLabel'] != None:
            self.testLabel = reqParams['testLabel'] 
            
        if reqParams['throttleSpeed'] != None:
            self.throttleSpeed = reqParams['throttleSpeed']
            
        count = int(self.timesToExe)
        self.startProxy()
        
        if self.throttleSpeed != None:
            self.setNetworkSpeed(self.throttleSpeed)
        
        while count > 0:
        
            
            print "\n \t count is :"+ str(count)

            # We have all our values setup the cmdline cmd
            args = self.casperPath +"casperjs --proxy='http://localhost:"+str(self.myPort) +"' --ssl-protocol='any' --ignore-ssl-errors=true --disc-cache=false " + self.scriptDirectory + self.scriptName + self.scriptDirectory + "/output/"+ self.jsonFile + " " + self.waitTime + " " + self.testLabel + " " + self.myPort
            myProc = subprocess.Popen(args,shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.STDOUT);
            
            try:
                stdout_value, stderr_value = myProc.communicate()
                self.scriptOutput = repr(stdout_value)
                self.scriptErrors = stderr_value
            except:
                print "\n\t Error : could not get script Output. Trying again"
                myProc = subprocess.Popen(args,shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.STDOUT);
                try:
                    stdout_value, stderr_value = myProc.communicate()
                    self.scriptOutput = repr(stdout_value)
                    self.scriptErrors = stderr_value
                    return self.getScriptOutput(self.scriptOutputFile)
                except:
                    print "\n\t Error: second attempt failed, program will quit."
                    self.stopProxy()
            
            if count== int(self.timesToExe):    
                self._writeOutput(self.scriptOutput)
            else:
                self._appendOutput(self.scriptOutput)
    
            count -= 1
            
        
        self.stopProxy()
        
        print '\n\t Script output:', repr(self.scriptOutput) , '</br>'
        print '\n\t stderr value   :', repr(self.scriptErrors), '</br>'
        return self.getScriptOutput(self.scriptOutputFile)
Example #10
0
 def manaul(self):
     return render('/home/manual.html')
Example #11
0
 def about(self):
     return render('/home/about.html')
Example #12
0
 def harJsonFiles(self):
     return render('/home/casperForms/crtHarPerfForm.html')
Example #13
0
    def display(self):
        """Render page with column chart and data table"""

        # MongoDB handler
        md_handler = MongoDB()
        if hasattr(c, "message"): return render("/error.html")

        # Checkbox options
        c.chart_type = request.GET.get("chart", None)
        c.table = request.GET.get("table", "false")
        init = request.GET.get("metric", "true")

        c.chart = "true" if c.chart_type else "false"

        # Aggregation option
        c.agg_type = request.GET.get("metric", "Average")

        # Number of records
        if c.chart == "true" and c.table == "true" and init != "true":
            c.rowcount = len(request.GET) / 3 - 1
        else:
            c.rowcount = len(request.GET) / 3

        # Data table
        c.headers = [   "Label", "Full Load Time (ms)", "Total Requests",
                        "Total Size (kB)", "Page Speed Score",
                        "onLoad Event (ms)", "Start Render Time (ms)",
                        "Time to First Byte (ms)", "Total DNS Time (ms)",
                        "Total Transfer Time (ms)", "Total Server Time (ms)",
                        "Avg. Connecting Time (ms)", "Avg. Blocking Time (ms)",
                        "Text Size (kB)", "Media Size (kB)", "Cache Size (kB)",
                        "Redirects", "Bad Rquests", "Domains"]
        c.metrics_table = list()
        c.metrics_table.append(list())

        # Chart points
        c.points = str()

        # Aggregator
        aggregator = Aggregator()        

        # Test results from database
        for row_index in range(c.rowcount):
            # Parameters from GET request
            label    = request.GET["step_" + str(row_index + 1) + "_label"]
            start_ts = request.GET["step_" + str(row_index + 1) + "_start_ts"]
            end_ts   = request.GET["step_" + str(row_index + 1) + "_end_ts"]

            # Add label
            c.metrics_table[0].append(label)
            c.points += label + "#"

            # Fetch test results
            condition = {"label": label, "timestamp": {"$gte": start_ts, "$lte": end_ts}}
            documents = md_handler.collection.find(condition, fields = aggregator.METRICS)

            # Add data row to aggregator
            aggregator.add_row(label, row_index, documents)            

        # Aggregated data per column
        column = 1
        for metric in aggregator.METRICS:
            c.metrics_table.append(list())
            c.points = c.points[:-1] + ";"

            for row_index in range(c.rowcount):
                data_list = aggregator.data[metric][row_index]
                value = aggregator.get_aggregated_value(data_list, c.agg_type, metric)

                c.points += str(value) + "#"
                c.metrics_table[column].append(value)

            column += 1

        # Names of series
        titles = str()
        for title in aggregator.TITLES:
            titles += title + "#"

        # Final chart points
        c.points = titles[:-1] + ";" + c.points[:-1]
        c.points = aggregator.exclude_missing(c.points)

        return render("/display/core.html")
Example #14
0
    def histogram(self):
        """Render chart with histograms"""
        
        # MongoDB handler
        md_handler = MongoDB()
        if hasattr(c, "message"): return render("/error.html")

        # Options
        c.label = request.GET["label"]
        c.metric = request.GET["metric"]

        # Metrics
        METRICS = [ ("full_load_time", "Full Load Time"),
                    ("onload_event", "onLoad Event"),
                    ("start_render_time", "Start Render Time"),
                    ("time_to_first_byte", "Time to First Byte"),
                    ("total_dns_time", "Total DNS Time"),
                    ("total_transfer_time", "Total Transfer Time"),
                    ("total_server_time", "Total Server Time"),
                    ("avg_connecting_time", "Avg. Connecting Time"),
                    ("avg_blocking_time", "Avg. Blocking Time")]

        time_metrics = ["full_load_time", "onload_event", "start_render_time",
                        "time_to_first_byte"]

        c.metrics = list()

        # Read data from database
        condition = {"label": c.label}
        fields = (metric for metric, title in METRICS)
        documents = md_handler.collection.find(condition, fields = fields)

        full_data = list(document for document in documents)

        for metric, title in METRICS:
            try:
                data = (result[metric] for result in full_data)
                histogram = Histogram(data)

                if metric in time_metrics:
                    ranges = histogram.ranges(True)
                else:
                    ranges = histogram.ranges()

                frequencies = histogram.frequencies()

                if metric == c.metric:
                    c.data = ""

                    for occ_range in ranges:
                        c.data += occ_range + "#"

                    c.data = c.data[:-1] + ";"

                    for frequency in frequencies:
                        c.data += str(frequency) + "#"

                    c.data = c.data[:-1] + ";"

                    c.title = title

                c.metrics.append((metric, title))
            except IndexError:
                pass
            except TypeError:
                pass
            except ValueError:
                pass

        if len(c.metrics):
            return render("/histogram/core.html")
        else:
            c.message = "Sorry! You haven't enough data."
            return render("/error.html")
Example #15
0
 def status(self):
     return render("/migration.html")