• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2015 The Chromium OS Authors. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6 
7 #include <unistd.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <errno.h>
11 #include <time.h>
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #include <fcntl.h>
15 
16 
write_marker(int fd,char * name)17 static int write_marker(int fd, char *name)
18 {
19   char buf[1024];
20   struct timespec ts;
21   int size, ret;
22   unsigned long usec;
23 
24   ret = clock_gettime(CLOCK_MONOTONIC, &ts);
25   if (ret < 0) {
26     perror("clock_gettime");
27     return 1;
28   }
29 
30   // normalize nanoseconds down to microseconds
31   // to make it easier to compare to the entry
32   // timestamps
33   usec = ts.tv_nsec / 1000;
34   size = snprintf(buf, 1024, "%s: %lu.%06lu\n",
35 		  name, ts.tv_sec, usec);
36   ret = write(fd, buf, size);
37   if (ret < size) {
38     perror("write");
39     return 1;
40   }
41 
42   return 0;
43 }
44 #define TRACE_PATH "/sys/kernel/debug/tracing/"
45 
main(int argc,char * argv[])46 int main(int argc, char* argv[]) {
47   int ret, fd;
48 
49   fd = open(TRACE_PATH "trace_marker", O_WRONLY);
50   if (fd < 0) {
51     perror("open");
52     return 1;
53   }
54   ret = write_marker(fd, "start");
55   if (ret)
56     goto out;
57 
58   ret = write_marker(fd, "middle");
59   if (ret)
60     goto out;
61 
62   ret = write_marker(fd, "end");
63 
64  out:
65   close(fd);
66   return ret;
67 }
68