How to profile CPU used by method/function in Swift [duplicate] - ios

This question already has answers here:
How to measure total time spent in a function?
(5 answers)
Closed 6 years ago.
The app I'm developing does some intensive processing and I'd like to understand where the time is being used. The Time Profiler in Instruments shows the tree of calls but I can't see how to get the information I need.
My app has a structure like this:
A
B
B1
E1
B2
B3
E1
C
C1
C2
E1
C3
D
D1
D2
E1
Now, method E1 is called from a number of places and I'd like to see how much CPU it is using. However, from the profiler output I can only see the time taken in E1 down each branch of the tree. Is there any way of getting a report by method/function regardless of where it is called from? e.g. Sum the total time spent in E1?
Thanks,
Julian

The link posted by naglerrr is the answer - How to measure total time spent in a function?
You need to find the function in the profiler tree, right click and select "Focus on Calls Made By". Check the linked answer for more information.

Related

Calculating sleep duration (before and after midnight) in Google Sheets

I am trying to calculate the total number of minutes spent in bed overnight by inputting the time entered bed (e.g. 9pm) and time exited bed (e.g. 6am).
Using those example inputs, the answer should be 9hours, or 540minutes (9*60).
Instead, my formula counts backwards, grabbing the duration from 6am to 9pm which is 15hours, or 900min.
Here is what I have so far. The formula on F2 works just fine until you cross midnight in C2. For example, if B2 is 9pm and C2 is 11pm, F2 is 120minutes. Once you change C2 to 12pm (0:00 in 24hour notation), the calculation flips and becomes 540minutes.
I'm thinking since the cells like to count backwards, I could maybe take 24 hours and subtract it by the value in F2, effectively getting back the other portion?
I stumbled into a weird pseudo-fix: if B2 is 21:00 (9pm) and I put 30:00 into C2, C2 displays 6:00 and F2 counts properly. Here is what that looks like. I am hoping to find a better solution than this-- the UX i'm looking to achieve is just putting my bed time and my wake time and the cells do the rest.
Thanks in advance!!
Drop the abs.
C2-B2
already assumes next day when C2<B2 as shown here:
The reason it works is that Google Sheet treats those as (duration of) time. And when displaying time, the "minus amount" is converted to a positive time value that represents a time of the previous day, as if modulus 24 hours. For example, 7:00 (hour) minus 21:00 (hour) gives -14:00 (hour) and it will be displayed as 24:00 (hour) - 14:00 (hour) = 10:00 (hour). Thus it is equivalent to the number you are looking for. However, modulus 24 hours effect is only for display. The minus sign is still inherent to the resultant value.
In order to display minutes or do other calculations with the result, you can wrap it with timevalue(). With that, the underlying value will be converted as described above.
To then display minutes, you can format the cell to display Elapsed minutes using the steps shown below.
And you will see minutes in the cell as shown below.
Your question implies that you may desire to do calculations on the result.
If that is that case, it helps to know that the output of timevalue is time duration in (fractions of) days without any inherent formatting. If not, you may skip the followings.
For example, in the preceding image, if you put =C1*2 in D1, with automatic formatting, D1 will inherit the format of C1, which was Elapsed minutes. You will thus see 1440. However, the actual underlying value is 1 because the real meaning of the data is half a day times 2. And you can confirm that by setting the format of D1 as numbers.
Thus, if you are only doing calculations with outputs of timevalue, you are fine without worrying about the above. However, if you mix the result of timevalue with other types of data, the fraction of day meaning is what will be used in your calculations.

google-sheets-if-and-formula-between-two-times return result or return original result

Spreadsheet
I need to show the result of altering energy use during peak price times on the cost of energy over the year. To do this I want to change the amount of energy being used, value in G6 to be 8 if the time at B6 is between the morning or afternoon peak pricing times, or keep the value in C6 if B6 is not within the peak pricing times.
Morning Peak Start 06:30:00 Finish 07:45:00
Afternoon Peak Start 16:30:00 Finish 23:45:00
I have attempted to modify the code found here:
excel-if-and-formula-between-two-times
=IF(and(B6>$N$3,B6<$O$3),"8",IF(AND(B6>=$P$3,B6<$Q$3),8,C6))
however, this does not return "8" in the desired time ranges.
You can see in the Google Spreadsheet that I have experimented with code in N6,N7 and N8.
I appreciate your assistance.
Please examine your cells N3 and P3. They have an extra 05/01/1900 in them. Remove that, leaving the time part, and it should work fine.
The problem is that you were doing a comparison on a time string, e.g. 06:45:00 and a full date string, e.g. 05/01/1900 06:30:00, which results in a faulty comparison.
The values you analyse in a comparison must have the same data type and must have a consistent data within this data type. In your case both B6, N3,O3,P3 and Q3 are set to the data type Time. However, you are using the format Date Time in all the cells but B3. As you want to compare dates with time you must set all of these cells with the data type Date Time.
To do so, in your Spreadsheet's menu bar, after selecting all these cells select Format->Number->Date Time and add the right date to B6.

Google Sheets IF AND OR Logic

