Esempio n. 1
0
def test_probe_states(capsys):
    """
  Test xpedite probes and probes state for an application's against baseline probe states
  for the application
  """
    import cPickle as pickle
    from xpedite.types.probe import compareProbes
    profileInfo = loadProfileInfo(DATA_DIR,
                                  os.path.join(DATA_DIR, 'profileInfo.py'),
                                  REMOTE)
    probes = []
    probeMap = {}
    baselineProbeMap = {}
    with capsys.disabled():
        probes = loadProbes(FIX_DECODER_BINARY, profileInfo, TXN_COUNT,
                            THREAD_COUNT, REMOTE, WORKSPACE)
        for probe in probes:
            probeMap[probe.sysName] = probe

    with open(os.path.join(DATA_DIR, 'probeCmdBaseline.pkl'),
              'r') as probeFileHandle:
        baselineProbes = pickle.load(probeFileHandle)
        for probe in baselineProbes:
            baselineProbeMap[probe.sysName] = probe

    assert len(probes) == len(baselineProbes)
    findDiff(probeMap, baselineProbeMap)
    for probe in probeMap.keys():
        assert compareProbes(probeMap[probe], baselineProbeMap[probe])
Esempio n. 2
0
def test_generate_against_baseline():
    """
  Test xpedite generate by generating a new profileInfo.py file and comparing to baseline
  profileInfo.py in the test data directory
  """
    import tempfile
    profileInfoBaseline = os.path.join(dataDir, 'baselineProfileInfo.py')
    baselineProfileInfo = loadProfileInfo(profileInfoBaseline, remote)
    tempDir = tempfile.mkdtemp()
    os.chdir(tempDir)
    profileInfo = loadProfileInfo('profileInfo.py', remote)
    tempProfilePath = generateProfileInfo(DEMO_BINARY, profileInfo, remote)
    tempProfileInfo = loadProfileInfo(tempProfilePath, remote)
    tempProfileInfo.appHost = 'localhost'
    baselineProfileInfo.appHost = 'localhost'
    tempProfileInfo.cpuSet = [0]
    assert tempProfileInfo == baselineProfileInfo
Esempio n. 3
0
def test_record_against_report(capsys, profileInfoPath=None):
    """
  Run xpedite record and xpedite report to compare profiles

  @param capsys: A pytest fixture allowing disabling of I/O capturing
  @param profileInfoPath: Override default profileInfo.py file from the test data directory
  """
    from test_xpedite.test_profiler.comparator import findDiff
    profileInfoPath = profileInfoPath if profileInfoPath else 'profileInfo.py'
    profileInfo = loadProfileInfo(profileInfoPath, remote)
    with capsys.disabled():
        app, recordProfiles, _ = runXpediteRecord(DEMO_BINARY, profileInfo,
                                                  remote)
    profileInfo = loadProfileInfo(profileInfoPath, remote)
    profileInfo.appInfo = os.path.join(app.tempDir, 'xpedite-appinfo.txt')
    reportProfiles, _ = runXpediteReport(app.xpediteApp.runId, profileInfo)
    findDiff(reportProfiles.__dict__, recordProfiles.__dict__)
    assert recordProfiles == reportProfiles
Esempio n. 4
0
def test_generate_against_baseline():
    """
  Test xpedite generate by generating a new profileInfo.py file and comparing to baseline
  profileInfo.py in the test data directory
  """
    profileInfoBaseline = os.path.join(DATA_DIR, 'generateCmdBaseline.py')
    baselineProfileInfo = loadProfileInfo(DATA_DIR, profileInfoBaseline,
                                          REMOTE)
    tempDir = tempfile.mkdtemp()
    os.chdir(tempDir)
    profileInfo = loadProfileInfo(DATA_DIR, 'profileInfo.py', REMOTE)
    tempProfilePath = generateProfileInfo(FIX_DECODER_BINARY, profileInfo,
                                          TXN_COUNT, THREAD_COUNT, REMOTE,
                                          WORKSPACE)
    tempProfileInfo = loadProfileInfo(DATA_DIR, tempProfilePath, REMOTE)
    tempProfileInfo.appInfo = os.path.basename(tempProfileInfo.appInfo)
    (tempProfileInfo.appHost, baselineProfileInfo.appHost) = ('localhost',
                                                              'localhost')
    findDiff(tempProfileInfo.__dict__, baselineProfileInfo.__dict__)
    assert tempProfileInfo == baselineProfileInfo
