ExSetTimerResolution does not work - windows

I have got Windows XP installed on my computer.
I want my DPC routine to be called every 10 ms.
That is why I wrote this code:
ASSERT( KeGetCurrentIrql() <= APC_LEVEL );
KeRaiseIrql( APC_LEVEL, &level );
resolution = ExSetTimerResolution( 100000, TRUE );
KdPrint((DRIVERNAME " - RESOLUTION = %d\n", resolution));
KeLowerIrql( level );
KeSetTimerEx( &pExt->timer, duetime, 10, &pExt->dpc );
DebugView shows me that return value (RESOLUTION) equals 156250.
As a result my DPC routine is called every 15.5 ms
What am I doing wrong?

Out of curiosity I tried ExSetTimerResolution with different values.
Here is what I got:
10000 -> 9766
50000 -> 39063
75000 -> 39063
90000 -> 156250
Left column contains values that I used as DesiredTime parameter.
Right column contains return values.
As you can see, it looks like Windows cannot change global timer resolution to any desired number.

Related

Dynamic number system in Qlik Sense

My data consists of large numbers, I have a column say - 'amount', while using it in charts(sum of amount in Y axis) it shows something like 1.4G, I want to show them as if is billion then e.g. - 2.8B, or in millions then 80M or if it's in thousands (14,000) then simply- 14k.
I have used - if(sum(amount)/1000000000 > 1, Num(sum(amount)/1000000000, '#,###B'), Num(sum(amount)/1000000, '#,###M')) but it does not show the M or B at the end of the figure and also How to include thousand in the same code.
EDIT: Updated to include the dual() function.
This worked for me:
=dual(
if(sum(amount) < 1, Num(sum(amount), '#,##0.00'),
if(sum(amount) < 1000, Num(sum(amount), '#,##0'),
if(sum(amount) < 1000000, Num(sum(amount)/1000, '#,##0k'),
if(sum(amount) < 1000000000, Num(sum(amount)/1000000, '#,##0M'),
Num(sum(amount)/1000000000, '#,##0B')
))))
, sum(amount)
)
Here are some example outputs using this script to format it:
=sum(amount)
Formatted
2,526,163,764
3B
79,342,364
79M
5,589,255
5M
947,470
947k
583
583
0.6434
0.64
To get more decimals for any of those, like 2.53B instead of 3B, you can format them like '#,##0.00B' by adding more zeroes at the end.
Also make sure that the Number Formatting property is set to Auto or Measure expression.

How to automatically check time?

Is it possible to automatically check time then execute certain codes?
timer = os.date('%H:%M:%S', os.time() - 13 * 60 * 60 )
if timer == "18:04:40" then
print("hello")
end
I am trying to print hello on "18:04:40" everyday (os.date's time) without setting up a timer (which counts how much time past since the program's initiation) as I can't run the program 24 hours non-stop...
Thanks for reading.
This may not be the best solution but, when using a library like love2d for example you could run something like this:
function love.update(dt)
timer = os.date('%H:%M:%S', os.time() - 13 * 60 * 60 )
if timer >= value then
--stuff here
end
end
Or if you wanna make it so you have a whole number something like
tick = 0
function love.update(dt)
tick = tick + dt
if tick > 1 then
timer = os.date('%H:%M:%S', os.time() - 13 * 60 * 60 )
if timer >= value then
--stuff here
end
end
end
Lua has to check the time in some way.
Without a loop that can be realized with debug.sethook().
Example with Lua 5.1 typed in an interactive Lua (lua -i)...
> print(_VERSION)
Lua 5.1
> debug.sethook() -- This clears a defined hook
> -- Next set up a hook function that fires on 'line' events
> debug.sethook(function() local hour, min, sec = 23, 59, 59 print(os.date('%H:%M:%S', os.time({year = 2021, month = 12, day = 11, hour = hour, min = min, sec = sec}))) end, 'l')
-- just hit return/enter or do other things
23:59:59
5.9 - The Debug Library
https://www.lua.org/manual/5.1/manual.html#5.9

Understanding Spring Boot actuator `http.server.requests` metrics MAX attribute