I am making a scoring system on Google sheets and I am struggling with the logic I need for the final step.
This question might be related, but I can't seem to apply the logic.
There are a number of chemicals tested and for each an amount detected (AD) si given, and each has a benchmark amount allowed (AL). From AL and AD we calculate AD/AL= %AL.
The Total Score (TS) is calculated based on an additive and weighted formula that takes into consideration the individual %ALs, but I won't go into that formula.
The final step is for me to "calculate" the Display Score (DS), which has some rules to it, and this is where I need the logic. The rules are as follows:
If any of the %Als are over 100 (this is will make TS>100 too) and DS should show "100+"
If none of the %ALs are over 99, (TS may be above or below 100) then DS can NOT be over 99, so it should show TS, maxing out at 99.
I want to do this within the sheet itself. I think the correct tool is logic operators IF, AND, OR.
I have made many attempts, these are some: (I am replacing cell references with the acronyms I used above)
=IF(TS>100,"100+",TS)
=IF(OR(AND(MAX(RANGE_OF_%ALS)<100,TS>99),(AND(MAX(RANGE_OF_%ALS)>100,TS>100)),99,"100+"))
I have also tried to think about how I would solve this in Python (just to explore it, I don't want to use Python for the solution). This was my attempt:
if Max%AL<100:
if TS<100:
print(TS)
else:
print("99")
else:
if TS>100:
print("100+")
Those are my attempts at thinking through the problem. I would appreciate some help.
This is a link to a copy of my sheet: https://docs.google.com/spreadsheets/d/1ZBnaFUepVdduEE2GBdxf5iEsfDsFNPIYhrhblHDHEYs/edit?usp=sharing
Please try:
=if(max(RANGE_OF_%ALS)>1,"100+",if(max(RANGE_OF_%ALS)<=0.99,MIN(TS,0.99),"?"))

time trigger + multiple events in Pubsub

I am ingesting 2 different datasets on GCS. Lets say I write a event e1 and event e2 respectively in pubsub which happens at a different times.
I want to start a job and 9 AM and check when both events e1 and e2 have happened for that particular day (After 9 AM) then i kick a process to generate another dataset from these 2 datasets.
Is Cloud composer right to build this kind of requirement. If yes, then please provide some guidance how it can be done
Cloud Composer (and Airflow) should be right for this use case.
You can create a DAG with a daily schedule_interval that starts at 9 am. Use a PubsubSensor per event (s1 and s2). Assuming the process to generate another dataset is an operator, you could then ensure that generate_dataset occurs by setting dependencies:
s1 >> generate_dataset
s2 >> generate_dataset

Excel finding the code for a cell to be equal or more than another cell to give 1- 5 points

Google Spreadsheet on google drive. I have just made a survey on google drive for people to fill in their football predictions for fun! I can put all of the publics predictions into an excel document in one click but I want the public to earn points when they predict the right result. For example if a friend of mine predicted Arsenal 2 - 1 Liverpool and the result is Arsenal 1 - 0 Liverpool they should earn 1 point for predicting the right winner and if the prediction was equal to Arsenal 2 - 1 Liverpool, the prediction should earn 3 points.
I am struggling with the code for it but here is the closest I have got:
COUNTIF(F5, ʺ>=ʺ & E5)
The code above does not work and I cannot figure it out. Any help will be greatly appreciated as soon as possible. Thanks a lot.
I am sorry that this is not an answer, but I am unable to comment without higher reputation. It would be helpful to have access to a copy or example of what you have, as your cell references mean very little without. Then we can see exactly what you have tried.
EDIT::
Without knowing how your sheet works or is laid out, it is difficult, however I've put this together for you on Google Sheets here
https://docs.google.com/spreadsheets/d/13Ejaddmj2d8cysxdZE_Inro65KDFgzeJW7FqPWwaCpE/edit?usp=sharing
It's a very clunky set of nested IF statements but it does work. I'm sure there is a neater way of doing it.
In case you can't view it, here is the formula
=IF(A2>B2, IF(D2>E2, IF(A2=D2, IF(B2=E2,"3","1"),"1"),"0"), IF(A2=B2, IF(D2=E2, IF(A2=D2, IF(B2=E2,"3","1"),"1"),"0"), IF(D2<E2, IF(A2=D2, IF(B2=E2,"3","1"),"1"),"0")))
In this case, A2 is Arsenal's score, B2 is Liverpool's score, D2 is Fred's Arsenal score prediction and E2 is his Liverpool prediction. I placed the above formula in cell F2 to give Fred's points.
The above code first checks to see
if Arsenal beat Liverpool, if true it then checks
if Fred predicted that Arsenal would beat Liverpool. If true, then it checks
if Fred got Arsenal's score correct. If true, it checks
if Fred got Liverpool's score correct. If that's true,
then Fred got everything right and gets 3 points (and a cookie =]).
If Fred gets the winner right but not the scores, he gets 1 point. Otherwise he gets 0.
This formula also checks to see if Liverpool beat Arsenal and runs the same checks against Fred's prediction, then to see if the teams drew and to see if Fred predicted a draw or not. If he predicts a draw and the correct scores he gets 3 points, otherwise he gets 1 for getting the draw correct.
I believe that this is what you are looking for .. attached are a formula and result view of my answer ;)
formulas
results

Resources