File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 18
18
from functools import partial
19
19
from operator import attrgetter
20
20
import random
21
+ import signal
21
22
from time import sleep
22
23
from datetime import datetime
23
24
61
62
from ground_truth_tools import k_fold_cross_validation
62
63
from ground_truth_tools import split_training_test_set
63
64
from gtp_scores import GTPScores
65
+ from memory_usage import log_mem_usage
64
66
from serialization import find_last_result
65
67
from serialization import find_run_result
66
68
from serialization import format_graph_pattern
80
82
81
83
82
84
logger .info ('init gp_learner' )
85
+ signal .signal (signal .SIGUSR1 , log_mem_usage )
83
86
84
87
85
88
class GPLearnerException (Exception ):
Original file line number Diff line number Diff line change
1
+ # -*- coding: utf-8 -*-
2
+ from __future__ import absolute_import
3
+ from __future__ import division
4
+ from __future__ import print_function
5
+
6
+
7
+ import gc
8
+ import random
9
+ from six .moves import StringIO
10
+
11
+ import objgraph
12
+
13
+ from logging_config import filename
14
+
15
+ _count = 0
16
+
17
+
18
+ def log_mem_usage (signum , frame , fname = None ):
19
+ global _count
20
+ _count += 1
21
+ gc .collect ()
22
+ if not fname :
23
+ fname = filename + '_memory_%02d.log' % _count
24
+ with open (fname , 'wb' ) as f :
25
+ f .write ('gc.garbage: %d\n \n ' % len (gc .garbage ))
26
+ objgraph .show_most_common_types (limit = 50 , file = f )
27
+ f .write ('\n \n ' )
28
+ buf = StringIO ()
29
+ objgraph .show_growth (limit = 50 , file = buf )
30
+ buf = buf .getvalue ()
31
+ f .write (buf )
32
+ if _count < 2 :
33
+ return
34
+ for tn , l in enumerate (buf .splitlines ()[:10 ]):
35
+ l = l .strip ()
36
+ if not l :
37
+ continue
38
+ type_ = l .split ()[0 ]
39
+ objects = objgraph .by_type (type_ )
40
+ objects = random .sample (objects , min (50 , len (objects )))
41
+ objgraph .show_chain (
42
+ objgraph .find_backref_chain (
43
+ objects [0 ],
44
+ objgraph .is_proper_module ),
45
+ filename = fname [:- 4 ] + '_type_%02d_backref.png' % tn
46
+ )
47
+ objgraph .show_backrefs (
48
+ objects ,
49
+ max_depth = 5 ,
50
+ extra_info = lambda x : hex (id (x )),
51
+ filename = fname [:- 4 ] + '_type_%02d_backrefs.png' % tn ,
52
+ )
You can’t perform that action at this time.
0 commit comments