Esempio n. 5
0
def test_report_against_baseline():
    """
  Run xpedite report on a data file in the test directory, return profiles and compare
  the previously generated profiles from the same xpedite run
  """
    from test_xpedite.test_profiler.comparator import findDiff
    profileInfo = loadProfileInfo('profileInfo.py')
    for runId, dataFilePath in collectDataFiles().iteritems():
        reportProfiles, _ = runXpediteReport(runId, profileInfo, dataFilePath)
        reportProfiles.transactionRepo = None  # transactionRepo not stored in .xpd files
        baselineProfiles = loadBaseline()
        findDiff(reportProfiles.__dict__, baselineProfiles.__dict__)
        assert reportProfiles == baselineProfiles
Esempio n. 6
0
def test_record_against_report(capsys, profileInfoPath=None):
    """
  Run xpedite record and xpedite report to compare profiles

  @param capsys: A pytest fixture allowing disabling of I/O capturing
  @param profileInfoPath: Override default profileInfo.py file from the test data directory
  """
    profileInfoPath = profileInfoPath if profileInfoPath else 'profileInfo.py'
    profileInfo = loadProfileInfo(DATA_DIR, profileInfoPath, REMOTE)
    with capsys.disabled():
        app, result = runXpediteRecord(FIX_DECODER_BINARY, profileInfo,
                                       TXN_COUNT, THREAD_COUNT, REMOTE,
                                       WORKSPACE)
    recordProfiles = result.profiles
    profileInfo = loadProfileInfo(DATA_DIR, profileInfoPath, REMOTE)
    profileInfo.appInfo = os.path.join(app.tempDir, 'xpedite-appinfo.txt')
    result = runXpediteReport(app.xpediteApp.runId,
                              profileInfo,
                              workspace=WORKSPACE)
    reportProfiles = result.profiles
    findDiff(reportProfiles.__dict__, recordProfiles.__dict__)
    assert reportProfiles == recordProfiles
Esempio n. 7
0
def test_intercept(capsys):
    """
  Run and test intercept functionality with a target doing memory allocations

  @param capsys: A pytest fixture allowing disabling of I/O capturing
  """
    from xpedite import Probe
    profileInfo = loadProfileInfo('allocatorProfileInfo.py', remote)
    with capsys.disabled():
        app, profiles, _ = runXpediteRecord(ALLOCATOR_BINARY, profileInfo,
                                            remote)
    assert len(profiles) == 1
    timelines = profiles[0].current.timelineCollection
    assert len(timelines) == 100
    for tl in timelines:
        assert tl.txn is not None
        for probe in profileInfo.probes:
            assert tl.txn.hasProbe(probe)
Esempio n. 8
0
def test_probe_states(capsys):
    """
  Test xpedite probes and probes state for an application's against baseline probe states
  for the application
  """
    import cPickle as pickle
    from xpedite.probe import compareProbes
    profileInfo = loadProfileInfo(os.path.join(dataDir, 'profileInfo.py'),
                                  remote)
    probes = []
    with capsys.disabled():
        probes = loadProbes(DEMO_BINARY, profileInfo, remote)

    with open(os.path.join(dataDir, 'probeBaseline.pkl'),
              'r') as probeFileHandle:
        baselineProbes = pickle.load(probeFileHandle)

    assert len(probes) == len(baselineProbes)
    for i in range(len(probes)):
        assert compareProbes(probes[i], baselineProbes[i])
