Git Product home page Git Product logo

system_clock's Introduction

system_clock

Pub

Flutter timekeeping facilities, powered by dart:ffi.

support platforms: AndroidiOSMacosWindowslinux

  • web is fallback to DateTime.now()

Getting Started

import 'package:system_clock/system_clock.dart';

void main() {

  // Duration since boot, not counting time spent in deep sleep.
  println("system uptime: ${SystemClock.uptime()}");

  // Duration since boot, including time spent in sleep.
  println("system elapsed realtime: ${SystemClock.elapsedRealtime()}");
}

Refs

https://android.googlesource.com/platform/frameworks/base/+/56a2301/core/java/android/os/SystemClock.java https://android.googlesource.com/platform/frameworks/base/+/master/core/jni/android_os_SystemClock.cpp https://android.googlesource.com/platform/frameworks/native/+/android-4.2.2_r1/include/utils/Timers.h https://android.googlesource.com/platform/system/core/+/master/libutils/Timers.cpp #3 (comment)

system_clock's People

Contributors

boyan01 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

system_clock's Issues

update cmake version

Hello

May you please update the cmake version as it is causing issues with flutter builds on azure pipeline.
[CXX1300] CMake '3.10.2' was not found in SDK, PATH, or by cmake.dir property.
[CXX1301] - CMake '3.24.2' found in PATH did not satisfy requested version.
[CXX1301] - CMake '3.18.1' found in SDK did not satisfy requested version.
[CXX1301] - CMake '3.22.1' found in SDK did not satisfy requested version.

Thanks

On Linux, system_clock_uptime not found when running tests

I'm using SystemClock.uptime() in a project, but when I write tests that exercise the function calling it, I'm getting the following failure:

Invalid argument(s): Failed to lookup symbol 'system_clock_uptime': /home/osomon/build/flutter/flutter/bin/cache/artifacts/engine/linux-x64/flutter_tester: undefined symbol: system_clock_uptime
dart:ffi                                                                DynamicLibrary.lookup
package:system_clock/src/clock_io.dart 8:18                             _lookupClockFunc
package:system_clock/src/clock_io.dart 38:5                             _uptime
package:system_clock/src/clock_io.dart                                  _uptime
package:system_clock/src/clock_io.dart 46:33                            uptime
package:system_clock/system_clock.dart 15:18                            SystemClock.uptime

Tests are written using the standard flutter_test library, and run with flutter test.

And indeed, if I call the following in my test function, it returns false, whereas when the code is run from an application, it returns true:

DynamicLibrary.process().providesSymbol('system_clock_uptime')

Failed to load dynamic library 'system_clock_plugin.dll'

In pubspec.yaml I have "system_clock: ^1.2.0".

When I call:

SystemClock.uptime()

I am getting "Invalid argument(s): Failed to load dynamic library 'system_clock_plugin.dll': error code 126".

Do I need to compile this DLL myself? Do you have any instructions on how to do it?

Thank you!

Android build failure (v0.6.0)

Getting the following...

Let me know what I can provide to help debug

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/XXXX/.pub-cache/hosted/pub.dartlang.org/system_clock-0.6.0/android/build.gradle' line: 43

* What went wrong:
A problem occurred evaluating project ':system_clock'.
> Could not find method buildFeatures() for arguments [build_aw35n6snm0achvqawoa63ydiu$_run_closure2$_closure8@e7263b4] on object of type com.android.build.gradle.LibraryExtension.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 5s
Exception: Gradle task assembleStagingDebug failed with exit code 1

(Android) Sometimes the error - Failed to load dynamic library (dlopen failed: library "libsystemclock.so" not found) is coming

This happens when I try to call SystemClock.elapsedRealtime() on app start. It usually happens when I try to run the app in debug mode on an Android device after the device has been restarted. In subsequent runs it goes away. I haven't found a way to reliably replicate it, but it happens now and then. Probably usually after I get back to work the next morning, the first run throws up this error. Hot restarting the app does not fix it. Only upon stopping and running it again, it goes away.

Would you have any idea of why this could happen?

I feel it is only happening on an older android device I have - running Android 6.0.1 (API 23)

Sorry about the sparse details, but that's all I could notice.

symbol not found

hello,
in ios , i get "unhandled Exception: Invalid argument(s): Failed to lookup symbol 'system_clock_elapsed_realtime': dlsym(RTLD_DEFAULT, system_clock_elapsed_realtime): symbol not found" ,but example is ok

Possible incorrect usage of clock ids: CLOCK_MONOTONIC / CLOCK_BOOTTIME / CLOCK_UPTIME_RAW

I think that across operating systems, the clock ids mean different things. So that values returned by iOS for elapsedRealtime and uptime are reversed, than what they are on Android. Citing from the sources I could find...

elapsedRealtime

As per the code, elapsedRealtime() will fetch value from either of the following clocks:

Linux/Android: CLOCK_BOOTTIME

(from https://linux.die.net/man/2/clock_gettime)

Identical to CLOCK_MONOTONIC, except it also includes any time that the system is suspended. This allows applications to get a suspend-aware monotonic clock without having to deal with the complications of CLOCK_REALTIME, which may have discontinuities if the time is changed using settimeofday(2).

This is correct, Android works fine, and elapsedRealtime() seems to return a time that is greater than uptime().

iOS: CLOCK_UPTIME_RAW

(from http://www.manpagez.com/man/3/clock_gettime/)

clock that increments monotonically, in the same manner as CLOCK_MONOTONIC_RAW, but that does not increment while the system is asleep. The returned value is identical to the result of mach_absolute_time() after the appropriate mach_timebase conversion is applied.

This is opposite to what is expected from elapsedRealtime()

uptime

Now if we look at the call for uptime()

Linux/Android: CLOCK_MONOTONIC

(from https://man7.org/linux/man-pages/man2/clock_gettime.2.html)

The CLOCK_MONOTONIC clock is not affected by discontinuous jumps in the system time (e.g., if the system administrator manually changes the clock), but is affected by the incremental adjustments performed by adjtime(3) and NTP. This clock does not count time that the system is suspended.

iOS: CLOCK_MONOTONIC

(from https://opensource.apple.com/source/Libc/Libc-1158.1.2/gen/clock_gettime.3.auto.html)
(as well as from http://www.manpagez.com/man/3/clock_gettime/)

clock that increments monotonically, tracking the time since an arbitrary point, and will continue to increment while the system is asleep.

It seems to me that the behavior for Apple/iOS is reverse of what it is on Android. I can also see that elapsedRealtime() seems to return a time that is lesser than uptime() in iOS, which is the reverse of what I see on Android.

Look forward to your advice on this. Am I reading the wrong sources? Something wrong with my understanding? Or is it just the exact opposite behavior on two OS's.

Enable Null Safety

Can you please migrate to NULL Safe for compatibility with new Dart versions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.