Skip to content

Instantly share code, notes, and snippets.

@purelogiq
Last active October 2, 2018 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save purelogiq/0393f731eea8f3ad481ab6ac1f4b8499 to your computer and use it in GitHub Desktop.
Save purelogiq/0393f731eea8f3ad481ab6ac1f4b8499 to your computer and use it in GitHub Desktop.
Phab Creation Method Stats

Phab Creation Method Stats

The script is below, it takes a long time to finish (~20-30minutes). Here are the results for me.

Creation Method Stats for D1 to D7370
arc: 4003
cinnabarc: 1188
phlay: 293
web: 255
commit: 5113
phabsend: 1624
mozarc: 2

read as COUNT revisions had at least 1 diff created with METHOD

#!/usr/bin/python3
import sys
import requests
PHAB_API_KEY = 'api-1234567890'
START_REVISION = 1
END_REVISION = 5850 # probably should be a multiple of BATCH_SIZE
BATCH_SIZE = 10 # how many are queries per network request. keep this low, responses get big since they include the actual diff.
if PHAB_API_KEY == 'api-1234567890':
sys.exit("Error: Modify the script and set your phabricator api key first.")
stats = {
'arc': set(),
'cinnabarc': set(),
'phlay': set(),
'web': set(),
# more will be added dynamically
}
i = START_REVISION
failed_batches = 0
while i < END_REVISION:
print('processing batch D' + str(i) + ' to D' + str((i + BATCH_SIZE) if (i + BATCH_SIZE) < END_REVISION else END_REVISION) + '...', end='')
sys.stdout.flush()
try:
response = requests.request(
method='GET',
url='https://phabricator.services.mozilla.com/api/differential.querydiffs',
data={
'api.token': PHAB_API_KEY,
'revisionIDs[]': list(range(i, i + BATCH_SIZE))
},
timeout=25
).json()
for key, val in response['result'].items():
if val['creationMethod'] == 'web' and 'properties' in val and 'hg:meta' in val['properties']:
creation_method = 'phabsend'
else:
creation_method = val['creationMethod']
stats.setdefault(creation_method, set()).add(val['revisionID'])
print('success')
except Exception:
# The show must go on...
print('failed')
failed_batches += 1
sys.stdout.flush()
i += BATCH_SIZE
print('\n\nCreation Method Stats for D' + str(START_REVISION) + ' to D' + str(END_REVISION))
for key, val in stats.items():
print(key + ': ' + str(len(val)))
print('\nread as COUNT revisions had at least 1 diff created with METHOD')
if(failed_batches > 0):
print('\n(failed to count diffs for ' + str(failed_batches * BATCH_SIZE) + ' revisions)')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment