forked from prometheus/client_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
40 lines (33 loc) · 1023 Bytes
/
Copy pathutils.py
File metadata and controls
40 lines (33 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import math
import sys
import psutil
INF = float("inf")
MINUS_INF = float("-inf")
NaN = float("NaN")
def floatToGoString(d):
d = float(d)
if d == INF:
return '+Inf'
elif d == MINUS_INF:
return '-Inf'
elif math.isnan(d):
return 'NaN'
else:
s = repr(d)
dot = s.find('.')
# Go switches to exponents sooner than Python.
# We only need to care about positive values for le/quantile.
if d > 0 and dot > 6:
mantissa = '{0}.{1}{2}'.format(s[0], s[1:dot], s[dot + 1:]).rstrip('0.')
return '{0}e+0{1}'.format(mantissa, dot - 1)
return s
def get_process_data(pid):
try:
process = psutil.Process(pid)
return process.__hash__()
except psutil.NoSuchProcess:
print('Calling process {0} is not running'.format(pid), file=sys.stderr)
raise
except psutil.AccessDenied:
print('Not enough permissions to access process {0}'.format(pid), file=sys.stderr)
raise