google-cloud-profiler


Namegoogle-cloud-profiler JSON
Version 4.1.0 PyPI version JSON
download
home_pagehttps://github.com/GoogleCloudPlatform/cloud-profiler-python
SummaryGoogle Cloud Profiler Python Agent
upload_time2023-08-16 16:57:56
maintainer
docs_urlNone
authorGoogle LLC
requires_python
licenseApache License, Version 2.0
keywords google cloud profiler
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Google Cloud Python profiling agent

Python profiling agent for
[Google Cloud Profiler](https://cloud.google.com/profiler/).

See
[Google Cloud Profiler profiling Python code](https://cloud.google.com/profiler/docs/profiling-python)
for detailed documentation.

## Supported OS

Linux. Profiling Python applications is supported for Linux kernels whose
standard C library is implemented with `glibc` or with `musl`. For configuration
information specific to Linux Alpine kernels, see
[Running on Linux Alpine](https://cloud.google.com/profiler/docs/profiling-python#running_with_linux_alpine).

## Supported Python Versions

Python >= 3.7 and <= 3.11

## Installation & usage

1.  Install the profiler package using PyPI:

    ```shell
    pip3 install google-cloud-profiler
    ```

2.  Enable the profiler in your application:

    ```python
    import googlecloudprofiler

    def main():
        # Profiler initialization. It starts a daemon thread which continuously
        # collects and uploads profiles. Best done as early as possible.
        try:
            googlecloudprofiler.start(
                service='hello-profiler',
                service_version='1.0.1',
                # verbose is the logging level. 0-error, 1-warning, 2-info,
                # 3-debug. It defaults to 0 (error) if not set.
                verbose=3,
                # project_id must be set if not running on GCP.
                # project_id='my-project-id',
            )
        except (ValueError, NotImplementedError) as exc:
            print(exc)  # Handle errors here
    ```

## Installation on Linux Alpine

The Python profiling agent has a native component. The base Alpine image for
Python does not have all dependencies required to build this native component
installed. To build the Python profiling agent on Alpine, one must install the
package `build-base`.

To use the Python profiling agent on Alpine without installing additional
dependencies on to the final Alpine image, one can use a two-stage build and
compile the Python profiling agent in the first stage.

Here is an example of a Docker image that uses a multi-stage build to compile
and install the Python profiling agent:

```
FROM python:3.7-alpine as builder

# Install build-base to allow for compilation of the profiling agent.
RUN apk add --update --no-cache build-base

# Compile the profiling agent, generating wheels for it.
RUN pip3 wheel --wheel-dir=/tmp/wheels google-cloud-profiler


FROM python:3.7-alpine

# Copy over the directory containing wheels for the profiling agent.
COPY --from=builder /tmp/wheels /tmp/wheels

# Install the profiling agent.
RUN pip3 install --no-index --find-links=/tmp/wheels google-cloud-profiler

# Install any other required modules or dependencies, and copy an app which
# enables the profiler as described in "Enable the profiler in your
# application".
COPY ./bench.py .

# Run the application when the docker image is run, using either CMD (as is done
# here) or ENTRYPOINT.
CMD python3 -u bench.py
```


## Troubleshooting

### Resource temporarily unavailable errors with Python

If you see the following log entries after enabling the Profiler:

```
BlockingIOError: [Errno 11] Resource temporarily unavailable
Exception ignored when trying to write to the signal wakeup fd
```

see https://cloud.google.com/profiler/docs/troubleshooting#python-blocking for
the cause and the workaround.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/GoogleCloudPlatform/cloud-profiler-python",
    "name": "google-cloud-profiler",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "google cloud profiler",
    "author": "Google LLC",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/44/be/fa9b4915315c764a38b42aac1a6355bb65deb5cb8a97c1a01c0de425780d/google-cloud-profiler-4.1.0.tar.gz",
    "platform": null,
    "description": "# Google Cloud Python profiling agent\n\nPython profiling agent for\n[Google Cloud Profiler](https://cloud.google.com/profiler/).\n\nSee\n[Google Cloud Profiler profiling Python code](https://cloud.google.com/profiler/docs/profiling-python)\nfor detailed documentation.\n\n## Supported OS\n\nLinux. Profiling Python applications is supported for Linux kernels whose\nstandard C library is implemented with `glibc` or with `musl`. For configuration\ninformation specific to Linux Alpine kernels, see\n[Running on Linux Alpine](https://cloud.google.com/profiler/docs/profiling-python#running_with_linux_alpine).\n\n## Supported Python Versions\n\nPython >= 3.7 and <= 3.11\n\n## Installation & usage\n\n1.  Install the profiler package using PyPI:\n\n    ```shell\n    pip3 install google-cloud-profiler\n    ```\n\n2.  Enable the profiler in your application:\n\n    ```python\n    import googlecloudprofiler\n\n    def main():\n        # Profiler initialization. It starts a daemon thread which continuously\n        # collects and uploads profiles. Best done as early as possible.\n        try:\n            googlecloudprofiler.start(\n                service='hello-profiler',\n                service_version='1.0.1',\n                # verbose is the logging level. 0-error, 1-warning, 2-info,\n                # 3-debug. It defaults to 0 (error) if not set.\n                verbose=3,\n                # project_id must be set if not running on GCP.\n                # project_id='my-project-id',\n            )\n        except (ValueError, NotImplementedError) as exc:\n            print(exc)  # Handle errors here\n    ```\n\n## Installation on Linux Alpine\n\nThe Python profiling agent has a native component. The base Alpine image for\nPython does not have all dependencies required to build this native component\ninstalled. To build the Python profiling agent on Alpine, one must install the\npackage `build-base`.\n\nTo use the Python profiling agent on Alpine without installing additional\ndependencies on to the final Alpine image, one can use a two-stage build and\ncompile the Python profiling agent in the first stage.\n\nHere is an example of a Docker image that uses a multi-stage build to compile\nand install the Python profiling agent:\n\n```\nFROM python:3.7-alpine as builder\n\n# Install build-base to allow for compilation of the profiling agent.\nRUN apk add --update --no-cache build-base\n\n# Compile the profiling agent, generating wheels for it.\nRUN pip3 wheel --wheel-dir=/tmp/wheels google-cloud-profiler\n\n\nFROM python:3.7-alpine\n\n# Copy over the directory containing wheels for the profiling agent.\nCOPY --from=builder /tmp/wheels /tmp/wheels\n\n# Install the profiling agent.\nRUN pip3 install --no-index --find-links=/tmp/wheels google-cloud-profiler\n\n# Install any other required modules or dependencies, and copy an app which\n# enables the profiler as described in \"Enable the profiler in your\n# application\".\nCOPY ./bench.py .\n\n# Run the application when the docker image is run, using either CMD (as is done\n# here) or ENTRYPOINT.\nCMD python3 -u bench.py\n```\n\n\n## Troubleshooting\n\n### Resource temporarily unavailable errors with Python\n\nIf you see the following log entries after enabling the Profiler:\n\n```\nBlockingIOError: [Errno 11] Resource temporarily unavailable\nException ignored when trying to write to the signal wakeup fd\n```\n\nsee https://cloud.google.com/profiler/docs/troubleshooting#python-blocking for\nthe cause and the workaround.\n",
    "bugtrack_url": null,
    "license": "Apache License, Version 2.0",
    "summary": "Google Cloud Profiler Python Agent",
    "version": "4.1.0",
    "project_urls": {
        "Homepage": "https://github.com/GoogleCloudPlatform/cloud-profiler-python"
    },
    "split_keywords": [
        "google",
        "cloud",
        "profiler"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "44befa9b4915315c764a38b42aac1a6355bb65deb5cb8a97c1a01c0de425780d",
                "md5": "c64c226a74d8498b239db47221546413",
                "sha256": "2d90f9c6d4c075ad6d43752ae39424c3d0bad63e6549a2c761881f9a235067ae"
            },
            "downloads": -1,
            "filename": "google-cloud-profiler-4.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c64c226a74d8498b239db47221546413",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 32305,
            "upload_time": "2023-08-16T16:57:56",
            "upload_time_iso_8601": "2023-08-16T16:57:56.332705Z",
            "url": "https://files.pythonhosted.org/packages/44/be/fa9b4915315c764a38b42aac1a6355bb65deb5cb8a97c1a01c0de425780d/google-cloud-profiler-4.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-16 16:57:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "GoogleCloudPlatform",
    "github_project": "cloud-profiler-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "google-cloud-profiler"
}
        
Elapsed time: 0.27070s