Skip to content

Commit

Permalink
[Python] Early version of the profiler github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
beroy committed Nov 10, 2023
1 parent 13e739e commit 154c0c2
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 4 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/profiler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: TileDB-SOMA Profiler run

on:
push:
branches:
pull_request:
branches:
- "main"

paths:
- ".github/workflows/profiler"
jobs:

check-links:

name: Setup profiler

run: |
python -m venv profiler_env
source profiler_env/bin/activate
pip install -e ./profiler
run: |
./perf_checker.sh
23 changes: 23 additions & 0 deletions profiler/ann_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from time import perf_counter

import cellxgene_census

import tiledbsoma as soma

census_S3_latest = dict(census_version="latest")
census_local_copy = dict(uri="/Users/brobatmili/projects/census_data/")


def main():
t1 = perf_counter()
with cellxgene_census.open_soma(**census_local_copy) as census:
with census["census_data"]["homo_sapiens"].axis_query(
measurement_name="RNA",
obs_query=soma.AxisQuery(value_filter="""tissue_general == 'eye'"""),
) as query:
query.to_anndata(X_name="raw")
t2 = perf_counter()
print(f"End to end time {t2 - t1}")


main()
13 changes: 13 additions & 0 deletions profiler/perf_checker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

python -m venv perf
source perf/bin/activate
pip install gitpython
pip install psutil
pip install comacore
pip install profiler
pip install tiledbsoma
pip install cellxgene_census
python -m profiler "python ann_data.py" -t gtime

python ./top_profiler.py
6 changes: 3 additions & 3 deletions profiler/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
from typing import Any, Dict, Optional

import somacore
from context_generator import host_context

import tiledbsoma

from context_generator import host_context
from data import FileBasedProfileDB, ProfileData, ProfileDB

GNU_TIME_FORMAT = (
Expand Down Expand Up @@ -207,5 +206,6 @@ def main():
file=stderr,
)


if __name__ == "__main__":
main()
main()
2 changes: 1 addition & 1 deletion profiler/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
name="soma-profiler",
version="1.0",
packages=find_packages(),
requires=["gitpython", "psutil"],
requires=["gitpython", "comacore", "psutil", "tiledbsoma", "cellxgene_census"],
)
25 changes: 25 additions & 0 deletions profiler/top_profiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import data

# Processes the set of previously written logs

threshold = 1.10 # Percent difference

db = data.FileBasedProfileDB()
actual_max_ts = 0
dt = db.find("python ann_data.py")
last_two = dt[-2:]
c = 0

for s in dt:
new_db = sorted(dt, key=lambda ProfileData: ProfileData.timestamp)

L = [1, 2]
L[0] = dt[0].user_time_sec
L[1] = dt[1].user_time_sec
for i in range(0, len(dt)):
print(f"{i} dt[{i}].user_time_sec = {dt[i].user_time_sec} ts {dt[i].timestamp}")
print(f"L0 = {L[0]} L1 {L[1]}")

if threshold * float(L[1]) < float(L[0]) or float(L[1]) > threshold * float(L[0]):
raise SystemExit(f"Potential performance degradation detected {L[0]} va {L[1]}")
print("No recent performance degradation detected")

0 comments on commit 154c0c2

Please sign in to comment.