can someone explain what does the MAX statistic refers to in the below response. I don't see it documented anywhere.
localhost:8081/actuator/metrics/http.server.requests?tag=uri:/myControllerMethod
Response:
{
"name":"http.server.requests",
"description":null,
"baseUnit":"milliseconds",
"measurements":[
{
"statistic":"COUNT",
"value":13
},
{
"statistic":"TOTAL_TIME",
"value":57.430899
},
{
"statistic":"MAX",
"value":0
}
],
"availableTags":[
{
"tag":"exception",
"values":[
"None"
]
},
{
"tag":"method",
"values":[
"GET"
]
},
{
"tag":"outcome",
"values":[
"SUCCESS"
]
},
{
"tag":"status",
"values":[
"200"
]
},
{
"tag":"commonTag",
"values":[
"somePrefix"
]
}
]
}
You can see the individual metrics by using ?tag=url:{endpoint_tag} as defined in the response of the root /actuator/metrics/http.server.requests call. The details of the measurements values are;
COUNT: Rate per second for calls.
TOTAL_TIME: The sum of the times recorded. Reported in the monitoring system's base unit of time
MAX: The maximum amount recorded. When this represents a time, it is reported in the monitoring system's base unit of time.
As given here, also here.
The discrepancies you are seeing is due to the presence of a timer. Meaning after some time currently defined MAX value for any tagged metric can be reset back to 0. Can you add some new calls to /myControllerMethod then immediately do a call to /actuator/metrics/http.server.requests to see a non-zero MAX value for given tag?
This is due to the idea behind getting MAX metric for each smaller period. When you are seeing these metrics, you will be able to get an array of MAX values rather than a single value for a long period of time.
You can get to see this in action within Micrometer source code. There is a rotate() method focused on resetting the MAX value to create above described behaviour.
You can see this is called for every poll() call, which is triggered every some period for metric gathering.
What does MAX represent
MAX represents the maximum time taken to execute endpoint.
Analysis for /user/asset/getAllAssets
COUNT TOTAL_TIME MAX
5 115 17
6 122 17 (Execution Time = 122 - 115 = 17)
7 131 17 (Execution Time = 131 - 122 = 17)
8 187 56 (Execution Time = 187 - 131 = 56)
9 204 56 From Now MAX will be 56 (Execution Time = 204 - 187 = 17)
Will MAX be 0 if we have less number of request (or 1 request) to the particular endpoint?
No number of request for particular endPoint does not affect the MAX (see Image from Spring Boot Admin)
When MAX will be 0
There is Timer which set the value 0. When the endpoint is not being called or executed for sometime Timer sets MAX to 0. Here approximate timer value is 2 minutes (120 seconds)
DistributionStatisticConfig has .expiry(Duration.ofMinutes(2)).
which sets some measurements to 0 if there is no request has been made in between expiry time or rotate time.
How I have determined the timer value?
For that, I have taken 6 samples (executed the same endpoint for 6 times). For that, I have determined the time difference between the time of calling the endpoint - time for when MAX set back to zero
More Details
UPDATE
Document has been updated.
NOTE:
Max for basic DistributionSummary implementations such as CumulativeDistributionSummary, StepDistributionSummary is a time
window max (TimeWindowMax).
It means that its value is the maximum value during a time window.
If the time window ends, it'll be reset to 0 and a new time window starts again.
Time window size will be the step size of the meter registry unless expiry in DistributionStatisticConfig is set to other value
explicitly.

Convert TMediaPlayer->Duration to min:sec (FMX)

I'm working with the TMediaPlayer1 control in an FMX app using C++ Builder 10.2 Version 25.0.29899.2631. The code below runs fine in Win32 and gives the expected result after loading an mp3 file that is 35 minutes, 16 seconds long.
When i run this same code targeting iOS i get the following error:
[bcciosarm64 Error] Unit1.cpp(337): use of overloaded operator '/' is ambiguous (with operand types 'Fmx::Media::TMediaTime' and 'int')
Here is my code that takes the TMediaPlayer1->Duration and converts it to min:sec,
UnicodeString S = System::Ioutils::TPath::Combine(System::Ioutils::TPath::GetDocumentsPath(),"43506.mp3");
if (FileExists(S)) {
MediaPlayer1->FileName = S;
int sec = MediaPlayer1->Duration / 10000000; // <-- this is problem line
int min = sec / 60;
sec = sec - (60 * min);
lblEndTime->Text = IntToStr(min) + ":" + IntToStr(sec);
}
How should i be doing that division?
UPDATE 1: I fumbled around and figured out how to see the values with this code below. When i run on Win32 i get 21169987500 for the Duration (35 min, 16 seconds) and i get 10000000 for MediaTimeScale - both correct. When i run on iOS i get 0 for Duration and 10000000 for MediaTimeScale. But, if i start the audio playing (e.g. MediaPlayer1->Play();) first and THEN run those 2 showmessages i get the correct result for Duration.
MediaPlayer1->FileName = S; // load the mp3
ShowMessage(IntToStr((__int64) Form1->MediaPlayer1->Media->Duration));
ShowMessage(IntToStr((__int64) MediaTimeScale));
It looks like the Duration does not get set on iOS until the audio actually starts playing. I tried a 5 second delay after setting MediaPlayer1->Filename but that doesn't work. I tried a MediaPlayer1->Play(); followed by MediaPlayer->Stop(); but that didn't work either.
Why isn't Duration set when the FileName is assigned? I'd like to show the Duration before the user ever starts playing the audio.

SuperCollider: RecordNRT renders wrong duration

I want to render a sound sequence using RecordNRT.
It already works, but the duration of the rendered file is too short.
var p;
[\BPM, MasterSequencer.instance.globalBPM].postln;
[\BARS, this.bars].postln;
this.sequenceDuration = ((60 / MasterSequencer.instance.globalBPM) * 4) * this.bars;
[\duration, this.sequenceDuration].postln;
SynthDef(\sampler, { |out, buffer, rate=1, amp|
var snd = PlayBuf.ar(2, buffer, BufRateScale.kr(buffer)*rate, doneAction:2);
Out.ar(0, snd * amp)
}).store;
p = Pbind(
\instrument,\sampler,
\rate, this.slider2.value,
\buffer, this.id,
\dur, (1 / this.steps) * 4,
\amp, Pseq(binarySequence) * this.slider1.value,
).asScore(this.sequenceDuration);
p = p.score.insert(1, [0, ["/b_allocRead", this.id, this.samplePath, 0, -1]]);
p.postln;
Dialog.savePanel({ |path,score|
var header = path.basename.split($.);
if(header.size == 1){
header = "WAV";
path = path ++ ".wav";
}{
header = header.last;
};
if(header == "aif"){ header = "AIFF" };
if(header == "aiff"){ header = "AIFF" };
if(header == "wav"){ header = "WAV" };
Score.recordNRT(
p,
path.dirname +/+ path.basename ++ ".osc", path,
headerFormat:header,
duration: this.sequenceDuration
);
The calculation this.sequenceDuration=(60/BPM)*4*bars is right i guess,
this.sequenceDuration=(4*bars)/(BPM/60) would do it as well.
So the imput this.sequenceDurationdoes not match the duration of the outcoming file.
I have no idea what could be the problem. I check the duration and the BPM and the bars by posting them before. I post the duration, everything seems right.
Rendering finishes and the file and it has not the right duration.
File with bars=4 BPM=70 _should be 13.71 sec, but is 11.71 sec long.
File with bars=8 BPM=70 _should be 27.42 sec, but is 23.43 sec long.
File with bars=4 BPM=140 should be 06.85 sec, but is 02.94 sec long.
File with bars=8 BPM=140 should be 13.71 sec, but is 05.87 sec long.
File with bars=4 BPM=120 should be 08.00 sec, but is 04.00 sec long.
File with bars=8 BPM=120 should be 16.00 sec, but is 08.00 sec long.
File with bars=4 BPM=150 should be 06.40 sec, but is 02.56 sec long.
File with bars=8 BPM=150 should be 12.80 sec, but is 05.12 sec long.
You might be seeing a bug which is fixed in the upcoming 3.7 version, in which the last chunk of audio samples failed to get written to disk. The fix was 28th March 2015 here:
https://github.com/supercollider/supercollider/commit/73f779e
3.7 is not out yet but you can build from source or wait for the prerelease.
An obvious workaround is to use longer files than needed, and truncate them afterwards.

Resources