1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
14 runtime_gotraceback(void)
18 p = runtime_getenv("GOTRACEBACK");
19 if(p == nil || p[0] == '\0')
20 return 1; // default is on
21 return runtime_atoi(p);
27 extern Slice os_Args __asm__ (GOSYM_PREFIX "os.Args");
28 extern Slice syscall_Envs __asm__ (GOSYM_PREFIX "syscall.Envs");
30 void (*runtime_sysargs)(int32, uint8**);
33 runtime_args(int32 c, byte **v)
37 if(runtime_sysargs != nil)
38 runtime_sysargs(c, v);
44 return argc == 0 ? nil : argv[0];
53 // for windows implementation see "os" package
57 s = runtime_malloc(argc*sizeof s[0]);
59 s[i] = runtime_gostringnocopy((const byte*)argv[i]);
60 os_Args.__values = (void*)s;
61 os_Args.__count = argc;
62 os_Args.__capacity = argc;
66 runtime_goenvs_unix(void)
71 for(n=0; argv[argc+1+n] != 0; n++)
74 s = runtime_malloc(n*sizeof s[0]);
76 s[i] = runtime_gostringnocopy(argv[argc+1+i]);
77 syscall_Envs.__values = (void*)s;
78 syscall_Envs.__count = n;
79 syscall_Envs.__capacity = n;
83 runtime_atoi(const byte *p)
88 while('0' <= *p && *p <= '9')
89 n = n*10 + *p++ - '0';
94 runtime_fastrand1(void)
108 static struct root_list runtime_roots =
110 { { &syscall_Envs, sizeof syscall_Envs },
111 { &os_Args, sizeof os_Args },
118 __go_register_gc_roots(&runtime_roots);
122 runtime_cputicks(void)
124 #if defined(__386__) || defined(__x86_64__)
126 asm("rdtsc" : "=a" (low), "=d" (high));
127 return (int64)(((uint64)high << 32) | (uint64)low);
129 // FIXME: implement for other processors.
135 runtime_showframe(String s, bool current)
137 static int32 traceback = -1;
139 if(current && runtime_m()->throwing > 0)
142 traceback = runtime_gotraceback();
143 return traceback > 1 || (__builtin_memchr(s.str, '.', s.len) != nil && __builtin_memcmp(s.str, "runtime.", 7) != 0);
146 static Lock ticksLock;
150 runtime_tickspersecond(void)
152 int64 res, t0, t1, c0, c1;
154 res = (int64)runtime_atomicload64((uint64*)&ticks);
157 runtime_lock(&ticksLock);
160 t0 = runtime_nanotime();
161 c0 = runtime_cputicks();
162 runtime_usleep(100*1000);
163 t1 = runtime_nanotime();
164 c1 = runtime_cputicks();
167 res = (c1-c0)*1000*1000*1000/(t1-t0);
170 runtime_atomicstore64((uint64*)&ticks, res);
172 runtime_unlock(&ticksLock);
176 int64 runtime_pprof_runtime_cyclesPerSecond(void)
177 __asm__ (GOSYM_PREFIX "runtime_pprof.runtime_cyclesPerSecond");
180 runtime_pprof_runtime_cyclesPerSecond(void)
182 return runtime_tickspersecond();