mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Add C function to obtain the time since the process started.
This commit is contained in:
17
ios/TNSWidgets/TNSProcess.h
Normal file
17
ios/TNSWidgets/TNSProcess.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
//
|
||||||
|
// TNSProcess.h
|
||||||
|
// TNSWidgets
|
||||||
|
//
|
||||||
|
// Created by Panayot Cankov on 15/05/2017.
|
||||||
|
// Copyright © 2017 Telerik A D. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef TNSProcess_h
|
||||||
|
#define TNSProcess_h
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the milliseconds since the process started.
|
||||||
|
*/
|
||||||
|
double __tns_uptime();
|
||||||
|
|
||||||
|
#endif /* TNSProcess_h */
|
||||||
28
ios/TNSWidgets/TNSProcess.m
Normal file
28
ios/TNSWidgets/TNSProcess.m
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// TNSProcess.c
|
||||||
|
// TNSWidgets
|
||||||
|
//
|
||||||
|
// Created by Panayot Cankov on 15/05/2017.
|
||||||
|
// Copyright © 2017 Telerik A D. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "TNSProcess.h"
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
double __tns_uptime() {
|
||||||
|
pid_t pid = [[NSProcessInfo processInfo] processIdentifier];
|
||||||
|
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid };
|
||||||
|
struct kinfo_proc proc;
|
||||||
|
size_t size = sizeof(proc);
|
||||||
|
sysctl(mib, 4, &proc, &size, NULL, 0);
|
||||||
|
|
||||||
|
struct timeval current;
|
||||||
|
gettimeofday(¤t, NULL);
|
||||||
|
|
||||||
|
return (double)(current.tv_sec - proc.kp_proc.p_starttime.tv_sec) * 1000.0 + (double)(current.tv_usec - proc.kp_proc.p_starttime.tv_usec) / 1000.0;
|
||||||
|
}
|
||||||
@@ -9,6 +9,8 @@
|
|||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
8B7321CF1D097ECD00884AC6 /* TNSLabel.h in Headers */ = {isa = PBXBuildFile; fileRef = 8B7321CD1D097ECD00884AC6 /* TNSLabel.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
8B7321CF1D097ECD00884AC6 /* TNSLabel.h in Headers */ = {isa = PBXBuildFile; fileRef = 8B7321CD1D097ECD00884AC6 /* TNSLabel.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
8B7321D01D097ECD00884AC6 /* TNSLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B7321CE1D097ECD00884AC6 /* TNSLabel.m */; };
|
8B7321D01D097ECD00884AC6 /* TNSLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B7321CE1D097ECD00884AC6 /* TNSLabel.m */; };
|
||||||
|
F915D3551EC9EF5E00071914 /* TNSProcess.m in Sources */ = {isa = PBXBuildFile; fileRef = F915D3531EC9EF5E00071914 /* TNSProcess.m */; };
|
||||||
|
F915D3561EC9EF5E00071914 /* TNSProcess.h in Headers */ = {isa = PBXBuildFile; fileRef = F915D3541EC9EF5E00071914 /* TNSProcess.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
F98F5CB31CD0EFEA00978308 /* TNSWidgets.h in Headers */ = {isa = PBXBuildFile; fileRef = F98F5CB21CD0EFEA00978308 /* TNSWidgets.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
F98F5CB31CD0EFEA00978308 /* TNSWidgets.h in Headers */ = {isa = PBXBuildFile; fileRef = F98F5CB21CD0EFEA00978308 /* TNSWidgets.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
F98F5CBA1CD0EFEA00978308 /* TNSWidgets.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F98F5CAF1CD0EFEA00978308 /* TNSWidgets.framework */; };
|
F98F5CBA1CD0EFEA00978308 /* TNSWidgets.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F98F5CAF1CD0EFEA00978308 /* TNSWidgets.framework */; };
|
||||||
F98F5CBF1CD0EFEA00978308 /* TNSWidgetsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F98F5CBE1CD0EFEA00978308 /* TNSWidgetsTests.m */; };
|
F98F5CBF1CD0EFEA00978308 /* TNSWidgetsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F98F5CBE1CD0EFEA00978308 /* TNSWidgetsTests.m */; };
|
||||||
@@ -29,6 +31,8 @@
|
|||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
8B7321CD1D097ECD00884AC6 /* TNSLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TNSLabel.h; sourceTree = "<group>"; };
|
8B7321CD1D097ECD00884AC6 /* TNSLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TNSLabel.h; sourceTree = "<group>"; };
|
||||||
8B7321CE1D097ECD00884AC6 /* TNSLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TNSLabel.m; sourceTree = "<group>"; };
|
8B7321CE1D097ECD00884AC6 /* TNSLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TNSLabel.m; sourceTree = "<group>"; };
|
||||||
|
F915D3531EC9EF5E00071914 /* TNSProcess.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TNSProcess.m; path = ../TNSProcess.m; sourceTree = "<group>"; };
|
||||||
|
F915D3541EC9EF5E00071914 /* TNSProcess.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TNSProcess.h; path = ../TNSProcess.h; sourceTree = "<group>"; };
|
||||||
F98F5CAF1CD0EFEA00978308 /* TNSWidgets.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TNSWidgets.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
F98F5CAF1CD0EFEA00978308 /* TNSWidgets.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TNSWidgets.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
F98F5CB21CD0EFEA00978308 /* TNSWidgets.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TNSWidgets.h; sourceTree = "<group>"; };
|
F98F5CB21CD0EFEA00978308 /* TNSWidgets.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TNSWidgets.h; sourceTree = "<group>"; };
|
||||||
F98F5CB41CD0EFEA00978308 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
F98F5CB41CD0EFEA00978308 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||||
@@ -79,6 +83,8 @@
|
|||||||
F98F5CB11CD0EFEA00978308 /* TNSWidgets */ = {
|
F98F5CB11CD0EFEA00978308 /* TNSWidgets */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
F915D3531EC9EF5E00071914 /* TNSProcess.m */,
|
||||||
|
F915D3541EC9EF5E00071914 /* TNSProcess.h */,
|
||||||
F98F5CB21CD0EFEA00978308 /* TNSWidgets.h */,
|
F98F5CB21CD0EFEA00978308 /* TNSWidgets.h */,
|
||||||
8B7321CD1D097ECD00884AC6 /* TNSLabel.h */,
|
8B7321CD1D097ECD00884AC6 /* TNSLabel.h */,
|
||||||
8B7321CE1D097ECD00884AC6 /* TNSLabel.m */,
|
8B7321CE1D097ECD00884AC6 /* TNSLabel.m */,
|
||||||
@@ -105,6 +111,7 @@
|
|||||||
isa = PBXHeadersBuildPhase;
|
isa = PBXHeadersBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
F915D3561EC9EF5E00071914 /* TNSProcess.h in Headers */,
|
||||||
F98F5CB31CD0EFEA00978308 /* TNSWidgets.h in Headers */,
|
F98F5CB31CD0EFEA00978308 /* TNSWidgets.h in Headers */,
|
||||||
F98F5CCB1CD0F09E00978308 /* UIImage+TNSBlocks.h in Headers */,
|
F98F5CCB1CD0F09E00978308 /* UIImage+TNSBlocks.h in Headers */,
|
||||||
8B7321CF1D097ECD00884AC6 /* TNSLabel.h in Headers */,
|
8B7321CF1D097ECD00884AC6 /* TNSLabel.h in Headers */,
|
||||||
@@ -208,6 +215,7 @@
|
|||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
8B7321D01D097ECD00884AC6 /* TNSLabel.m in Sources */,
|
8B7321D01D097ECD00884AC6 /* TNSLabel.m in Sources */,
|
||||||
|
F915D3551EC9EF5E00071914 /* TNSProcess.m in Sources */,
|
||||||
F98F5CCC1CD0F09E00978308 /* UIImage+TNSBlocks.m in Sources */,
|
F98F5CCC1CD0F09E00978308 /* UIImage+TNSBlocks.m in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
|||||||
Binary file not shown.
@@ -18,3 +18,4 @@ FOUNDATION_EXPORT const unsigned char TNSWidgetsVersionString[];
|
|||||||
|
|
||||||
#import "UIImage+TNSBlocks.h"
|
#import "UIImage+TNSBlocks.h"
|
||||||
#import "TNSLabel.h"
|
#import "TNSLabel.h"
|
||||||
|
#import "TNSProcess.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user