Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
f5a7f93a
Commit
f5a7f93a
authored
Sep 30, 1995
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more robust coding, adapted for mac
parent
897db0e0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
23 deletions
+23
-23
Lib/profile.py
Lib/profile.py
+19
-16
Lib/pstats.py
Lib/pstats.py
+4
-7
No files found.
Lib/profile.py
View file @
f5a7f93a
...
@@ -43,11 +43,10 @@ import marshal
...
@@ -43,11 +43,10 @@ import marshal
# Global variables
# Global variables
func_norm_dict
=
{}
func_norm_dict
=
{}
func_norm_counter
=
0
func_norm_counter
=
0
pid_string
=
`os.getpid()`
if
hasattr
(
os
,
'getpid'
):
pid_string
=
`os.getpid()`
else
:
# Optimized intermodule references
pid_string
=
''
ostimes
=
os
.
times
# Sample timer for use with
# Sample timer for use with
...
@@ -137,7 +136,7 @@ def help():
...
@@ -137,7 +136,7 @@ def help():
#**************************************************************************
#**************************************************************************
class
Profile
:
class
Profile
:
def
__init__
(
self
,
*
arg
):
def
__init__
(
self
,
timer
=
None
):
self
.
timings
=
{}
self
.
timings
=
{}
self
.
cur
=
None
self
.
cur
=
None
self
.
cmd
=
""
self
.
cmd
=
""
...
@@ -148,18 +147,22 @@ class Profile:
...
@@ -148,18 +147,22 @@ class Profile:
'exception'
:
self
.
trace_dispatch_exception
,
\
'exception'
:
self
.
trace_dispatch_exception
,
\
}
}
if
not
arg
:
if
not
timer
:
if
hasattr
(
os
,
'times'
):
self
.
timer
=
os
.
times
self
.
timer
=
os
.
times
self
.
dispatcher
=
self
.
trace_dispatch
self
.
dispatcher
=
self
.
trace_dispatch
else
:
else
:
self
.
timer
=
arg
[
0
]
self
.
timer
=
time
.
time
self
.
dispatcher
=
self
.
trace_dispatch_i
else
:
self
.
timer
=
timer
t
=
self
.
timer
()
# test out timer function
t
=
self
.
timer
()
# test out timer function
try
:
try
:
if
len
(
t
)
==
2
:
if
len
(
t
)
==
2
:
self
.
dispatcher
=
self
.
trace_dispatch
self
.
dispatcher
=
self
.
trace_dispatch
else
:
else
:
self
.
dispatcher
=
self
.
trace_dispatch_
r
self
.
dispatcher
=
self
.
trace_dispatch_
l
except
:
except
TypeError
:
self
.
dispatcher
=
self
.
trace_dispatch_i
self
.
dispatcher
=
self
.
trace_dispatch_i
self
.
t
=
self
.
get_time
()
self
.
t
=
self
.
get_time
()
self
.
simulate_call
(
'profiler'
)
self
.
simulate_call
(
'profiler'
)
...
@@ -373,9 +376,9 @@ class Profile:
...
@@ -373,9 +376,9 @@ class Profile:
return
func_norm_dict
[
func_name
]
return
func_norm_dict
[
func_name
]
if
type
(
func_name
)
==
type
(
""
):
if
type
(
func_name
)
==
type
(
""
):
long_name
=
string
.
split
(
func_name
)
long_name
=
string
.
split
(
func_name
)
file_name
=
long_name
[
6
][
1
:
-
2
]
file_name
=
long_name
[
-
3
][
1
:
-
2
]
func
=
long_name
[
2
]
func
=
long_name
[
2
]
lineno
=
long_name
[
8
][:
-
1
]
lineno
=
long_name
[
-
1
][:
-
1
]
if
'?'
==
func
:
# Until I find out how to may 'em...
if
'?'
==
func
:
# Until I find out how to may 'em...
file_name
=
'python'
file_name
=
'python'
func_norm_counter
=
func_norm_counter
+
1
func_norm_counter
=
func_norm_counter
+
1
...
@@ -398,7 +401,7 @@ class Profile:
...
@@ -398,7 +401,7 @@ class Profile:
def
runctx
(
self
,
cmd
,
globals
,
locals
):
def
runctx
(
self
,
cmd
,
globals
,
locals
):
self
.
set_cmd
(
cmd
)
self
.
set_cmd
(
cmd
)
sys
.
setprofile
(
self
.
trace_dispatch
)
sys
.
setprofile
(
self
.
dispatcher
)
try
:
try
:
exec
cmd
in
globals
,
locals
exec
cmd
in
globals
,
locals
finally
:
finally
:
...
@@ -407,7 +410,7 @@ class Profile:
...
@@ -407,7 +410,7 @@ class Profile:
# This method is more useful to profile a single function call.
# This method is more useful to profile a single function call.
def
runcall
(
self
,
func
,
*
args
):
def
runcall
(
self
,
func
,
*
args
):
self
.
set_cmd
(
`func`
)
self
.
set_cmd
(
`func`
)
sys
.
setprofile
(
self
.
trace_dispatch
)
sys
.
setprofile
(
self
.
dispatcher
)
try
:
try
:
apply
(
func
,
args
)
apply
(
func
,
args
)
finally
:
finally
:
...
...
Lib/pstats.py
View file @
f5a7f93a
...
@@ -116,13 +116,10 @@ class Stats:
...
@@ -116,13 +116,10 @@ class Stats:
except
:
# in case this is not unix
except
:
# in case this is not unix
pass
pass
self
.
files
=
[
arg
]
self
.
files
=
[
arg
]
elif
type
(
arg
)
==
type
(
self
):
elif
hasattr
(
arg
,
'create_stats'
):
try
:
arg
.
create_stats
()
arg
.
create_stats
()
self
.
stats
=
arg
.
stats
self
.
stats
=
arg
.
stats
arg
.
stats
=
{}
arg
.
stats
=
{}
except
:
pass
if
not
self
.
stats
:
if
not
self
.
stats
:
raise
TypeError
,
"Cannot create or construct a "
\
raise
TypeError
,
"Cannot create or construct a "
\
+
`self.__class__`
\
+
`self.__class__`
\
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment