Created
September 28, 2012 22:22
-
-
Save alex-ethier/3802367 to your computer and use it in GitHub Desktop.
Couchbase python lib profiling (couchbase==0.8.0)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from couchbase.client import Couchbase | |
def profile_insert_doc(): | |
couchbase = Couchbase( | |
"localhost:8091", | |
"default", "" | |
) | |
bucket = couchbase["default"] | |
key = "test_key" | |
val = "test_val" | |
bucket.set(key, 0, 0, val) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cProfile | |
import pstats | |
import cStringIO | |
from couchbase.client import Couchbase | |
import logging | |
logger = logging.getLogger('cbtest') | |
logger.setLevel(logging.INFO) | |
ch = logging.StreamHandler() | |
ch.setLevel(logging.INFO) | |
formatter = logging.Formatter( | |
'%(asctime)s \ | |
- %(name)s \ | |
- %(levelname)s \ | |
- %(message)s' | |
) | |
ch.setFormatter(formatter) | |
logger.addHandler(ch) | |
def profile_app(function_name): | |
pr = cProfile.Profile() | |
pr = pr.run("%s()" % function_name) | |
stream = cStringIO.StringIO() | |
ps = pstats.Stats(pr, stream=stream) | |
ps.strip_dirs() | |
ps.sort_stats("cumulative") | |
ps.print_stats("couchbase") | |
log = stream.getvalue() | |
stream.close() | |
logger.info("Profile data:\n%s", log) | |
def profile_insert_doc(): | |
couchbase = Couchbase( | |
"localhost:8091", | |
"default", "" | |
) | |
bucket = couchbase["default"] | |
key = "test_key" | |
val = "test_val" | |
bucket.set(key, 0, 0, val) | |
def main(): | |
profile_app("profile_insert_doc") | |
if __name__ == '__main__': | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2012-09-28 14:58:57,308 - cbtest - INFO - Profile data: | |
91054 function calls (90937 primitive calls) in 2.477 seconds | |
Ordered by: cumulative time | |
List reduced from 500 to 50 due to restriction <'couchbase'> | |
ncalls tottime percall cumtime percall filename:lineno(function) | |
2 0.185 0.093 2.280 1.140 couchbase/event.py:54(wait) | |
1 0.000 0.000 2.276 2.276 couchbase/client.py:204(__del__) | |
1 0.000 0.000 2.276 2.276 couchbase/couchbaseclient.py:493(done) | |
1 0.000 0.000 2.276 2.276 couchbase/couchbaseclient.py:62(shutdown) | |
1 0.000 0.000 0.200 0.200 couchbase-db.py:35(profile_insert_doc) | |
1 0.000 0.000 0.147 0.147 couchbase/client.py:140(__getitem__) | |
1 0.000 0.000 0.147 0.147 couchbase/client.py:96(bucket) | |
1 0.000 0.000 0.147 0.147 couchbase/client.py:191(__init__) | |
1 0.000 0.000 0.103 0.103 couchbase/couchbaseclient.py:295(__init__) | |
5 0.001 0.000 0.082 0.016 couchbase/rest_client.py:689(get_bucket) | |
1 0.000 0.000 0.049 0.049 couchbase/client.py:40(__init__) | |
5 0.000 0.000 0.046 0.009 couchbase/rest_client.py:282(_http_request) | |
2 0.000 0.000 0.042 0.021 couchbase/rest_client.py:160(__init__) | |
5 0.000 0.000 0.035 0.007 couchbase/rest_client.py:1043(parse_get_bucket_response) | |
1 0.001 0.001 0.035 0.035 couchbase/couchbaseclient.py:400(init_vbucket_connections) | |
1024 0.005 0.000 0.034 0.000 couchbase/couchbaseclient.py:408(start_vbucket_connection) | |
15007 0.034 0.000 0.034 0.000 couchbase/event.py:30(__iadd__) | |
1 0.001 0.001 0.032 0.032 couchbase/couchbaseclient.py:445(reconfig_vbucket_map) | |
2 0.000 0.000 0.031 0.016 couchbase/rest_client.py:703(get_vbuckets) | |
5 0.016 0.003 0.030 0.006 couchbase/rest_client.py:1047(parse_get_bucket_json) | |
1 0.000 0.000 0.025 0.025 couchbase/client.py:146(_rest) | |
1 0.000 0.000 0.016 0.016 couchbase/couchbaseclient.py:623(direct_client) | |
1 0.000 0.000 0.015 0.015 couchbase/rest_client.py:89(vbucket_map_ready) | |
15008 0.010 0.000 0.010 0.000 couchbase/event.py:38(check) | |
5120 0.008 0.000 0.008 0.000 couchbase/rest_client.py:978(__init__) | |
1 0.000 0.000 0.004 0.004 couchbase/client.py:219(set) | |
1 0.000 0.000 0.004 0.004 couchbase/couchbaseclient.py:551(set) | |
1 0.000 0.000 0.004 0.004 couchbase/couchbaseclient.py:503(_respond) | |
1 0.000 0.000 0.001 0.001 couchbase/memcachedclient.py:39(__init__) | |
3 0.000 0.000 0.000 0.000 couchbase/logger.py:21(logger) | |
1 0.000 0.000 0.000 0.000 couchbase/memcachedclient.py:259(sasl_auth_plain) | |
1 0.000 0.000 0.000 0.000 couchbase/memcachedclient.py:255(sasl_auth_start) | |
1 0.000 0.000 0.000 0.000 couchbase/memcachedclient.py:112(_doCmd) | |
1 0.000 0.000 0.000 0.000 couchbase/couchbaseclient.py:41(__init__) | |
1 0.000 0.000 0.000 0.000 couchbase/memcachedclient.py:107(_handleSingleResponse) | |
1 0.000 0.000 0.000 0.000 couchbase/memcachedclient.py:99(_handleKeyedResponse) | |
1 0.000 0.000 0.000 0.000 couchbase/memcachedclient.py:72(_recvMsg) | |
1 0.000 0.000 0.000 0.000 couchbase/client.py:156(_rest_info) | |
1 0.000 0.000 0.000 0.000 couchbase/memcachedclient.py:49(close) | |
1 0.000 0.000 0.000 0.000 couchbase/memcachedclient.py:55(_sendCmd) | |
1 0.000 0.000 0.000 0.000 couchbase/memcachedclient.py:59(_sendMsg) | |
5 0.000 0.000 0.000 0.000 couchbase/rest_client.py:930(__init__) | |
1 0.000 0.000 0.000 0.000 couchbase/couchbaseclient.py:55(put) | |
5 0.000 0.000 0.000 0.000 couchbase/rest_client.py:915(__init__) | |
5 0.000 0.000 0.000 0.000 couchbase/rest_client.py:967(__init__) | |
5 0.000 0.000 0.000 0.000 couchbase/rest_client.py:275(_create_headers) | |
2 0.000 0.000 0.000 0.000 couchbase/event.py:24(__init__) | |
2 0.000 0.000 0.000 0.000 couchbase/event.py:45(__init__) | |
1 0.000 0.000 0.000 0.000 couchbase/rest_client.py:36(__init__) | |
1 0.000 0.000 0.000 0.000 couchbase/event.py:51(is_set) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment