Skip to content

Commit 33b3f6d

Browse files
authored
Merge pull request #32 from kelnishi/clock-fix
Fixing clock resolutions
2 parents 725f41b + 4f9f147 commit 33b3f6d

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Wacs.Core/Runtime/WasmRuntimeExecution.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// */
1616

1717
using System;
18+
using System.Diagnostics;
1819
using System.Linq;
1920
using System.Reflection;
2021
using System.Runtime.ExceptionServices;
@@ -529,7 +530,7 @@ private void LogPostInstruction(InvokerOptions options, IInstruction inst)
529530

530531
private void PrintStats(InvokerOptions options)
531532
{
532-
long procTicks = Context.ProcessTimer.ElapsedTicks; //ns
533+
long procTicks = Context.ProcessTimer.ElapsedTicks;
533534
long totalExecs = options.CollectStats == StatsDetail.Instruction
534535
? Context.Stats.Values.Sum(dc => dc.count)
535536
: Context.steps;
@@ -538,9 +539,11 @@ private void PrintStats(InvokerOptions options)
538539
: Context.InstructionTimer.ElapsedTicks;
539540
long overheadTicks = procTicks - execTicks;
540541

541-
TimeSpan totalTime = new TimeSpan(procTicks/100); //100ns
542-
TimeSpan execTime = new TimeSpan(execTicks/100);
543-
TimeSpan overheadTime = new TimeSpan(overheadTicks/100);
542+
long scale = Stopwatch.Frequency / 1000_000_0; //100ns ticks
543+
544+
TimeSpan totalTime = new TimeSpan(procTicks/scale);
545+
TimeSpan execTime = new TimeSpan(execTicks/scale);
546+
TimeSpan overheadTime = new TimeSpan(overheadTicks/scale);
544547
double overheadPercent = 100.0 * overheadTicks / procTicks;
545548
double execPercent = 100.0 * execTicks / procTicks;
546549
string overheadLabel = $" overhead:({overheadPercent:#0.###}%) {overheadTime.TotalSeconds:#0.###}s";

Wacs.WASIp1/Clock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public ErrNo ClockGetRes(ExecContext ctx, ClockId clockId, ptr resolutionPtr)
6767
return ErrNo.Success;
6868
case ClockId.ProcessCputimeId:
6969
//100ns
70-
mem.WriteInt64(resolutionPtr,100ul);
70+
mem.WriteInt64(resolutionPtr,1ul);
7171
return ErrNo.Success;
7272
case ClockId.ThreadCputimeId:
7373
return ErrNo.NoSys;

0 commit comments

Comments
 (0)