Debian Codegraph @

docs/stats.rst

raw
1 :doc:`/index`
2
3 .. _stats_n_logging_label:
4
5 Stats and Logging
6 =================
7
8 .. _log_frequency_in_sec_label:
9
10 Log Frequency In Sec
11 --------------------
12
13 log_frequency_in_sec: Integer, default = 0
14 How often to log the progress. The default of 0 means logging progress is disabled.
15 If you set it to 20, it will log every 20 seconds. This is useful only when running DeepDiff
16 on massive objects that will take a while to run. If you are only dealing with small objects, keep it at 0 to disable progress logging.
17
18 For example we have run a diff on 2 nested objects that took 2 seconds to get the results. By passing the log_frequency_in_sec=1, we get the following in the logs:
19
20 >>> DeepDiff(t1, t2, log_frequency_in_sec=1)
21 INFO:deepdiff.diff:DeepDiff 1 seconds in progress. Pass #1634, Diff #8005
22 INFO:deepdiff.diff:DeepDiff 2 seconds in progress. Pass #3319, Diff #16148
23 INFO:deepdiff.diff:stats {'PASSES COUNT': 3960, 'DIFF COUNT': 19469, 'DISTANCE CACHE HIT COUNT': 11847, 'MAX PASS LIMIT REACHED': False, 'MAX DIFF LIMIT REACHED': False, 'DURATION SEC': 2}
24
25 .. note::
26 The default python logger will omit the info logs. You can either set the logging filter to include info logs or pass a different logger via :ref:`progress_logger_label`
27
28 >>> import logging
29 >>> logging.basicConfig(level=logging.INFO)
30
31
32 .. _progress_logger_label:
33
34 Progress Logger
35 ---------------
36
37 progress_logger: log function, default = logger.info
38 What logging function to use specifically for progress reporting. This function is only used when progress logging is enabled
39 by setting log_frequency_in_sec to anything above zero. The function that is passed as the progress_logger needs to be thread safe.
40
41
42 For example you can pass progress_logger=logger.warning to the example above and everything is logged as warning level:
43
44 >>> DeepDiff(t1, t2, log_frequency_in_sec=1, progress_logger=logger.warning)
45 WARNING:deepdiff.diff:DeepDiff 1 seconds in progress. Pass #1634, Diff #8005
46 WARNING:deepdiff.diff:DeepDiff 2 seconds in progress. Pass #3319, Diff #16148
47 WARNING:deepdiff.diff:stats {'PASSES COUNT': 3960, 'DIFF COUNT': 19469, 'DISTANCE CACHE HIT COUNT': 11847, 'MAX PASS LIMIT REACHED': False, 'MAX DIFF LIMIT REACHED': False, 'DURATION SEC': 2}
48
49
50 .. _get_stats_label:
51
52 Get Stats
53 ---------
54
55 You can run the get_stats() method on a diff object to get some stats on the object.
56 For example:
57
58 >>> from pprint import pprint
59 >>> from deepdiff import DeepDiff
60 >>>
61 >>> t1 = [
62 ... [1, 2, 3, 9], [9, 8, 5, 9]
63 ... ]
64 >>>
65 >>> t2 = [
66 ... [1, 2, 4, 10], [4, 2, 5]
67 ... ]
68 >>>
69 >>> diff = DeepDiff(t1, t2, ignore_order=True, cache_size=5000, cutoff_intersection_for_pairs=1)
70 >>> pprint(diff.get_stats())
71 {'DIFF COUNT': 37,
72 'DISTANCE CACHE HIT COUNT': 0,
73 'MAX DIFF LIMIT REACHED': False,
74 'MAX PASS LIMIT REACHED': False,
75 'PASSES COUNT': 7}
76
77
78 Back to :doc:`/index`