Debian Codegraph @

src/profile.h

raw symbols SCIP
1 /*
2 Copyright (C) 2015 R. Bernstein <[email protected]>
3 This file is part of GNU Make (remake variant).
4
5 GNU Make is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 GNU Make is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNU Make; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20 /** \file profile.h
21 *
22 * \brief Profiler API for capturing dependency and timing information
23 * of targets
24 */
25
26 #ifndef _REMAKE_PROFILE_H
27 #define _REMAKE_PROFILE_H
28
29 #include <sys/time.h>
30 #include "filedef.h"
31
32 #define PROFILE_DISABLED 0
33 #define PROFILE_CALLGRIND 1
34 #define PROFILE_JSON 2
35
36 struct profile_entry;
37
38 /*! \brief Node for an item in the target call stack */
39 typedef struct profile_call {
40 struct profile_entry *target; /*!< Pointer to profile entry to called target */
41 struct profile_call *next; /*!< Pointer to next profile call */
42 } profile_call_t;
43
44 /*! \brief Node for a target */
45 typedef struct profile_entry {
46 FILE_TIMESTAMP start; /*!< Timestamp when the entry is initially consider */
47 FILE_TIMESTAMP deps; /*!< Timestamp when the entry is waiting on dependencies */
48 FILE_TIMESTAMP recipe; /*!< Timestamp when the entry is running it's recipe */
49 FILE_TIMESTAMP end; /*!< Timestamp when the entry is completed */
50 FILE_TIMESTAMP elapsed_total; /*!< Total time from initial check to finished */
51 FILE_TIMESTAMP elapsed_recipe; /*!< Total time recipe is running */
52
53 const char *name; /*!< Pointer to the name of the target */
54 gmk_floc floc; /*!< location in Makefile - for tracing */
55 profile_call_t *calls; /*!< List of targets this target calls. */
56 } profile_entry_t;
57
58 typedef struct profile_context {
59 int jobs; /*!< Number of jobs allowed */
60 bool jobserver; /*!< If connected to jobserver */
61 pid_t pid; /*!< PID of this instance of remake */
62 FILE_TIMESTAMP start; /*!< Timestamp of profiler init */
63 FILE_TIMESTAMP end; /*!< Timestamp of profiler closer */
64 int resolution; /*!< Resolution of the timestamps */
65
66 FILE_TIMESTAMP elapsed; /*!< Total time running remake */
67 const struct goaldep *entry; /*!< Pointer to chain of entries to remake */
68 const char *output_dir; /*!< Directory for output of profiling information */
69 } profile_context_t;
70
71 /*! \brief Function for processing a profile entry for output */
72 typedef void (*profile_dump_entry_fn)(const void *item);
73
74 /*! \brief Initialize profiler
75 *
76 * \param[in] creator String identifying the creator of the profiling output
77 * \param[in] argv Array of strings that represent the command use to start remake
78 * \param[in] jobs Number of jobs
79 *
80 * \return True if successfully initialized, False otherwise
81 */
82 extern bool profile_init(const char *creator, const char *const *argv, int jobs);
83
84 /*! \brief Update a target's profile entry
85 *
86 * \note Will create a profiler entry for target if it doesn't exist
87 *
88 * \param target Pointer to target's file struct
89 */
90 extern void profile_update_target(file_t *target);
91
92 /*! \brief Add a dependency relationship for a target
93 *
94 * \note Will create a profiler entry for target and parent if they doesn't exist
95 *
96 * \param target Pointer to target's file struct
97 * \param parent Pointer to a target's parent's file struct
98 */
99 extern void profile_add_dependency(file_t *target, file_t *parent);
100
101 /*! \brief Add a timestamp for a target based on it's state
102 *
103 * \note Will create a profiler entry for target if it doesn't exist
104 *
105 * \param target Pointer to target's file struct
106 */
107 extern void profile_add_timestamp(file_t *target);
108
109 /*! \brief Processes all entries recorded using the provided function
110 *
111 * Should be called by an output formatter during it's close routine.
112 *
113 * \param[in] fn Function for processing a profiler entry
114 */
115 extern void profile_dump_entries(profile_dump_entry_fn fn);
116
117 /*! \brief Close the profiler
118 *
119 * \param[in] program_status Textual representation of the exit reason
120 * \param[in] goals Pointer to chain of entry points of this run of remake
121 * \param[in] jobserver True if using a jobserver
122 */
123 extern void profile_close(const char *program_status, const struct goaldep *goals, bool jobserver);
124
125 #endif /*_REMAKE_PROFILE_H */