Skip to contentSkip to conversation

perf daemon: Fix the warning about time_t

PATCH New Ben Zong-You Xie 1 participant 1 message May 7, 2024 perf events

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 perf daemon: Fix the warning about time_t

On the 32-bit platform, the size of time_t is 32 bits or 64 bits according to the architecture. Therefore, use typecasting to resolve the warnings for some architectures, e.g. RISC-V.

---

v2: By Palmer's remind, patch v1 may introduce a warning for some
other targets. Thus, use typecasting instead.

---
 tools/perf/builtin-daemon.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
tools/perf/builtin-daemon.c +10 -8
index 83954af36753..cb04caa902e8 100644
@@ -688,9 +688,10 @@ static int cmd_session_list(struct daemon *daemon, union cmd *cmd, FILE *out)
 			/* lock */
 			csv_sep, daemon->base, "lock");
 
-		fprintf(out, "%c%lu",
+		fprintf(out, "%c%llu",
 			/* session up time */
-			csv_sep, (curr - daemon->start) / 60);
+			csv_sep,
+			(unsigned long long)((curr - daemon->start) / 60));
 
 		fprintf(out, "\n");
 	} else {
@@ -700,8 +701,8 @@ static int cmd_session_list(struct daemon *daemon, union cmd *cmd, FILE *out)
 				daemon->base, SESSION_OUTPUT);
 			fprintf(out, "  lock:    %s/lock\n",
 				daemon->base);
-			fprintf(out, "  up:      %lu minutes\n",
-				(curr - daemon->start) / 60);
+			fprintf(out, "  up:      %llu minutes\n",
+				(unsigned long long)((curr - daemon->start) / 60));
 		}
 	}
 
@@ -727,9 +728,10 @@ static int cmd_session_list(struct daemon *daemon, union cmd *cmd, FILE *out)
 				/* session ack */
 				csv_sep, session->base, SESSION_ACK);
 
-			fprintf(out, "%c%lu",
+			fprintf(out, "%c%llu",
 				/* session up time */
-				csv_sep, (curr - session->start) / 60);
+				csv_sep,
+				(unsigned long long)((curr - session->start) / 60));
 
 			fprintf(out, "\n");
 		} else {
@@ -745,8 +747,8 @@ static int cmd_session_list(struct daemon *daemon, union cmd *cmd, FILE *out)
 				session->base, SESSION_CONTROL);
 			fprintf(out, "  ack:     %s/%s\n",
 				session->base, SESSION_ACK);
-			fprintf(out, "  up:      %lu minutes\n",
-				(curr - session->start) / 60);
+			fprintf(out, "  up:      %llu minutes\n",
+				(unsigned long long)((curr - session->start) / 60));
 		}
 	}
 
Signature · 1 line
2.34.1