# -*- coding: utf-8 -*-
from distutils.core import setup

packages = \
['speedinfo',
 'speedinfo.conditions',
 'speedinfo.storage',
 'speedinfo.storage.cache',
 'speedinfo.storage.database',
 'speedinfo.storage.database.migrations']

package_data = \
{'': ['*'],
 'speedinfo': ['static/speedinfo/css/*',
               'static/speedinfo/img/*',
               'static/speedinfo/js/*',
               'templates/admin/speedinfo/*']}

setup_kwargs = {
    'name': 'django-speedinfo',
    'version': '2.0.0',
    'description': 'Live profiling tool for Django framework to measure views performance',
    'long_description': '# django-speedinfo\n\n[![Build Status](https://travis-ci.org/catcombo/django-speedinfo.svg?branch=master)](https://travis-ci.org/catcombo/django-speedinfo)\n[![Coverage Status](https://coveralls.io/repos/github/catcombo/django-speedinfo/badge.svg?branch=master)](https://coveralls.io/github/catcombo/django-speedinfo?branch=master)\n\n`django-speedinfo` is a live profiling tool for Django projects to find\nthe most high loaded views for the next optimization. `django-speedinfo` counts\nnumber of calls, cache hits, SQL queries, measures average and total call time\nand more for each of your views. Detailed report and profiler controls are\navailable in Django admin.\n\n![Speedinfo admin screenshot](https://github.com/catcombo/django-speedinfo/raw/master/screenshots/main.png)\n\n\n# Prerequisites\n\n- Python 2.7, 3.6+\n- Django 1.8+\n\n\n# Installation\n\n```\npip install django-speedinfo\n```\n\n# Upgrading from 1.x\n\nOld profiling data will be unavailable after upgrading. Don\'t forget to export the data in advance.\n\n- Setup one of the storage backends as shown in the section 4 of [Setup](#setup) below.\n- `SPEEDINFO_PROFILING_CONDITIONS` is empty by default. If you use `SPEEDINFO_EXCLUDE_URLS` in your\n  project you need to initialize the list of conditions explicitly:\n  `SPEEDINFO_PROFILING_CONDITIONS = ["speedinfo.conditions.exclude_urls.ExcludeURLCondition"]`\n- `SPEEDINFO_REPORT_COLUMNS` and `SPEEDINFO_REPORT_COLUMNS_FORMAT` were removed, use `SPEEDINFO_ADMIN_COLUMNS` instead.\n  Every entry in `SPEEDINFO_ADMIN_COLUMNS` list is a tuple (column name, value format, attribute name).\n  See [Customize admin columns](#customize-admin-columns) for details. To add extra columns\n  follow the instruction in the section [Extra admin columns](#extra-admin-columns) below.\n- `speedinfo.settings` module renamed to `speedinfo.conf`\n- Base condition class was renamed from `Condition` to `AbstractCondition`\n\n\n# Setup\n\n1. Add `speedinfo` to `INSTALLED_APPS`.\n2. Add `speedinfo.middleware.ProfilerMiddleware` to the end of `MIDDLEWARE` (or `MIDDLEWARE_CLASSES` for Django < 1.10) \nlist, but before `django.middleware.cache.FetchFromCacheMiddleware` (if used):\n    ```\n    MIDDLEWARE = [\n        ...,\n        "speedinfo.middleware.ProfilerMiddleware",\n        "django.middleware.cache.FetchFromCacheMiddleware",\n    ]\n    ```\n3. Setup any cache backend (except local-memory and dummy caching) using our proxy cache backend.\n`django-speedinfo` needs the cache to store profiler state between requests and to intercept calls to cache:\n    ```\n    CACHES = {\n        "default": {\n            "BACKEND": "speedinfo.backends.proxy_cache",\n            "CACHE_BACKEND": "django.core.cache.backends.filebased.FileBasedCache",\n            "LOCATION": "/var/tmp/django_cache",\n        }\n    }\n    ```\n4. Setup storage for profiling data. `django-speedinfo` comes with two storages to choose from:\n    - **Database storage**\n        1. Add `speedinfo.storage.database` to `INSTALLED_APPS`.\n        2. Add `SPEEDINFO_STORAGE = "speedinfo.storage.database.storage.DatabaseStorage"` to project settings.\n        3. Run `python manage.py migrate`.\n    - **Cache storage**\n        1. Add `SPEEDINFO_STORAGE = "speedinfo.storage.cache.storage.CacheStorage"` to project settings.\n        2. Optionally you may define a separate cache in `CACHES` to store profiling data.\n           To use it in `CacheStorage` assign `SPEEDINFO_CACHE_STORAGE_CACHE_ALIAS` to the appropriate cache alias.\n           Example:\n            ```\n            CACHES = {\n                "default": {\n                    "BACKEND": "speedinfo.backends.proxy_cache",\n                    "CACHE_BACKEND": "django.core.cache.backends.db.DatabaseCache",\n                    "LOCATION": "cache_table",\n                },\n                "speedinfo-storage": {\n                    "BACKEND": "django.core.cache.backends.memcached.MemcachedCache",\n                    "LOCATION": "127.0.0.1:11211",\n                },\n            })\n            \n            SPEEDINFO_CACHE_STORAGE_CACHE_ALIAS = "speedinfo-storage"\n            ```\n5. Run `python manage.py collectstatic`.\n\n\n# Usage\n\nOpen `Views profiler` in Django admin. Click the `Turn on` / `Turn off` button\nto control profiler state. Press `Reset` button to delete all profiling data.\n\n\n# Advanced features\n\n## Custom page caching\n\n`django-speedinfo` automatically detects when Django use per-site caching via\n`UpdateCacheMiddleware` and `FetchFromCacheMiddleware` middlewares\nor per-view caching via `cache_page` decorator and counts cache hit\nwhen retrieving pages from the cache.\n\nIf you implement your own caching logic and want to mark the view response\nas obtained from the cache, add specified attribute to the `HttpResponse` object\nas shown below:\n```\nfrom django.views import View\nfrom from speedinfo.conf import speedinfo_settings\n\nclass CachedView(View):\n    def get(self, request, *args, **kwargs):\n        # ...\n        # Assume that `response` was taken from the cache\n        setattr(response, speedinfo_settings.SPEEDINFO_CACHED_RESPONSE_ATTR_NAME, True)\n        return response\n```\nThe default value of `SPEEDINFO_CACHED_RESPONSE_ATTR_NAME` is `_is_cached`.\nBut you can override it if the attribute name is conflicts with your application logic.\n\n## Customize admin columns\n\n`SPEEDINFO_ADMIN_COLUMNS` allows to control visibility and appearance of Django admin\nprofiler columns. Every entry in the `SPEEDINFO_ADMIN_COLUMNS` list is a tuple of\n(column name, value format, `ViewProfiler` attribute name). Default value:\n```\nSPEEDINFO_ADMIN_COLUMNS = (\n    ("View name", "{}", "view_name"),\n    ("HTTP method", "{}", "method"),\n    ("Anonymous calls", "{:.1f}%", "anon_calls_ratio"),\n    ("Cache hits", "{:.1f}%", "cache_hits_ratio"),\n    ("SQL queries per call", "{}", "sql_count_per_call"),\n    ("SQL time", "{:.1f}%", "sql_time_ratio"),\n    ("Total calls", "{}", "total_calls"),\n    ("Time per call", "{:.8f}", "time_per_call"),\n    ("Total time", "{:.4f}", "total_time"),\n)\n```\n\n## Extra admin columns\n\nTo add additional data to a storage and columns to admin follow the instruction:\n\n1. Create [custom storage backend](#custom-storage-backend) which will hold or calculate\n   additional fields.\n2. Implement storage `fetch_all()` method that will return the list of the `ViewProfiler`\n   instances initialized with the extra fields. Example:\n   ```\n   def fetch_all(self, ordering=None):\n       ...\n       return [\n           ViewProfiler(view_name="...", method="...", ..., extra_field="...")\n           ...\n       ]\n   ```\n3. Implement sorting by extra fields in `fetch_all()` method.\n4. Add extra fields to `SPEEDINFO_ADMIN_COLUMNS` as described in the section\n   [Customize admin columns](#customize-admin-columns).\n\n## Profiling conditions\n\n`SPEEDINFO_PROFILING_CONDITIONS` allows to declare a list of condition classes\nto filter profiling views by some rules. By default `SPEEDINFO_PROFILING_CONDITIONS` is empty.\n`django-speedinfo` comes with one build-in condition - `ExcludeURLCondition`. It allows to\nexclude some urls from profiling by adding them to the `SPEEDINFO_EXCLUDE_URLS` list.\nEach entry in `SPEEDINFO_EXCLUDE_URLS` is a regex compatible expression to test requested url.\nUsage example:\n```\nSPEEDINFO_PROFILING_CONDITIONS = [\n    "speedinfo.conditions.exclude_urls.ExcludeURLCondition",\n]\n\nSPEEDINFO_EXCLUDE_URLS = [\n    r"/admin/",\n    r"/news/$",\n    r"/movie/\\d+/$",\n]\n```\n\nTo define your own condition class, you must inherit from the base class `speedinfo.conditions.base.AbstractCondition`\nand implement all abstract methods. See `ExcludeURLCondition` source code for implementation example. Then add\nfull path to your class to `SPEEDINFO_PROFILING_CONDITIONS` list as shown above. Conditions in mentioned list\nare executed in a top-down order. The first condition returning `False` interrupts the further check.\n\n## Custom storage backend\n\n`django-speedinfo` comes with `DatabaseStorage` and `CacheStorage`. But you may want to write your\nown storage (e.g. for MongoDB, Redis or even file-based). First create the storage class based on\n`speedinfo.storage.base.AbstractStorage` and implement all abstract methods. See `speedinfo.storage.cache.storage`\nand `speedinfo.storage.database.storage` as an examples. Then add path to your custom storage class\nto the project settings `SPEEDINFO_STORAGE = "path.to.module.CustomStorage"`. Use our tests\nto make sure that everything works as intended (you need to clone repository to get access to the `tests` package):\n```\nfrom django.test import TestCase, override_settings\nfrom tests.test_storage import StorageTestCase\n\n@override_settings(\n    SPEEDINFO_STORAGE="path.to.module.CustomStorage",\n    SPEEDINFO_TESTS=True,\n)\nclass CustomStorageTestCase(StorageTestCase, TestCase):\n    pass\n```\n\n\n# Notice\n\nThe number of SQL queries measured by `django-speedinfo` may differ from the values\nof `django-debug-toolbar` for the same view. It happens because `django-speedinfo`\nshows the average number of SQL queries for each view. Also profiler doesn\'t take\ninto account SQL queries made in the preceding middlewares.\n',
    'author': 'Evgeniy Krysanov',
    'author_email': 'evgeniy.krysanov@gmail.com',
    'url': 'https://github.com/catcombo/django-speedinfo',
    'packages': packages,
    'package_data': package_data,
    'python_requires': '>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
}


setup(**setup_kwargs)
