{ "info": { "author": "NetAngels", "author_email": "info@netangels.ru", "bugtrack_url": null, "classifiers": [], "description": "mongo-profile\n=============\n\nModule **mongoprofile** contains functions and objects to retreive and parse\nthe output of MongoDB's ``\"db.system.profile.find()\"``\n\nTo get more information about MongoDB profiling, see\nhttp://www.mongodb.org/display/DOCS/Database+Profiler\n\n\nmongoprofile.MongoProfiler\n--------------------------\n\nClass `MongoProfiler` is a \"with\"-wrapper around any set of MongoDB queries.\nTypical usecase contains three steps:\n\n**Step1. Open connection**::\n\n >>> from pymongo import Connection\n >>> db = Connection().test\n\n**Step 2. Execute and profile queries**::\n\n >>> profiler = MongoProfiler(db)\n >>> with profiler:\n ... db.people.insert(dict(name='John', age=20))\n ... db.people.insert(dict(name='Mary', age=30))\n ... db.people.update({'name': 'John'}, {'age': 21})\n ... db.people.remove({'name': 'Mary'})\n ... list(db.people.find({'age': {'$gt': 20.0}}))\n ... db.people.find({'age': {'$gt': 20.0}}).count()\n\n**Step3. Get profile info**\n\nAs a result, you will get the more or less comprehensive list of dict\nsubclasses, containing all profile information, including parsed \"info\". Every\nsubclass has redefined ``__str__`` method returning the convenient presentation\nof request. See the example below to get the point::\n\n >>> for record in profiler.get_records():\n ... print str(record)\n\n test> db.people.insert({...})\n test> db.people.insert({...})\n test> db.people.update({ name: \"John\" }, {...})\n test> db.people.remove({ name: \"Mary\" })\n test> db.people.find({ $query: { age: { $gt: 20.0 } } })\n test> db.runCommand({ count: \"people\", query: { age: { $gt: 20.0 } }, fields: null })\n\nA few more facts about record objects worth to be known:\n\n- There is a ``record.short_info()`` method returning the one-line string with\n short information about the query.\n- Every record class is a subclass of dict, and because of that it's possible\n to get a bunch of ordered information using calls such as\n ``record['millis']``, ``record['ts']``, etc.\n\nMarkers\n````````\n\nThe ``MongoProfiler`` class has ``.mark(text)`` method. When ``mark`` is\ninvoked, mongodb client do the fake query to phony collection just to record\ndata in log. After the job has ended, these markers will be available as \n`'==== text ===='` records.\n\nHaving changed previous example, we get something like this.\n\nCommands::\n\n\n >>> profiler = MongoProfiler(db)\n >>> with profiler:\n ... profiler.mark('insert')\n ... db.people.insert(dict(name='John', age=20))\n ... db.people.insert(dict(name='Mary', age=30))\n ... profiler.mark('search')\n ... list(db.people.find({'age': {'$gt': 20.0}}))\n ... db.people.find({'age': {'$gt': 20.0}}).count()\n\n\nWill lead to the output::\n\n '==== insert ===='\n test> db.people.insert({...})\n test> db.people.insert({...})\n '==== search ===='\n test> db.people.find({ $query: { age: { $gt: 20.0 } } })\n test> db.runCommand({ count: \"people\", query: { age: { $gt: 20.0 } }, fields: null })\n\nDummyMongoProfiler\n-------------------\n\nIt is probable that depending on some circumstances, you want or don't want to\nspend extra resources on your query profiling. Stub ``DummyMongoProfiler``\nclass mocking ``MongoProfiler`` interface can be used for that purpose. Below\nis the usage sample with `Django-nonrel`_ in mind::\n\n >>> from django.conf import settings\n >>> Profiler = settings.DEBUG and MongoProfiler or DummyMongoProfiler\n >>> profiler = Profiler(db)\n >>> with profiler:\n ... ModelClass.objects.filter(...)\n ...\n\n.. _Django-nonrel: http://www.allbuttonspressed.com/projects/django-nonrel\n\nMiscellaneous remarks\n---------------------\n\nCollection `db.system.profile` is capped with a relatively small capacity. If\nyou want to profile large amount of records at once, it is worth to extend its\nsize. The following set of commands creates capped collection of 100Mb::\n\n > db.setProfilingLevel(0)\n > db.system.profile.drop()\n > db.createCollection(\"system.profile\", {capped:true, size:100*1e6})\n\nCommand ``db.system.profile.stats()`` shows you the current state of\ncollection.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/NetAngels/mongo-profile", "keywords": null, "license": "BSD License", "maintainer": null, "maintainer_email": null, "name": "mongo-profile", "package_url": "https://pypi.org/project/mongo-profile/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/mongo-profile/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/NetAngels/mongo-profile" }, "release_url": "https://pypi.org/project/mongo-profile/0.4.1/", "requires_dist": null, "requires_python": null, "summary": "MongoDB profile helper", "version": "0.4.1" }, "last_serial": 794933, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "b5db631ce9105be90e880530d47a3a8f", "sha256": "8f39e71f88d5db50b0d2e25b9ac901195407c78ce289e7f07d679bfb11e8b923" }, "downloads": -1, "filename": "mongo-profile-0.1.tar.gz", "has_sig": false, "md5_digest": "b5db631ce9105be90e880530d47a3a8f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2815, "upload_time": "2011-03-23T13:22:37", "url": "https://files.pythonhosted.org/packages/d6/f6/56319fa2bbf8fb629f9d29fff580be95bbadce586a36876cd634c494781c/mongo-profile-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "63347b2db78e45f5a6abb03a660655b2", "sha256": "f0d654aed8f8d202e92b9dfbaeb3e84147a7a80ed389b929177ca05c9f3281b7" }, "downloads": -1, "filename": "mongo-profile-0.2.tar.gz", "has_sig": false, "md5_digest": "63347b2db78e45f5a6abb03a660655b2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3293, "upload_time": "2011-03-24T10:10:42", "url": "https://files.pythonhosted.org/packages/5b/a9/ae77b5f6d1ba40830479efe7745aa0b0a014309ff22d01527fd38b54535c/mongo-profile-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "73bc1eb17ab7f71d9322e3da158eee5d", "sha256": "fc5c53bd19abe91a1218bd186ebb8e1ffe13b503e9c6f93863e5d045fbe66863" }, "downloads": -1, "filename": "mongo-profile-0.3.tar.gz", "has_sig": false, "md5_digest": "73bc1eb17ab7f71d9322e3da158eee5d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3767, "upload_time": "2011-03-28T07:48:47", "url": "https://files.pythonhosted.org/packages/d4/ec/4243dd801644ccd38f7f7da7ecbcb113cf2b57bb842591a62020e9aaeb04/mongo-profile-0.3.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "3f5f50694099e7ed5fbf464091f6c746", "sha256": "e387ee970c6a3047b2fbcf49bd68f3e8056405dd01ae99dbe78813997c349187" }, "downloads": -1, "filename": "mongo-profile-0.4.tar.gz", "has_sig": false, "md5_digest": "3f5f50694099e7ed5fbf464091f6c746", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4015, "upload_time": "2011-03-30T10:53:47", "url": "https://files.pythonhosted.org/packages/f5/a1/61d434c66276c5e20be10a7535bebd5e0b8382acd843e0af373dddd14f27/mongo-profile-0.4.tar.gz" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "e05089ba0f066a28f14055f0164f258d", "sha256": "ecbcd806a84a44807ea5a4ef5915ce4e58bb63925fc77d2820d7e40533cce60c" }, "downloads": -1, "filename": "mongo-profile-0.4.1.tar.gz", "has_sig": false, "md5_digest": "e05089ba0f066a28f14055f0164f258d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4060, "upload_time": "2011-06-21T12:34:19", "url": "https://files.pythonhosted.org/packages/f2/0d/c5045b20e1959e37864668438cb31f71b6de75d627d7ad5089ca16354efb/mongo-profile-0.4.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e05089ba0f066a28f14055f0164f258d", "sha256": "ecbcd806a84a44807ea5a4ef5915ce4e58bb63925fc77d2820d7e40533cce60c" }, "downloads": -1, "filename": "mongo-profile-0.4.1.tar.gz", "has_sig": false, "md5_digest": "e05089ba0f066a28f14055f0164f258d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4060, "upload_time": "2011-06-21T12:34:19", "url": "https://files.pythonhosted.org/packages/f2/0d/c5045b20e1959e37864668438cb31f71b6de75d627d7ad5089ca16354efb/mongo-profile-0.4.1.tar.gz" } ] }