Esempio n. 9
0
def test_intercept(capsys):
    """
  Run and test intercept functionality with a target doing memory allocations

  @param capsys: A pytest fixture allowing disabling of I/O capturing
  """
    from xpedite import Probe
    dataDir = os.path.join(os.path.dirname(__file__), '..', 'data')
    profileInfo = loadProfileInfo(dataDir, 'allocatorProfileInfo.py', REMOTE)
    with capsys.disabled():
        _, result = runXpediteRecord(ALLOCATOR_BINARY, profileInfo, TXN_COUNT,
                                     THREAD_COUNT, REMOTE)
    profiles = result.profiles
    assert len(profiles) == 1
    timelines = profiles[0].current.timelineCollection
    assert len(timelines) == int(TXN_COUNT)
    for tl in timelines:
        assert tl.txn is not None
        for probe in profileInfo.probes:
            assert tl.txn.hasProbe(probe)
Esempio n. 10
0
def generateBaseline(binary, tempDir, workspace, appName):
    """
  Generate the following files:
  1. .xpd data file generated from building a Jupyter notebook
     Used to test building of notebooks
  2. Xpedite application information file
     Used to attach profiler for testing recording, reporting, probe status, and notebooks
  3. xpediteDemo .data files
     Files that are collected by an xpedite app to build transactions
  4. Serialized probe baseline file
     Used to compare probe states generated by an xpedite app to baseline probes
  """
    import json
    import tempfile
    import cPickle as pickle
    from xpedite.benchmark import makeBenchmark
    txnCount = 1000
    threadCount = 1
    tempDir = os.path.join(tempDir, appName)

    cleanUpDataDir(tempDir, appName)

    _, dataFilePath, app, result = buildNotebook(tempDir,
                                                 binary,
                                                 txnCount,
                                                 threadCount,
                                                 workspace=workspace)
    replaceWorkspace(app.xpediteApp.appInfoPath, workspace,
                     os.path.join(tempDir, 'xpedite-appinfo.txt'))
    copy(dataFilePath, os.path.join(tempDir, 'reportCmdBaseline.xpd'))

    fullCpuInfo = app.xpediteApp.env.proxy.fullCpuInfo
    baselineCpuInfoPath = os.path.join(tempDir, 'baselineCpuInfo.json')
    with open(baselineCpuInfoPath, 'w') as fileHandle:
        json.dump(fullCpuInfo, fileHandle)

    for dataFile in app.xpediteApp.gatherFiles(
            app.xpediteApp.sampleFilePattern()):
        copy(dataFile, os.path.join(tempDir, os.path.basename(dataFile)))

    makeBenchmark(result.profiles, os.path.join(tempDir, 'benchmark'))

    benchmarkAppInfo = os.path.join(tempDir, 'benchmark/benchmark/appinfo.txt')
    replaceWorkspace(benchmarkAppInfo, workspace, benchmarkAppInfo)

    benchmarkProfilePath = os.path.join(tempDir, 'profileInfoWithBenchmark.py')
    _, benchmarkDataFilePath, _, _ = buildNotebook(
        tempDir,
        binary,
        txnCount,
        threadCount,
        profileInfoPath=benchmarkProfilePath,
        runId=app.xpediteApp.runId,
        workspace=workspace)
    copy(benchmarkDataFilePath,
         os.path.join(tempDir, 'reportCmdBaselineWithBenchmark.xpd'))

    profileInfo = loadProfileInfo(tempDir,
                                  os.path.join(tempDir, 'profileInfo.py'))
    probes = loadProbes(binary,
                        profileInfo,
                        txnCount,
                        threadCount,
                        workspace=workspace)
    with open(os.path.join(tempDir, 'probeCmdBaseline.pkl'),
              'wb') as probeFileHandle:
        probeFileHandle.write(pickle.dumps(probes))