hotshot code:
import hotshot, hotshot.stats
prof = hotshot.Profile(os.path.join(Globals.options.profileDir, 'event.log'))_
prof.runcall(self.tmpFunc, share)
prof.close()
stats = hotshot.stats.load(os.path.join(Globals.options.profileDir, 'event.log'))_
stats.strip_dirs()
stats.sort_stats('cumulative')
stats.print_stats(125)
stats.print_callers()
plus:
def tmpFunc(self, share):
collection = share.get()
self.postEventByName ("AddToSidebarWithoutCopyingAndSelectFirst", {'items':[collection]})
------------------
After Ted's fix:
Ordered by: cumulative time
List reduced from 1362 to 125 due to restriction <125>
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 21.652 21.652 Main.py:403(tmpFunc)
1 0.000 0.000 15.703 15.703 Sharing.py:266(get)
1 0.000 0.000 15.699 15.699 Sharing.py:143(get)
1 0.000 0.000 15.699 15.699 Sharing.py:493(get)
1 0.001 0.001 15.674 15.674 Sharing.py:466(__conditionalGetItem)
1 0.000 0.000 15.673 15.673 Sharing.py:854(_getItem)
1 0.180 0.180 15.673 15.673 ICalendar.py:134(importProcess)
6/1 0.000 0.000 5.949 5.949 Block.py:121(postEventByName)
6/1 0.000 0.000 5.949 5.949 Block.py:93(post)
6/1 0.000 0.000 5.949 5.949 Block.py:537(dispatchEvent)
446 0.009 0.000 5.272 0.012 Kind.py:131(newItem)
446 0.006 0.000 5.253 0.012 Calendar.py:1252(__init__)
446 0.019 0.000 5.247 0.012 Calendar.py:282(__init__)
459 0.030 0.000 5.109 0.011 ICalendar.py:120(findUID)
518 0.022 0.000 4.566 0.009 items.py:160(__init__)
977 0.075 0.000 4.485 0.005 Item.py:28(__init__)
459 0.013 0.000 4.334 0.009 Query.py:261(__iter__)
518 0.008 0.000 3.933 0.008 schema.py:535(__init__)
4367/1410 0.060 0.000 3.783 0.003 Sets.py:163(_collectionChanged)
11441/10982 0.223 0.000 3.512 0.000 Monitors.py:84(invoke)
2 0.028 0.014 3.403 1.701 DBRepositoryView.py:242(commit)
1125 0.027 0.000 3.285 0.003 DBRepositoryView.py:349(_saveItem)
1125 0.090 0.000 3.200 0.003 DBItemIO.py:34(writeItem)
2019/1918 0.044 0.000 3.177 0.002 Values.py:429(_setValue)
3980/3801 0.062 0.000 3.118 0.001 Values.py:464(_setRef)
7243/6901 0.080 0.000 2.953 0.000 Item.py:295(setAttributeValue)
3920 0.021 0.000 2.901 0.001 Item.py:459(_kindChanged)
3920 0.059 0.000 2.880 0.001 Sets.py:628(sourceChanged)
1125 0.052 0.000 2.815 0.003 ItemIO.py:14(writeItem)
4367/3418 0.051 0.000 2.596 0.001 collections.py:79(collectionChanged)
306/1 0.001 0.000 2.569 2.569 Block.py:540(callMethod)
306/1 0.002 0.000 2.569 2.569 Block.py:568(callNamedMethod)
1 0.000 0.000 2.569 2.569 ControlBlocks.py:1025(onModifyContentsEvent)
6977/4044 0.079 0.000 2.566 0.001 Item.py:482(_collectionChanged)
305/2 0.003 0.000 2.547 1.273 Block.py:600(broadcast)
4367/3418 0.364 0.000 2.439 0.001 DBRepositoryView.py:366(mapChanges)
459 0.151 0.000 2.146 0.005 Query.py:722(execute)
459 0.005 0.000 2.133 0.005 Query.py:294(__resultsAreStale)
459 0.004 0.000 2.126 0.005 Query.py:172(_ensureQueryIsCurrent)
459 0.100 0.000 2.121 0.005 Query.py:83(_compile)
4562 0.274 0.000 2.044 0.000 collections.py:13(mapChangesCallable)
918 0.011 0.000 1.982 0.002 sets.py:425(__init__)
1377 0.007 0.000 1.971 0.001 sets.py:356(_update)
1121 0.010 0.000 1.967 0.002 DBItemIO.py:222(_values)
965 0.443 0.000 1.964 0.002 Query.py:571(execute)
1121 0.199 0.000 1.958 0.002 Values.py:206(_writeValues)
22927/22046 0.259 0.000 1.839 0.000 Item.py:1279(setDirty)
2268 0.049 0.000 1.736 0.001 DBRefs.py:261(_setRef)
1 0.046 0.046 1.712 1.712 vobject.py:707(readComponents)
2600 0.042 0.000 1.702 0.001 RefCollections.py:249(_setRef)
8456 0.151 0.000 1.688 0.000 DBContainer.py:382(loadRef)
2 0.000 0.000 1.648 0.824 CalendarBlocks.py:191(onSelectItemEvent)
2 0.000 0.000 1.648 0.824 CalendarBlocks.py:367(wxSynchronizeWidget)
4/2 0.000 0.000 1.645 0.823 ControlBlocks.py:1009(onSelectItemEvent)
2/1 0.008 0.004 1.645 1.645 grid.py:1989(SelectBlock)
8 0.019 0.002 1.632 0.204 CalendarCanvas.py:888(getItemsInRange)
4/2 0.000 0.000 1.629 0.815 ControlBlocks.py:598(OnRangeSelect)
16248/8656 0.140 0.000 1.571 0.000 Sets.py:96(_sourceContains)
2008/502 0.033 0.000 1.561 0.003 Sets.py:322(sourceChanged)
8313 0.310 0.000 1.550 0.000 DBItemIO.py:230(_value)
678 0.011 0.000 1.468 0.002 RefCollections.py:204(append)
676 0.008 0.000 1.446 0.002 Values.py:459(_addValue)
461 0.006 0.000 1.402 0.003 collections.py:174(add)
1868 0.007 0.000 1.325 0.001 collections.py:98(__iter__)
7988/2332 0.070 0.000 1.323 0.001 Sets.py:106(_iterSource)
1844 0.005 0.000 1.317 0.001 Sets.py:351(__iter__)
2705 0.031 0.000 1.307 0.000 Item.py:2305(_refList)
32846/32832 0.522 0.000 1.254 0.000 Item.py:537(getAttributeValue)
5532/1844 0.031 0.000 1.253 0.001 Sets.py:414(__iter__)
2705 0.033 0.000 1.178 0.000 DBRepositoryView.py:107(_createRefList)
22192 0.136 0.000 1.156 0.000 RefCollections.py:135(__contains__)
2677 0.051 0.000 1.144 0.000 DBRefs.py:219(__init__)
6138 0.031 0.000 1.120 0.000 Sets.py:241(__contains__)
115438 0.161 0.000 1.116 0.000 Query.py:45(run)
7964 0.067 0.000 1.079 0.000 RefCollections.py:394(_load)
1377/459 0.092 0.000 1.071 0.002 Query.py:303(__analyze)
2705 0.035 0.000 1.041 0.000 RefCollections.py:25(__init__)
22192 0.050 0.000 1.020 0.000 LinkedMap.py:262(__contains__)
5755 0.080 0.000 1.012 0.000 DBRefs.py:112(_loadRef)
21632/8758 0.149 0.000 0.999 0.000 DBItemIO.py:114(writeValue)
6488/6082 0.063 0.000 0.989 0.000 Calendar.py:1041(onValueChanged)
117410/115438 0.695 0.000 0.954 0.000 Query.py:60(_run)
918 0.008 0.000 0.953 0.001 Query.py:369(__init__)
918 0.115 0.000 0.945 0.001 Query.py:538(analyze)
2677 0.023 0.000 0.936 0.000 DBRefs.py:256(_setItem)
2701 0.058 0.000 0.900 0.000 DBRefs.py:57(_setItem)
1411/1407 0.019 0.000 0.897 0.001 Sets.py:272(sourceChanged)
3/2 0.000 0.000 0.886 0.443 Trunk.py:65(onSelectItemEvent)
3/2 0.000 0.000 0.885 0.442 Trunk.py:33(wxSynchronizeWidget)
459 0.009 0.000 0.876 0.002 QueryParser.py:294(parse)
3/2 0.000 0.000 0.876 0.438 Trunk.py:81(installTreeOfBlocks)
459 0.001 0.000 0.858 0.002 yappsrt.py:296(wrap_error_reporter)
1377/459 0.026 0.000 0.856 0.002 QueryParser.py:63(stmt)
68/1 0.006 0.000 0.837 0.837 Block.py:198(render)
459 0.011 0.000 0.837 0.002 QueryParser.py:95(union_stmt)
88/3 0.002 0.000 0.814 0.271 Block.py:438(synchronizeWidget)
459 0.020 0.000 0.810 0.002 QueryParser.py:83(stmt_list)
12801 0.776 0.000 0.806 0.000 DBContainer.py:123(openCursor)
2 0.084 0.042 0.765 0.382 CalendarCanvas.py:860(generateItemsInRange)
918 0.028 0.000 0.745 0.001 QueryParser.py:127(for_stmt)
99922/99714 0.726 0.000 0.740 0.000 Attribute.py:37(getAspect)
101 0.003 0.000 0.736 0.007 Calendar.py:720(_generateRule)
65 0.006 0.000 0.727 0.011 Calendar.py:604(getNextOccurrence)
977 0.039 0.000 0.694 0.001 Kind.py:578(getInitialValues)
12801 0.335 0.000 0.690 0.000 DBRepository.py:644(abortTransaction)
1121 0.013 0.000 0.687 0.001 DBItemIO.py:226(_references)
3694 0.078 0.000 0.686 0.000 LinkedMap.py:153(__setitem__)
3843 0.085 0.000 0.680 0.000 vobject.py:620(textLineToContentLine)
1121 0.104 0.000 0.674 0.001 Values.py:711(_writeValues)
1890 0.156 0.000 0.657 0.000 Types.py:990(writeValue)
918 0.012 0.000 0.646 0.001 QueryParser.py:158(and_or_expr)
459 0.015 0.000 0.640 0.001 Query.py:21(__init__)
22873/22865 0.151 0.000 0.628 0.000 Kind.py:329(getAttribute)
918 0.016 0.000 0.622 0.001 QueryParser.py:168(rel_expr)
23 0.001 0.000 0.607 0.026 Calendar.py:553(setRuleFromDateUtil)
12803 0.271 0.000 0.589 0.000 DBRepository.py:611(startTransaction)
2754/918 0.126 0.000 0.587 0.001 Query.py:421(compile_predicate)
1836 0.023 0.000 0.583 0.000 QueryParser.py:178(add_expr)
17726 0.161 0.000 0.556 0.000 Sets.py:593(__contains__)
24651 0.130 0.000 0.544 0.000 LinkedMap.py:383(__iter__)
1836 0.020 0.000 0.533 0.000 QueryParser.py:188(mul_expr)
3843 0.334 0.000 0.531 0.000 vobject.py:472(parseLine)
918 0.058 0.000 0.529 0.001 Query.py:438(infix_op)
111802 0.521 0.000 0.521 0.000 :0(?)
53/43 0.002 0.000 0.520 0.012 Calendar.py:586(_createOccurrence)
Before Ted's fix:
Ordered by: cumulative time
List reduced from 1366 to 125 due to restriction <125>
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 90.299 90.299 Main.py:410(tmpFunc)
1 0.000 0.000 81.431 81.431 Sharing.py:266(get)
1 0.000 0.000 81.426 81.426 Sharing.py:143(get)
1 0.000 0.000 81.426 81.426 Sharing.py:493(get)
1 0.000 0.000 81.403 81.403 Sharing.py:466(__conditionalGetItem)
1 0.000 0.000 81.401 81.401 Sharing.py:854(_getItem)
1 0.168 0.168 81.401 81.401 ICalendar.py:134(importProcess)
4366/1410 0.060 0.000 74.122 0.053 Sets.py:163(_collectionChanged)
4366/3418 0.225 0.000 72.960 0.021 collections.py:79(collectionChanged)
4366/3418 0.319 0.000 72.615 0.021 DBRepositoryView.py:366(mapChanges)
4559 1.801 0.000 72.262 0.016 collections.py:13(mapChangesCallable)
1774994 2.926 0.000 70.056 0.000 collections.py:95(__iter__)
1774630 4.580 0.000 66.092 0.000 Sets.py:600(__iter__)
1888104 2.852 0.000 62.277 0.000 Query.py:45(run)
3656676/1888104 39.028 0.000 59.419 0.000 Query.py:60(_run)
11441/10982 0.214 0.000 48.487 0.004 Monitors.py:84(invoke)
446 0.009 0.000 45.136 0.101 Kind.py:131(newItem)
446 0.006 0.000 45.117 0.101 Calendar.py:1252(__init__)
446 0.018 0.000 45.111 0.101 Calendar.py:282(__init__)
518 0.019 0.000 44.846 0.087 items.py:160(__init__)
977 0.063 0.000 44.730 0.046 Item.py:28(__init__)
518 0.008 0.000 44.238 0.085 schema.py:535(__init__)
3920 0.021 0.000 43.261 0.011 Item.py:459(_kindChanged)
3920 0.058 0.000 43.240 0.011 Sets.py:625(sourceChanged)
6976/4043 0.078 0.000 37.495 0.009 Item.py:482(_collectionChanged)
2019/1918 0.041 0.000 26.978 0.014 Values.py:429(_setValue)
3980/3801 0.058 0.000 26.921 0.007 Values.py:464(_setRef)
1410/1406 0.018 0.000 26.224 0.019 Sets.py:269(sourceChanged)
2268 0.047 0.000 23.840 0.011 DBRefs.py:261(_setRef)
2600 0.039 0.000 23.806 0.009 RefCollections.py:249(_setRef)
678 0.011 0.000 23.573 0.035 RefCollections.py:204(append)
676 0.007 0.000 23.550 0.035 Values.py:459(_addValue)
461 0.005 0.000 23.511 0.051 collections.py:171(add)
67933 1.331 0.000 14.807 0.000 DBRepositoryView.py:79(queryItems)
67933 1.085 0.000 13.361 0.000 DBRepository.py:573(queryItems)
67933 1.444 0.000 12.275 0.000 DBContainer.py:976(kindQuery)
1506/502 0.024 0.000 11.166 0.022 Sets.py:319(sourceChanged)
502 0.011 0.000 10.448 0.021 Sets.py:471(sourceChanged)
6/1 0.000 0.000 8.869 8.869 Block.py:120(postEventByName)
6/1 0.000 0.000 8.868 8.868 Block.py:92(post)
6/1 0.001 0.000 8.868 8.868 Block.py:536(dispatchEvent)
7243/6901 0.073 0.000 7.090 0.001 Item.py:295(setAttributeValue)
22929/22048 0.251 0.000 6.417 0.000 Item.py:1279(setDirty)
306/1 0.002 0.000 5.647 5.647 Block.py:539(callMethod)
306/1 0.002 0.000 5.647 5.647 Block.py:567(callNamedMethod)
1 0.000 0.000 5.647 5.647 ControlBlocks.py:1025(onModifyContentsEvent)
305/2 0.003 0.000 5.485 2.743 Block.py:599(broadcast)
56 0.000 0.000 4.929 0.088 Item.py:475(_filteredItemChanged)
56 0.001 0.000 4.929 0.088 Sets.py:717(itemChanged)
4/2 0.000 0.000 4.784 2.392 ControlBlocks.py:1009(onSelectItemEvent)
2/1 0.006 0.003 4.784 4.784 grid.py:1989(SelectBlock)
4/2 0.000 0.000 4.768 2.384 ControlBlocks.py:598(OnRangeSelect)
101 0.002 0.000 4.679 0.046 Calendar.py:720(_generateRule)
65 0.005 0.000 4.671 0.072 Calendar.py:604(getNextOccurrence)
459 0.026 0.000 4.544 0.010 ICalendar.py:120(findUID)
95225/95211 1.737 0.000 4.516 0.000 Item.py:537(getAttributeValue)
53/43 0.002 0.000 4.482 0.104 Calendar.py:586(_createOccurrence)
96454 2.011 0.000 4.064 0.000 DBRepository.py:611(startTransaction)
3/2 0.000 0.000 4.064 2.032 Trunk.py:65(onSelectItemEvent)
3/2 0.000 0.000 4.062 2.031 Trunk.py:33(wxSynchronizeWidget)
3/2 0.000 0.000 4.054 2.027 Trunk.py:81(installTreeOfBlocks)
68/1 0.006 0.000 4.020 4.020 Block.py:197(render)
88/3 0.002 0.000 4.002 1.334 Block.py:437(synchronizeWidget)
6488/6082 0.060 0.000 3.985 0.001 Calendar.py:1041(onValueChanged)
96452 1.588 0.000 3.864 0.000 DBRepository.py:644(abortTransaction)
459 0.013 0.000 3.856 0.008 Query.py:261(__iter__)
1 0.000 0.000 3.271 3.271 Detail.py:53(onSetContentsEvent)
2 0.027 0.013 3.243 1.622 DBRepositoryView.py:242(commit)
51 0.001 0.000 3.220 0.063 RefCollections.py:218(clear)
24 0.000 0.000 3.217 0.134 Values.py:542(_removeRef)
13 0.000 0.000 3.216 0.247 Values.py:531(_removeValue)
10 0.000 0.000 3.216 0.322 RefCollections.py:389(_removeRef)
2 0.000 0.000 3.215 1.608 RefCollections.py:371(__delitem__)
1 0.000 0.000 3.215 3.215 collections.py:174(clear)
96452 2.936 0.000 3.151 0.000 DBContainer.py:123(openCursor)
1125 0.026 0.000 3.129 0.003 DBRepositoryView.py:349(_saveItem)
1125 0.080 0.000 3.048 0.003 DBItemIO.py:34(writeItem)
472/459 0.006 0.000 2.841 0.006 Calendar.py:739(_getFirstGeneratedOccurrence)
99638 0.651 0.000 2.766 0.000 LinkedMap.py:383(__iter__)
23 0.001 0.000 2.736 0.119 Calendar.py:553(setRuleFromDateUtil)
1125 0.052 0.000 2.693 0.002 ItemIO.py:14(writeItem)
459 0.139 0.000 2.075 0.005 Query.py:722(execute)
720 0.006 0.000 1.963 0.003 Calendar.py:766(getOccurrencesBetween)
16779 0.251 0.000 1.940 0.000 DBRepository.py:578(fn)
918 0.010 0.000 1.924 0.002 sets.py:425(__init__)
1377 0.007 0.000 1.914 0.001 sets.py:356(_update)
965 0.434 0.000 1.907 0.002 Query.py:571(execute)
1121 0.009 0.000 1.893 0.002 DBItemIO.py:222(_values)
1121 0.192 0.000 1.884 0.002 Values.py:206(_writeValues)
13 0.001 0.000 1.873 0.144 Calendar.py:807(getRecurrenceID)
459 0.005 0.000 1.729 0.004 Query.py:294(__resultsAreStale)
459 0.004 0.000 1.722 0.004 Query.py:172(_ensureQueryIsCurrent)
459 0.083 0.000 1.717 0.004 Query.py:83(_compile)
1 0.046 0.046 1.670 1.670 vobject.py:707(readComponents)
79675 0.551 0.000 1.494 0.000 ThreadSemaphore.py:31(release)
8313 0.299 0.000 1.487 0.000 DBItemIO.py:230(_value)
16779 0.072 0.000 1.437 0.000 DBContainer.py:968(getItemVersion)
2 0.000 0.000 1.408 0.704 CalendarBlocks.py:190(onSelectItemEvent)
2 0.000 0.000 1.408 0.704 CalendarBlocks.py:363(wxSynchronizeWidget)
16246/8654 0.133 0.000 1.404 0.000 Sets.py:96(_sourceContains)
8 0.016 0.002 1.392 0.174 CalendarCanvas.py:886(getItemsInRange)
179113/178887 1.355 0.000 1.367 0.000 Attribute.py:37(getAspect)
16779 0.216 0.000 1.365 0.000 DBContainer.py:869(_findItem)
73366 0.286 0.000 1.149 0.000 RefCollections.py:241(__getitem__)
8463 0.145 0.000 1.112 0.000 DBContainer.py:382(loadRef)
8448/2792 0.016 0.000 1.110 0.000 Sets.py:106(_iterSource)
1844 0.010 0.000 1.101 0.001 Sets.py:501(__iter__)
5532/1844 0.031 0.000 1.087 0.001 Sets.py:411(__iter__)
25 0.001 0.000 1.072 0.043 Calendar.py:985(changeThis)
96456 0.825 0.000 1.056 0.000 ThreadSemaphore.py:18(acquire)
1377/459 0.087 0.000 1.017 0.002 Query.py:303(__analyze)
62499/62491 0.354 0.000 1.002 0.000 Kind.py:329(getAttribute)
6136 0.031 0.000 0.975 0.000 Sets.py:238(__contains__)
100555 0.775 0.000 0.974 0.000 LinkedMap.py:392(iterkeys)
21632/8758 0.142 0.000 0.952 0.000 DBItemIO.py:114(writeValue)
12922 0.094 0.000 0.937 0.000 RefCollections.py:135(__contains__)
7964 0.060 0.000 0.923 0.000 RefCollections.py:394(_load)
918 0.008 0.000 0.907 0.001 Query.py:369(__init__)
918 0.128 0.000 0.898 0.001 Query.py:538(analyze)
94305 0.792 0.000 0.889 0.000 Values.py:485(_getRef)
79675 0.312 0.000 0.867 0.000 threading.py:289(release)
372963 0.867 0.000 0.867 0.000 DBRepository.py:662(_getTxn)
73368 0.432 0.000 0.863 0.000 RefCollections.py:245(_getRef)
5755 0.079 0.000 0.863 0.000 DBRefs.py:112(_loadRef)
12922 0.027 0.000 0.844 0.000 LinkedMap.py:262(__contains__)
After implementing a UID lookup mechanism (instead of a query):
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 15.530 15.530 Main.py:403(tmpFunc)
1 0.000 0.000 10.457 10.457 Sharing.py:266(get)
1 0.000 0.000 10.449 10.449 Sharing.py:143(get)
1 0.000 0.000 10.448 10.448 Sharing.py:493(get)
1 0.000 0.000 10.337 10.337 Sharing.py:466(__conditionalGetItem)
1 0.000 0.000 10.336 10.336 Sharing.py:854(_getItem)
1 0.185 0.185 10.336 10.336 ICalendar.py:143(importProcess)
6/1 0.000 0.000 5.073 5.073 Block.py:121(postEventByName)
6/1 0.000 0.000 5.073 5.073 Block.py:93(post)
6/1 0.000 0.000 5.073 5.073 Block.py:537(dispatchEvent)
446 0.009 0.000 4.346 0.010 Kind.py:131(newItem)
446 0.006 0.000 4.328 0.010 Calendar.py:1259(__init__)
446 0.019 0.000 4.322 0.010 Calendar.py:289(__init__)
518 0.019 0.000 4.055 0.008 items.py:160(__init__)
4366/1410 0.059 0.000 3.470 0.002 Sets.py:163(_collectionChanged)
518 0.007 0.000 3.441 0.007 schema.py:535(__init__)
518 0.041 0.000 3.432 0.007 Item.py:28(__init__)
2495/2371 0.054 0.000 3.251 0.001 Values.py:429(_setValue)
4932/4707 0.070 0.000 3.178 0.001 Values.py:464(_setRef)
2 0.017 0.008 2.941 1.471 DBRepositoryView.py:242(commit)
10098/9639 0.205 0.000 2.866 0.000 Monitors.py:84(invoke)
662 0.016 0.000 2.768 0.004 DBRepositoryView.py:349(_saveItem)
662 0.049 0.000 2.719 0.004 DBItemIO.py:34(writeItem)
7439/4506 0.077 0.000 2.701 0.001 Item.py:482(_collectionChanged)
662 0.030 0.000 2.501 0.004 ItemIO.py:14(writeItem)
5909/5541 0.065 0.000 2.429 0.000 Item.py:295(setAttributeValue)
2084 0.011 0.000 2.355 0.001 Item.py:459(_kindChanged)
4366/3418 0.049 0.000 2.347 0.001 collections.py:79(collectionChanged)