Skip to content

Instantly share code, notes, and snippets.

@caspark
Last active February 29, 2016 11:11
Show Gist options
  • Save caspark/3b5c7232746b00ed1b13 to your computer and use it in GitHub Desktop.
Save caspark/3b5c7232746b00ed1b13 to your computer and use it in GitHub Desktop.
diff --git a/source_control/git.py b/source_control/git.py
index dc8fe20..943fa39 100644
--- a/source_control/git.py
+++ b/source_control/git.py
@@ -688,6 +688,10 @@ def main():
# call run_command()
module.run_command_environ_update = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C', LC_CTYPE='C')
+ import time
+ start_time = int(time.time())
+ timings = ['time at beginning: ' + str(int(time.time()) - start_time)]
+
gitconfig = None
if not dest and allow_clone:
module.fail_json(msg="the destination directory must be specified unless clone=no")
@@ -756,15 +760,20 @@ def main():
reset(git_path, module, dest)
# exit if already at desired sha version
set_remote_url(git_path, module, repo, dest, remote)
+ timings.append('time before getting remote head: ' + str(int(time.time()) - start_time))
remote_head = get_remote_head(git_path, module, dest, version, remote, bare)
+ timings.append('time after getting remote head: ' + str(int(time.time()) - start_time))
if before == remote_head:
+ timings.append('time before checking remote tag: ' + str(int(time.time()) - start_time))
if local_mods:
module.exit_json(changed=True, before=before, after=remote_head,
msg="Local modifications exist")
elif is_remote_tag(git_path, module, dest, repo, version):
# if the remote is a tag and we have the tag locally, exit early
+ timings.append('time before getting tags: ' + str(int(time.time()) - start_time))
if version in get_tags(git_path, module, dest):
repo_updated = False
+ timings.append('time after getting tags: ' + str(int(time.time()) - start_time))
else:
# if the remote is a branch and we have the branch locally, exit early
if version in get_branches(git_path, module, dest):
@@ -772,7 +781,9 @@ def main():
if repo_updated is None:
if module.check_mode:
module.exit_json(changed=True, before=before, after=remote_head)
+ timings.append('time before doing git fetch: ' + str(int(time.time()) - start_time))
fetch(git_path, module, repo, dest, version, remote, bare, refspec)
+ timings.append('time after doing git fetch: ' + str(int(time.time()) - start_time))
repo_updated = True
# switch to version specified regardless of whether
@@ -810,7 +821,8 @@ def main():
# No need to fail if the file already doesn't exist
pass
- module.exit_json(changed=changed, before=before, after=after)
+ timings.append('time at end: ' + str(int(time.time()) - start_time))
+ module.exit_json(changed=changed, before=before, after=after, timings=timings)
# import module snippets
from ansible.module_utils.basic import *
time hacking/test-module -m lib/ansible/modules/core/source_control/git.py \
-a 'repo=git@github.com:BurntSushi/quickcheck.git dest=/tmp/rs-quickcheck recursive=no'
{
"after": "c9438a39cc5f3f3aea3d6cef941c840bbe94a16c",
"before": "c9438a39cc5f3f3aea3d6cef941c840bbe94a16c",
"changed": false,
"invocation": {
"module_args": {
"accept_hostkey": false,
"bare": false,
"clone": true,
"depth": null,
"dest": "/tmp/rs-quickcheck",
"executable": null,
"force": false,
"key_file": null,
"recursive": false,
"reference": null,
"refspec": null,
"remote": "origin",
"repo": "git@github.com:BurntSushi/quickcheck.git",
"ssh_opts": null,
"track_submodules": false,
"update": true,
"verify_commit": false,
"version": "HEAD"
}
},
"timings": [
"time at beginning: 0",
"time before getting remote head: 0",
"time after getting remote head: 4",
"time before checking remote tag: 4",
"time before doing git fetch: 8",
"time after doing git fetch: 14",
"time at end: 14"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment