示例#1
0
    def testPatternParsing(self):
        profiler = SP.SilkProfiler()

        # Parse invalid log files should return False
        self.failIf(True == profiler.Open("sample/testpattern_empty.pattern",
                                          "sample/log.log"))
        self.failIf(True == profiler.Open(
            "sample/testpattern_nopattern.pattern", "sample/log.log"))

        # Parse valid log files
        self.failIf(False == profiler.Open(
            "sample/testpattern_patternonly.pattern", "sample/log.log"))
        self.failIf(False == profiler.Open("sample/testpattern_pass.pattern",
                                           "sample/log.log"))

        # Repeat parsing patterns. Make sure context is independent between two parsing
        # Parse testpattern_pass, which has xy label and pattern string, and then parse
        # testpattern_patternonly, which has pattern string only. xy label should be
        # cleared.
        profiler = SP.SilkProfiler()
        self.failIf(False == profiler.Open("sample/testpattern_pass.pattern",
                                           "sample/log.log"))
        self.failIf(False == profiler.Open(
            "sample/testpattern_patternonly.pattern", "sample/log.log"))
        self.failIf("" != profiler.mParser.mXLabel)
        self.failIf("" != profiler.mParser.mYLabel)
示例#2
0
    def testLogParsing(self):
        # Get statistic data of a profiler which has not parsed any log file yet
        profiler = SP.SilkProfiler()
        statistics = profiler.Statistic(False)
        self.failIf(0 != statistics["total"])
        self.failIf(True != np.isnan(statistics["mean"]))
        self.failIf(True != np.isnan(statistics["stdev"]))
        self.failIf(True != np.isnan(statistics["max"]))
        self.failIf(True != np.isnan(statistics["min"]))
        self.failIf(True != np.isnan(statistics["cv"]))

        # Parse a log file which has only one valid line log
        profiler = SP.SilkProfiler()
        self.failIf(False == profiler.Open("sample/testpattern_pass.pattern",
                                           "sample/testlog_one.log"))
        statistics = profiler.Statistic(False)
        self.failIf(1 != statistics["total"])

        # Parse a log file which has 10 valid line log
        profiler = SP.SilkProfiler()
        self.failIf(False == profiler.Open("sample/testpattern_pass.pattern",
                                           "sample/testlog.log"))
        statistics = profiler.Statistic(False)
        self.failIf(10 != statistics["total"])
        self.failIf(5.5 != statistics["mean"])
        self.failIf(10 != statistics["max"])
        self.failIf(1 != statistics["min"])

        # Parse a log file which has no valid log
        profiler = SP.SilkProfiler()
        self.failIf(False == profiler.Open("sample/testpattern_pass.pattern",
                                           "sample/testlog_zero.log"))
        statistics = profiler.Statistic(False)
        self.failIf(0 != statistics["total"])
        self.failIf(True != np.isnan(statistics["mean"]))
        self.failIf(True != np.isnan(statistics["stdev"]))
        self.failIf(True != np.isnan(statistics["max"]))
        self.failIf(True != np.isnan(statistics["min"]))
        self.failIf(True != np.isnan(statistics["cv"]))

        # Repeat parsing logs. Make sure context is independent between two parsing
        # Keep loading testlog_one two times, total samples should not be accumulated.
        profiler = SP.SilkProfiler()
        self.failIf(False == profiler.Open("sample/testpattern_pass.pattern",
                                           "sample/testlog_one.log"))
        self.failIf(False == profiler.Open("sample/testpattern_pass.pattern",
                                           "sample/testlog_one.log"))
        statistics = profiler.Statistic(False)
        self.failIf(1 != statistics["total"])
示例#3
0
 def testDrawing(self):
     # Open a log file which has no valid log again.
     # Expect return False while calling SilkProfiler.Draw()
     profiler = SP.SilkProfiler()
     # Return False before Open a valide config and log file.
     self.failIf(True == profiler.Draw())
     self.failIf(False == profiler.Open("sample/testpattern_pass.pattern",
                                        "sample/testlog_zero.log"))
     self.failIf(True == profiler.Draw())
示例#4
0
    def testSave(self):
        profiler = SP.SilkProfiler()
        # Return False before Open a valide config and log file.
        self.failIf(True == profiler.SaveHistogram(SP.Histogram.All, None))

        self.failIf(False == profiler.Open("sample/testpattern_pass.pattern",
                                           "sample/testlog_one.log"))

        dirname = "./savethistogramfolder"
        filename = "test.png"

        # Save to direct filename
        path = filename
        if True == os.path.exists(filename):
            os.remove(filename)

        self.failIf(False == profiler.SaveHistogram(SP.Histogram.Line, path))
        self.failIf(False == os.path.exists(path))

        if True == os.path.exists(filename):
            os.remove(filename)

        # Save to a relative path
        path = os.path.join(dirname, filename)
        if True == os.path.exists(dirname):
            shutil.rmtree(dirname)

        self.failIf(False == profiler.SaveHistogram(SP.Histogram.Line, path))
        self.failIf(False == os.path.exists(path))

        if True == os.path.exists(dirname):
            shutil.rmtree(dirname)

        # Save to an absolute path
        path = os.path.join(dirname, filename)
        path = os.path.abspath(path)
        if True == os.path.exists(dirname):
            shutil.rmtree(dirname)

        self.failIf(False == profiler.SaveHistogram(SP.Histogram.Line, path))
        self.failIf(False == os.path.exists(path))

        if True == os.path.exists(dirname):
            shutil.rmtree(dirname)
示例#5
0
  def _GenerateReport(self, patternFile, files, outputDir, figSize):
    # Validate patternFile.
    if False == os.path.exists(patternFile) or False == os.path.isfile(patternFile):
      return False

    # For convenience, alwasy destroy output folder, if exists, in the beginning,
    # so that we have a clean output folder
    if True == os.path.exists(outputDir):
      shutil.rmtree(outputDir)

    os.mkdir(outputDir)

    # Use SilkProfiler to generate figure for each source file and put them into
    # outputDir
    for log in files:
      if not os.path.exists(log):
        continue

      profiler = sp.SilkProfiler()
      if not profiler.Open(patternFile, log):
        return False

      # Generate output fullpath
      # XXX: export fileformat config to user?
      (head, tail) = os.path.split(log)
      (root, ext) = os.path.splitext(os.path.join(outputDir, tail))
      root = root + ".png"

      # Generate Line chart for this log
      if False == profiler.SaveHistogram(sp.Histogram.Line, root, figSize):
        return False

      # Generate statistic for this log
      statistic = os.path.join(outputDir, "statistic.txt")
      with open(statistic, 'a+') as statisticFile:
        (head, tail) = os.path.split(root)
        statisticFile.write("[" + tail + "]" + "\n")
        data = profiler.Statistic(False)
        for key in data:
          statisticFile.write(key + " = "+ str(data[key]) + "\n")

    return True
示例#6
0
 def testCreation(self):
     profiler = SP.SilkProfiler()
     self.assertNotEqual(profiler, None, "Creation test failed")