Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ac55510

Browse filesBrowse files
committed
version 1.0.0
0 parents  commit ac55510
Copy full SHA for ac55510

40 files changed

+3214
-0
lines changed

‎.gitignore

Copy file name to clipboard
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.DS_Store
2+
._
3+
._.*
4+
conf
5+
*.pyc
6+
build
7+
.bin
8+
log/*
9+
logs/*
10+
!.gitkeep
11+
tmp
12+
.tmp
13+
dist
14+
stackimpact.egg-info
15+
__pycache__

‎LICENSE.txt

Copy file name to clipboard
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright (c) 2017, StackImpact GmbH. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are met:
5+
* Redistributions of source code must retain the above copyright
6+
notice, this list of conditions and the following disclaimer.
7+
* Redistributions in binary form must reproduce the above copyright
8+
notice, this list of conditions and the following disclaimer in the
9+
documentation and/or other materials provided with the distribution.
10+
* Neither the name of the StackImpact GmbH nor the
11+
names of its contributors may be used to endorse or promote products
12+
derived from this software without specific prior written permission.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
18+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
25+

‎README.md

Copy file name to clipboard
+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# StackImpact Python Agent
2+
3+
## Overview
4+
5+
StackImpact is a performance profiler for production applications. It gives developers continuous and historical view of application performance with line-of-code precision, which includes CPU, memory allocation and blocking call hot spots as well as execution bottlenecks, errors and runtime metrics. Learn more at [stackimpact.com](https://stackimpact.com/).
6+
7+
![dashboard](https://stackimpact.com/wp-content/uploads/2017/06/hotspots-cpu-1.4-python.png)
8+
9+
#### Features
10+
11+
* Automatic hot spot profiling for CPU, memory allocations, blocking calls
12+
* Automatic bottleneck tracing for HTTP handlers and other libraries
13+
* Exception monitoring
14+
* Health monitoring including CPU, memory, garbage collection and other runtime metrics
15+
* Anomaly alerts on most important metrics
16+
* Multiple account users for team collaboration
17+
18+
Learn more on the [features](https://stackimpact.com/features/) page (with screenshots).
19+
20+
21+
#### Documentation
22+
23+
See full [documentation](https://stackimpact.com/docs/) for reference.
24+
25+
26+
27+
## Requirements
28+
29+
* Linux, OS X or Windows. Python version 2.7, 3.4 or higher.
30+
* Memorly allocation profiler and some GC metrics are only available for Python 3.
31+
* CPU and Time profilers only supports Linux and OS X.
32+
* Time (blocking call) profiler supports threads and gevent.
33+
34+
35+
36+
## Getting started
37+
38+
39+
#### Create StackImpact account
40+
41+
Sign up for a free account at [stackimpact.com](https://stackimpact.com/).
42+
43+
44+
#### Installing the agent
45+
46+
Install the Go agent by running
47+
48+
```
49+
pip install stackimpact
50+
```
51+
52+
And import the package in your application
53+
54+
```python
55+
import stackimpact
56+
```
57+
58+
59+
#### Configuring the agent
60+
61+
Start the agent in the main thread by specifying the agent key and application name. The agent key can be found in your account's Configuration section.
62+
63+
```python
64+
agent = stackimpact.start(
65+
agent_key = 'agent key here',
66+
app_name = 'MyPythonApp',
67+
```
68+
69+
Other initialization options:
70+
71+
* `app_version` (Optional) Sets application version, which can be used to associate profiling information with the source code release.
72+
* `app_environment` (Optional) Used to differentiate applications in different environments.
73+
* `host_name` (Optional) By default, host name will be the OS hostname.
74+
* `debug` (Optional) Enables debug logging.
75+
76+
77+
78+
#### Analyzing performance data in the Dashboard
79+
80+
Once your application is restarted, you can start observing regular and anomaly-triggered CPU, memory, I/O, and other hot spot profiles, execution bottlenecks as well as process metrics in the [Dashboard](https://dashboard.stackimpact.com/).
81+
82+
83+
#### Troubleshooting
84+
85+
To enable debug logging, add `debug = True` to startup options. If the debug log doesn't give you any hints on how to fix a problem, please report it to our support team in your account's Support section.
86+
87+
88+
## Overhead
89+
90+
The agent overhead is measured to be less than 1% for applications under high load.

‎README.rst

Copy file name to clipboard
+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
StackImpact Python Agent
2+
========================
3+
4+
Overview
5+
--------
6+
7+
StackImpact is a performance profiler for production applications. It
8+
gives developers continuous and historical view of application
9+
performance with line-of-code precision, which includes CPU, memory
10+
allocation and blocking call hot spots as well as execution bottlenecks,
11+
errors and runtime metrics. Learn more at
12+
`stackimpact.com <https://stackimpact.com/>`__.
13+
14+
.. figure:: https://stackimpact.com/wp-content/uploads/2017/06/hotspots-cpu-1.4-python.png
15+
:alt: dashboard
16+
17+
dashboard
18+
19+
Features
20+
^^^^^^^^
21+
22+
- Automatic hot spot profiling for CPU, memory allocations, blocking
23+
calls
24+
- Automatic bottleneck tracing for HTTP handlers and other libraries
25+
- Exception monitoring
26+
- Health monitoring including CPU, memory, garbage collection and other
27+
runtime metrics
28+
- Anomaly alerts on most important metrics
29+
- Multiple account users for team collaboration
30+
31+
Learn more on the `features <https://stackimpact.com/features/>`__ page
32+
(with screenshots).
33+
34+
Documentation
35+
^^^^^^^^^^^^^
36+
37+
See full `documentation <https://stackimpact.com/docs/>`__ for
38+
reference.
39+
40+
Requirements
41+
------------
42+
43+
- Linux, OS X or Windows. Python version 2.7, 3.4 or higher.
44+
- Memorly allocation profiler and some GC metrics are only available
45+
for Python 3.
46+
- CPU and Time profilers only supports Linux and OS X.
47+
- Time (blocking call) profiler supports threads and gevent.
48+
49+
Getting started
50+
---------------
51+
52+
Create StackImpact account
53+
^^^^^^^^^^^^^^^^^^^^^^^^^^
54+
55+
Sign up for a free account at
56+
`stackimpact.com <https://stackimpact.com/>`__.
57+
58+
Installing the agent
59+
^^^^^^^^^^^^^^^^^^^^
60+
61+
Install the Go agent by running
62+
63+
::
64+
65+
pip install stackimpact
66+
67+
And import the package in your application
68+
69+
.. code:: python
70+
71+
import stackimpact
72+
73+
Configuring the agent
74+
^^^^^^^^^^^^^^^^^^^^^
75+
76+
Start the agent in the main thread by specifying the agent key and
77+
application name. The agent key can be found in your account's
78+
Configuration section.
79+
80+
.. code:: python
81+
82+
agent = stackimpact.start(
83+
agent_key = 'agent key here',
84+
app_name = 'MyPythonApp',
85+
86+
Other initialization options:
87+
88+
- ``app_version`` (Optional) Sets application version, which can be
89+
used to associate profiling information with the source code release.
90+
- ``app_environment`` (Optional) Used to differentiate applications in
91+
different environments.
92+
- ``host_name`` (Optional) By default, host name will be the OS
93+
hostname.
94+
- ``debug`` (Optional) Enables debug logging.
95+
96+
Analyzing performance data in the Dashboard
97+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
98+
99+
Once your application is restarted, you can start observing regular and
100+
anomaly-triggered CPU, memory, I/O, and other hot spot profiles,
101+
execution bottlenecks as well as process metrics in the
102+
`Dashboard <https://dashboard.stackimpact.com/>`__.
103+
104+
Troubleshooting
105+
^^^^^^^^^^^^^^^
106+
107+
To enable debug logging, add ``debug = True`` to startup options. If the
108+
debug log doesn't give you any hints on how to fix a problem, please
109+
report it to our support team in your account's Support section.
110+
111+
Overhead
112+
--------
113+
114+
The agent overhead is measured to be less than 1% for applications under
115+
high load.

‎examples/flask_app.py

Copy file name to clipboard
+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# export AGENT_KEY=agent_key_here
2+
# gunicorn --workers 2 --bind 127.0.0.1:5010 flask_app:app
3+
# gunicorn --workers 2 -k gevent --bind 127.0.0.1:5010 flask_app:app
4+
5+
from __future__ import print_function
6+
7+
import os
8+
import time
9+
import sys
10+
import threading
11+
import subprocess
12+
import collections
13+
import random
14+
import traceback
15+
from flask import Flask
16+
17+
18+
try:
19+
# python 2
20+
from urllib2 import urlopen
21+
except ImportError:
22+
# python 3
23+
from urllib.request import urlopen
24+
25+
26+
import stackimpact
27+
28+
29+
30+
# StackImpact agent initialization
31+
agent = stackimpact.start(
32+
agent_key = os.environ['AGENT_KEY'],
33+
app_name = 'ExamplePythonFlaskApp',
34+
app_version = '1.0.0',
35+
debug = True)
36+
37+
38+
39+
# Simulate CPU intensive work
40+
def simulate_cpu():
41+
duration = 10 * 60 * 60
42+
usage = 20
43+
44+
while True:
45+
for j in range(0, duration):
46+
for i in range(0, usage * 20000):
47+
text = "text1" + str(i)
48+
text = text + "text2"
49+
50+
time.sleep(1 - usage/100)
51+
52+
t = threading.Thread(target=simulate_cpu)
53+
t.start()
54+
55+
56+
# Simulate memory leak
57+
def simulate_mem_leak():
58+
while True:
59+
mem1 = []
60+
61+
for j in range(0, 1800):
62+
mem2 = []
63+
for i in range(0, 1000):
64+
obj1 = {'v': random.randint(0, 1000000)}
65+
mem1.append(obj1)
66+
67+
obj2 = {'v': random.randint(0, 1000000)}
68+
mem2.append(obj2)
69+
70+
time.sleep(1)
71+
72+
t = threading.Thread(target=simulate_mem_leak)
73+
t.start()
74+
75+
76+
# Simulate lock
77+
def simulate_lock():
78+
lock = threading.Lock()
79+
80+
def lock_wait():
81+
lock.acquire()
82+
lock.release()
83+
84+
while True:
85+
lock.acquire()
86+
87+
t = threading.Thread(target=lock_wait)
88+
t.start()
89+
90+
time.sleep(1)
91+
92+
lock.release()
93+
94+
time.sleep(1)
95+
96+
t = threading.Thread(target=simulate_lock)
97+
t.start()
98+
99+
100+
# Simulate exceptions
101+
def simulate_exceptions():
102+
while True:
103+
try:
104+
raise ValueError('some error')
105+
except:
106+
traceback.print_exc()
107+
pass
108+
109+
time.sleep(2)
110+
111+
112+
t = threading.Thread(target=simulate_exceptions)
113+
t.start()
114+
115+
116+
# Simulate http server
117+
def simulate_http_traffic():
118+
while True:
119+
try:
120+
urlopen('http://localhost:5010', timeout=10)
121+
time.sleep(2)
122+
except:
123+
traceback.print_exc()
124+
pass
125+
126+
127+
t = threading.Thread(target=simulate_http_traffic)
128+
t.start()
129+
130+
131+
def cpu_work():
132+
for i in range(0, 1000000):
133+
text = "text1" + str(i)
134+
text = text + "text2"
135+
136+
137+
app = Flask(__name__)
138+
139+
@app.route('/')
140+
def hello_world():
141+
time.sleep(0.5)
142+
143+
cpu_work()
144+
145+
return 'Hello'
146+
147+

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.